Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ bool Bake(IGH_Param param, BakeOptions options, out ICollection<ElementId> ids)
}

ds.SetShape(geometry.ToShape());

if (options.Material is object)
{
ds.Document.Regenerate();
using (var shape = ds.get_Geometry(new Options() { DetailLevel = ViewDetailLevel.Undefined }))
{
foreach (var solid in shape.OfType<Solid>())
{
foreach (var face in solid.Faces.OfType<Face>())
options.Document.Paint(ds.Id, face, options.Material.Id);
}
}
}

ids.Add(ds.Id);
}

Expand All @@ -176,15 +190,13 @@ public override Result Execute(ExternalCommandData data, ref string message, Ele
if (bakeOptsDlg.ShowModal() != Eto.Forms.DialogResult.Ok)
return Result.Cancelled;

var groupResult = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl);

var options = new BakeOptions()
{
Document = doc,
View = data.View,
Category = Category.GetCategory(doc, bakeOptsDlg.SelectedCategory),
Workset = doc.IsWorkshared ? doc.GetWorksetTable().GetWorkset(bakeOptsDlg.SelectedWorkset) : default,
Material = default
Category = Category.GetCategory(doc, bakeOptsDlg.SelectedCategory),
Material = doc.GetElement<Material>(bakeOptsDlg.SelectedMaterial)
};

var resultingElementIds = new List<ElementId>();
Expand Down Expand Up @@ -233,9 +245,9 @@ public override Result Execute(ExternalCommandData data, ref string message, Ele
}
}

