Set AssemblyInstance.Name on creation

Set AssemblyInstance.Name on creation

Anonymous
Not applicable
2,074 Views
6 Replies
Message 1 of 7

Set AssemblyInstance.Name on creation

Anonymous
Not applicable

I've written a tool that expands on the creation of AssemblyInstances.  The problem that I'm encountering now is that I want users to be able to set the name during the process.  The native Revit function does this:

Untitled.png

 

I'm pretty much trying to replicate it without the combobox, as I already grab the naming category prior.  I've already created the dialog, which take the user input for the string.  It's stored statically, so if they've created AssemblyInstances with it before, we will have the naming convention.  Questions are:

  1. If this is the first AssemblyInstance they're creating, is there a way to pull the native Revit naming convention based on the Category.Id
  2. I've tried setting the AssemblyInstance.Name, which has both a get and set, and I get the following error:
    • "This element does not support assignment of a user-specified name."
    • I've tried setting this both inside the initial Transaction when I'm creating the AssmeblyInstance, and in a following one where I'm setting other shared parameters - I get the same result.

What am I missing here?  What do I need to do to accomplish this?  Thanks!!!

0 Likes
Accepted solutions (1)
2,075 Views
6 Replies
Replies (6)
Message 2 of 7

jeremytammik
Autodesk
Autodesk

The get and set operations are inherited from the base class Element.Name property.

 

You can set the name on many Revit elements.

 

Apparently, on the AssemblyInstance, you cannot.

 

Cheers,

 

Jeremy



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

0 Likes
Message 3 of 7

Anonymous
Not applicable

Perhaps you need to commit your transaction prior to renaming the assembly. An assembly which does not exist cannot be renamed.

 

I am using a routine which renames assemblyinstances so it is possible to rename them.

0 Likes
Message 4 of 7

Anonymous
Not applicable

So I tried it when I was creating the Assembly, and then later in a separate transaction.  Neither worked...  BUT - both Transactions were in a GroupTransaction...  So maybe I need to do it after the GroupTransaction is commited, because technically the Assembly still didn't exist when I was trying to rename it in the 2nd Transaction of the GroupTransaction????

 

I'm gonna give it a shot.  Hopefully you're right!!!

Message 5 of 7

Anonymous
Not applicable

Untitled.png

 

 

Maybe you could tell me how you're doing it...  Because I just keep hitting the same wall from a different vector...

0 Likes
Message 6 of 7

RPTHOMAS108
Mentor
Mentor
Accepted solution

As @jeremytammik said class .name is inherited from Element but luckily they have reinvented the wheel for you:

 

So you want

 

AssemblyInstance.AssemblyTypeName

 

A trick I've learned in terms of avoiding inherited members is to read the 'Methods' and 'Properties' branches of the item within the .chm file rather than the 'Members' branch. Not sure why they list everything in 'Members', if you wanted a member which is inherited then you wouldn't cast to a more specific type. Is probably auto generated to a certain degree.

 

You may also ask: why is this property not on the AssemblyType class which seems pretty barren in terms of its own properties and methods (I would not know the answer).

Message 7 of 7

jorge_herron
Explorer
Explorer

I have been working in Revit 2024 and encountered the same issue. I am relatively new to the Revit API, but I believe that in order to modify assembly properties (such as the name), the object must first be created—at least, that’s what worked for me.

0 Likes