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.
Solved! Go to Solution.
Solved by PaulCollins7972. Go to Solution.
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.
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
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
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