if (groupResult)
if (bakeOptsDlg.Group)
{
using (var trans = new Transaction(options.Document, "Group Bake"))
using (var trans = new Transaction(options.Document, "Bake Group"))
{
if (trans.Start() == TransactionStatus.Started)
{
Expand Down
97 changes: 60 additions & 37 deletions src/RhinoInside.Revit.AddIn/Forms/Dialogs/BakeOptionsDialog.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Eto.Forms;
using Eto.Drawing;
using Eto.Forms;
using ARDB = Autodesk.Revit.DB;
using ARUI = Autodesk.Revit.UI;

namespace RhinoInside.Revit.AddIn.Forms
{
using Properties;
using External.DB;
using External.DB.Extensions;

class BakeOptionsDialog : ModalDialog
Expand All @@ -17,11 +18,15 @@ class BakeOptionsDialog : ModalDialog

readonly ARDB.Document Document;

ComboBox _categorySelector = new ComboBox();
ComboBox _worksetSelector = new ComboBox() { Enabled = false };
ComboBox _worksetSelector = new ComboBox() { ReadOnly = true, Enabled = false };
ComboBox _categorySelector = new ComboBox() { ReadOnly = true };
ComboBox _materialSelector = new ComboBox() { ReadOnly = true };
CheckBox _groupBox = new CheckBox() { Enabled = true };

public ARDB.ElementId SelectedCategory { get; private set; } = ARDB.ElementId.InvalidElementId;
public ARDB.WorksetId SelectedWorkset { get; private set; } = ARDB.WorksetId.InvalidWorksetId;
public ARDB.ElementId SelectedCategory { get; private set; } = ARDB.ElementId.InvalidElementId;
public ARDB.ElementId SelectedMaterial { get; private set; } = ARDB.ElementId.InvalidElementId;
public bool Group { get; private set; } = false;

public BakeOptionsDialog(ARUI.UIApplication uiApp) : base(uiApp, initialSize: new Size(400, -1))
{
Expand All @@ -37,42 +42,55 @@ protected override void Dispose(bool disposing)
{
if (disposing)
{
_categorySelector?.Dispose(); _categorySelector = null;
_worksetSelector?.Dispose(); _worksetSelector = null;
_categorySelector?.Dispose(); _categorySelector = null;
_materialSelector?.Dispose(); _materialSelector = null;
_groupBox?.Dispose(); _groupBox = null;
}

base.Dispose(disposing);
}

void InitLayout()
{
// collect worksets
if (Document.IsWorkshared)
{
_worksetSelector.Enabled = true;
var wsTable = Document.GetWorksetTable();
foreach (var workset in new ARDB.FilteredWorksetCollector(Document).OfKind(ARDB.WorksetKind.UserWorkset).ToWorksets())
_worksetSelector.Items.Add(new ListItem { Key = workset.Name, Text = workset.Name, Tag = workset.Id });

var activeWorkset = wsTable.GetWorkset(wsTable.GetActiveWorksetId());
if (activeWorkset.Kind == ARDB.WorksetKind.UserWorkset)
_worksetSelector.SelectedKey = activeWorkset.Name;
}

// collect categories (only applicable to directshapes since baking creates directshapes)
foreach (var group in DirectShapeCategories.GroupBy(x => x.CategoryType).OrderBy(x => x.Key.ToString()))
{
foreach (var category in group.OrderBy(x => x.Name))
{
_categorySelector.Items.Add(new ListItem { Key = category.Name, Text = category.Name });
if (category.ToBuiltInCategory() == ARDB.BuiltInCategory.OST_GenericModel)
var id = category.ToBuiltInCategory();
_categorySelector.Items.Add(new ListItem { Key = category.Name, Text = category.Name, Tag = id });
if (id == ARDB.BuiltInCategory.OST_GenericModel)
_categorySelector.SelectedKey = category.Name;
}
}

// collect materials
_materialSelector.Items.Add(new ListItem { Key = "<By Category>", Text = "<By Category>", Tag = ARDB.ElementId.InvalidElementId });
_materialSelector.SelectedIndex = 0;
foreach (var material in new ARDB.FilteredElementCollector(Document).OfClass<ARDB.Material>().OrderBy(x => x.Name))
_materialSelector.Items.Add(new ListItem { Key = material.Name, Text = material.Name, Tag = material.Id });

_groupBox.Checked = Group;

// select the previously selected category if any
if (AddInOptions.Current.CustomOptions.Get(OPTROOT, "LastSelectedCategory") is string lastCategoryName)
if (_categorySelector.Items.Select(x => x.Key).Contains(lastCategoryName))
_categorySelector.SelectedKey = lastCategoryName;

// collect worksets
if (Document.IsWorkshared)
{
var wsTable = Document.GetWorksetTable();
_worksetSelector.Enabled = true;
foreach (ARDB.Workset workset in new ARDB.FilteredWorksetCollector(Document).OfKind(ARDB.WorksetKind.UserWorkset).ToWorksets())
_worksetSelector.Items.Add(new ListItem { Key = workset.Name, Text = workset.Name });

var activeWorkset = wsTable.GetWorkset(wsTable.GetActiveWorksetId());
if (activeWorkset.Kind == ARDB.WorksetKind.UserWorkset)
_worksetSelector.SelectedKey = activeWorkset.Name;
}

// select the previously selected workset if any
if (AddInOptions.Current.CustomOptions.Get(OPTROOT, "LastSelectedWorkset") is string lastWorksetName)
if (_worksetSelector.Items.Select(x => x.Key).Contains(lastWorksetName))
Expand All @@ -82,18 +100,18 @@ void InitLayout()
{
Spacing = new Size(5, 10),
Padding = new Padding(5),
Rows = {
Rows =
{
new TableLayout
{
Spacing = new Size(5, 10),
Padding = new Padding(5),
Rows = {
new TableRow {
Cells = { new Label { Text = "Select Category" }, _categorySelector }
},
new TableRow {
Cells = { new Label { Text = "Select Workset" }, _worksetSelector }
},
Rows =
{
new TableRow { Cells = { new Label { Text = "Workset" }, _worksetSelector } },
new TableRow { Cells = { new Label { Text = "Category" }, _categorySelector } },
new TableRow { Cells = { new Label { Text = "Paint" }, _materialSelector } },
new TableRow { Cells = { new Label { Text = "Group" }, _groupBox } },
}
},
}
Expand All @@ -108,15 +126,6 @@ void InitLayout()

private void BakeButton_Click(object sender, EventArgs e)
{
// set selected category
foreach (var category in DirectShapeCategories)
{
if (category.Name != _categorySelector.SelectedKey) continue;

AddInOptions.Current.CustomOptions.Set(OPTROOT, "LastSelectedCategory", category.Name);
SelectedCategory = category.Id;
}

// set selected workset
if (Document.IsWorkshared)
{
Expand All @@ -129,6 +138,20 @@ private void BakeButton_Click(object sender, EventArgs e)
}
}

// set selected category
foreach (var category in DirectShapeCategories)
{
if (category.Name != _categorySelector.SelectedKey) continue;

AddInOptions.Current.CustomOptions.Set(OPTROOT, "LastSelectedCategory", category.Name);
SelectedCategory = category.Id;
}

if ((_materialSelector.SelectedValue as ListItem)?.Tag is ARDB.ElementId materialId)
SelectedMaterial = materialId;

Group = _groupBox.Checked is true;

AddInOptions.Save();
Close(DialogResult.Ok);
}
Expand Down
2 changes: 1 addition & 1 deletion src/RhinoInside.Revit.GH/Components/Element/Materials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA)
face.Document.Paint(face.Id, face.Value, paint.Id);
}

Params.TrySetData(DA, "Paint", () => new Types.Material(face.Document, face.Document.GetPaintedMaterial(face.Id, face.Value)).FromSource(face.Source));
Params.TrySetData(DA, "Paint", () => face.GetElement<Types.Material>(face.Document.GetPaintedMaterial(face.Id, face.Value)));
}
}
}
Loading