Assembly code in system families

Assembly code in system families

Anonymous
Not applicable
1,629 Views
2 Replies
Message 1 of 3

Assembly code in system families

Anonymous
Not applicable

Hi there,

 

I'm trying to change the assembly code of walls. here is my code:

 

Document doc = commandData.Application.ActiveUIDocument.Document;
UIApplication app = commandData.Application;

ElementSet elemset = commandData.Application.ActiveUIDocument.Selection.Elements;

Transaction trans = new Transaction(doc, "Changeparam");
trans.Start();

foreach (Element el in elemset)
{
Parameter par = el.GetParameterNoCase("assembly code");
if (par == null)
{
FamilyInstance fi = el as FamilyInstance;
if (fi != null) par = fi.Symbol.GetParameterNoCase("assembly code");
}
if (par == null)
{
par = el.get_Parameter(BuiltInParameter.UNIFORMAT_CODE); //here I can see a wall actually has an assembly code
}
if (par != null)
{
string waarde = "2D(21.0)";
par.Set(waarde); //It will assign the value to the assembly code of the selected wall
}

}

trans.Commit();

 

 

It works great for family instances like Windows and Doors, but If I try it on walls, no error comes but the assembly code stays unchanged??

 

Does anybody know how to change the assembly code for walls (or any other system family) ?

 

 

0 Likes
1,630 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk

Dear Remy,

Thank you for your query.

I would suggest that you clean up your code first, so that we can see better what is going on.

I am pretty sure that you can use a built-in parameter to access the assembly code on all elements.

That would enable you to:

a) eliminate those mysterious if statements.

b) eliminate your language dependency.

You can use the debugger to explore how to clean it up, and then you can use the debugger again to ensure that the same code is actually being executed for both walls and family instances.

Once that is done, and if it still does not work, I would suggest that you use RevitLookup to examine what the difference between walls and family instances might be in regard to the asssembly code.

Especially, you need to check that the assembly code can be changed in all the places you need it to be via the user interface.

If that is possible, you can use RevitLookup to see exactly how and where the data is stored, and how you can drive it programmatically to achieve the same as in the UI.

I hope this helps.

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 3

Anonymous
Not applicable

Thanks Jeremy,

 

I have looked deeper in it and this is what I came up with :

 

Parameter par = null;
FamilyInstance fi = null;
Element element = null;
foreach (Element el in elemset)
{
fi = el as FamilyInstance;
if (fi != null) par = fi.Symbol.get_Parameter(BuiltInParameter.UNIFORMAT_CODE);  //check if the element is a family instance
if (par == null) //if not, it must be a system family
{
element = commandData.Application.ActiveUIDocument.Document.GetElement(el.GetTypeId());
if (element != null) //okay, this if may be overkill 🙂
{
foreach (Parameter ps in element.Parameters)
{
if (ps.Definition.Name == "Assembly Code")
{
par = ps;
break;
}
}
}
}

if (par != null) //if for some reason the selected element has no assembly code, skip it
{
string waarde = "2D(21.0)"; //example value
par.Set(waarde);
}
}
trans.Commit();

 

I need the mysterious ifs because without them Revit returns the famous "Object not set to a reference".

Only little thingie I can't figure out is curtain walls. The code works when I select the elements seperatly, but when I do a selection of a complete curtain wall with mullions, panels ect. the curtain wall it self (Wall) refuses to accept the new assembly code. When I Tab-select it, the code works. I guess it has something to do with the order curtain wall items are selected ??

 

 

0 Likes