Problems with SetDefaultFamilyTypeId and PostableCommands
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Everybody,
I'm trying to create a command that sets the default Familytype before using a postablecommand to create an actual element.
Default Revit uses the last place type when starting a command again.
The user has to manualy find the desired type to place in the view.
I have got the same kind of logic working with a TextNote.
So, when the user uses my command,
the defaultTextNotetype of the project is Set to the textnotetype i want and then the Text Command is activated with the postablecommand methods. This works like a charm. the code below, changes the textnotetype to a specific type and the user gets to place a text in the desiderd type. (in this case the third found in the collector).
So it doesn't matter what text type was last used to
//Get 3 textnotetype from collector
Element el = new FilteredElementCollector(doc).OfClass(typeof(TextNoteType)).ToElements()[3];
if (doc.IsDefaultElementTypeIdValid(ElementTypeGroup.TextNoteType, el.Id))
{
TaskDialog.Show("Revit", "Valid Type");
Transaction trans = new Transaction(doc, "SetDefaultTextNoteType");
trans.Start();
doc.SetDefaultElementTypeId(ElementTypeGroup.TextNoteType, el.Id);
trans.Commit();
}
else
{
TaskDialog.Show("Revit", "Invalid Type");
}
RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.Text);
app.PostCommand(id);
But when I try to adapt this command to use the SetDefaultFamilyTypeId() the changes of type isn't reflected in the command when it is activated using postablecommand
This is the code i got so far:
The dialog boxes tell me the default type Id of the category is changed.
But this type isn't used in the posted command, or even when activating the command itself afterwards.
//Pick a symbol to set as default type
FamilyInstance Pick = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element).ElementId) as FamilyInstance;
FamilySymbol el = Pick.Symbol;
ElementId catId = new ElementId(BuiltInCategory.OST_DetailComponents);
if (doc.IsDefaultFamilyTypeIdValid(catId, el.Id))
{
TaskDialog.Show("Revit", "Valid Type");
Transaction trans = new Transaction(doc, "SetDefaultFamilyType");
trans.Start();
doc.SetDefaultFamilyTypeId(catId, el.Id);
trans.Commit();
}
else
{
TaskDialog.Show("Revit", "Invalid Type");
}
RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.DetailComponent);
app.PostCommand(id);
Does anybody know what I am doing wrong?
Maarten