Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to get ElementID of a newly created element?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
PaulCollins7972
2100 Views, 4 Replies

How to get ElementID of a newly created element?

I am creating a viewport using Viewport.Create(doc, sheet_id,source_id, XYZ) which works fine but always uses the default Viewport type.

 

I would like to change the Viewport type by using Viewport.ChangeTypeID(doc,viewport_id, type_id)

 

Please can someone tell me how to find the elementID of something that has just been created so I can use that in the above?

 

Any help appreciated.

4 REPLIES 4
Message 2 of 5
ollikat
in reply to: PaulCollins7972

Hi

 

It seems that you have misunderstood the API somehow. The ChangeTypeId() method takes only one parameter and that is the id of the desired type element. In this case the target type is not a newly created but some already existing type element you want to use.

So the real question for you is how to find the type element that you would like to use as a type instead of one used by Viewport.Create(). But I believe you should be aware of how to do that...but if not, then you can check out the filtering API and various examples for that.

And as a matter of fact, the Viewport.Create() returns the element it creates so if you still need the element/id of newle created ViewPort, there you have it.

Message 3 of 5
PaulCollins7972
in reply to: ollikat

Cheers,

 

Your reply has pointed me in the right direction and I now have things working fine.

 

I am using the 2014 Revit API, the  CHM gives me 2 versions of the Element.ChangeTypeID method.

Method 1 as you say has only one argument which is the typeid to change to.

Method 2 (suggested by autocomplete) has arguments "document,icollection(elementid),typeid"

 

I have changed my code to return a viewport object from the create argument and then set to new typeid as you suggested:

 

NewVP=Viewport.Create( doc, vw_id, source_id, XYZ )

NewVP.ChangeTypeID( New_ID )

 

Thanks

Message 4 of 5

Just to answer your original question, i.e., how to retrieve the element id of a newly created element:

 

Use a temporary DocumentChanged event handler and the DocumentChangedEventArgs GetAddedElementIds method as described here:

 

http://thebuildingcoder.typepad.com/blog/2010/06/place-family-instance.html

 

I'm glad to hear you found a better solution and no longer need this approach  🙂

 

Cheers,

 

Jeremy

Jeremy Tammik, Developer Advocacy and Support, The Building Coder, Autodesk Developer Network, ADN Open
Message 5 of 5
pbuggmen
in reply to: jeremy_tammik

Hi Jeremy,

I saw your post on

Retrieving Newly Created Elements

 

http://thebuildingcoder.typepad.com/blog/2010/06/place-family-instance.html

 

Just wondering if this can work inside an external event call from a modeless dialog?

 

cheers,

 

Phil

 

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community