Use CopyElements ignoring their hosted elements

Use CopyElements ignoring their hosted elements

Anonymous
Not applicable
1,182 Views
1 Reply
Message 1 of 2

Use CopyElements ignoring their hosted elements

Anonymous
Not applicable

Problem:

I have used the CopyElements method which causes a "Autodesk.Revit.Exceptions.InvalidOperationException: Copying one or more elements failed." exception. When I manually try to copy the elements from the Revit UI I receive the message "Can't copy to clipboard because of relationship between Elements" which I believe is related to the Revit API InvalidOperationException above.

Cannot Copy to Clipboard because of relationships.PNG

 

To avoid the above problem I discovered that if I copy the elements one by one Revit ignores the relationships between the element and allows elements to be copied. Therefore I don't receive the above Exception from the Revit API. When elements using the CopyElements method which are hosts, Revit also copies automatically all hosted elements associated with their hosts. The problem is that CopyElements method does not return any of the hosted Elements and this makes the Copy operation very difficult to control.

 

Questions:

1. Is there any way to overcome the InvalidOperationException associated with the "Selection cannot be copied. Cannot copy to clipboard because of relationship between elements." when copying multiple elements together?

2. Is there any easy way to find the newly added hosted elements when copying hosts using the CopyElements method?

 

Many thanks,

Alexandros

0 Likes
1,183 Views
1 Reply
Reply (1)
Message 2 of 2

jeremytammik
Autodesk
Autodesk

Dear Alexandros,

 

Yes, you can determine the hosted elements either before or after copying the hosts.

 

This is illustrated clearly by the MaterialQuantities Revit SDK sample.

 

It uses the temporary transaction trick to determine net and gross BIM element material quantities like this:

 

  • Collect all roof elements
  • Iterate through each material found in each roof
  • Find the net volume and area of the material
  • Store the material quantities
  • Write the results to the output file
  • Find the gross material quantities
    • Start a new transaction
    • Delete the elements that cut the host (doors, windows, openings)
    • Find the volume and area for each material
    • Store the material quantities
    • Write the results to the output file
    • Rollback the transaction
  • Repeat the above steps for walls and floors
  • Open the output file in Microsoft Excel

  

Look at the SDK sample to see how that can be achieved.

  

Best regards,

  

Jeremy

 



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

0 Likes