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: 

PhaseCreated & PhaseDemolished after using CopyElements()

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
floretti
462 Views, 5 Replies

PhaseCreated & PhaseDemolished after using CopyElements()

Dear Santa,

 

I know I'm a bit late but hopefully I can get this for my 2022 Christmas.

 

I'm trying to copy elements from one document into another, which I'm managing fine. The issue I'm facing is that, despite having the origin document phases present in the destination document (same phase names at least), the copied elements' Phase Created and Phase Demolished are not matching the original elements'.

 

I've checked if the ElementIds returned by CopyElements() come up in the same order as the given ElementIds but unfortunately that was not the case and once the elements are copied I'm struggling to make a connection between origin and destination so I can match the phases.

 

I'll try and behave this year!

 

Fabio

5 REPLIES 5
Message 2 of 6
floretti
in reply to: floretti

Oh, and I've seen this too but it didn't help.

Message 3 of 6
jeremy_tammik
in reply to: floretti

I believe that when you collect a bunch of elements and copy them all together in one single operation, Revit will try to maintain and restore all their mutual relationships in the target database. Therefore, it might help if you add all possible references these elements have to other source database elements to the set of elements to copy. These references will include the element instances themselves, their types, phases, levels, views, materials, and whatever other objects you are interested in. Then you will have to test and see what Revit can do to try to avoid creating duplicates of them in the target database and map them to existing target objects instead.

 

This behaviour is hinted at in the list of extensible storage features:

  

https://thebuildingcoder.typepad.com/blog/2011/06/extensible-storage-features.html#7

  

Jeremy Tammik, Developer Advocacy and Support, The Building Coder, Autodesk Developer Network, ADN Open
Message 4 of 6
sragan
in reply to: floretti

That’s standard behavior for the Revit User Interface.  Elements that are pasted into a view do not get their phases from the copied elements.  Instead, they get their phases from the phase of the view they are pasted into.   For example, if the view pasted into has a new construction phase, that’s the phase that the elements will inherit for their created in phase.

 

It’s possible to check the phases of every element copied, store those in an array, and then apply the phases to the new elements.  I’ve created an addin that does that, and I’ve posted the code online.  You will have to do some extra work to deal with the fact that you are pasting into a different document, but that should be fairly easy to do.

 

https://sites.google.com/site/revitapi123/copy-similar-code

 

 

 

 

Message 5 of 6
floretti
in reply to: floretti

Thanks for the help, @jeremy_tammik and @sragan .

 

@sragan I was doing exactly what you suggested but I was getting inconsistent results when comparing the elements from the source model against the destination model. I then tried a few different ways and ended up realising that the CopyElements() does return the same order of the given ElementId list, which then solved my problem.

 

When I collected the elements in my source document I also collected their Phase Created and Phase Demolished and stored all 3 in a list as shown below. This allowed me to compared the output of CopyElements() with that list and apply the settings of each element individually.

List<KeyValuePair<ElementId, KeyValuePair<string, string>>>()

Message 6 of 6
jeremy_tammik
in reply to: floretti

Thank you both for the interesting discussion and useful sample code! I added it to the blog for posterity:

 

https://thebuildingcoder.typepad.com/blog/2022/02/acc-summit-model-properties-copy-relationships.htm...

  

Jeremy Tammik, Developer Advocacy and Support, The Building Coder, Autodesk Developer Network, ADN Open

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