Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Modifications to elements in document opened using OpenDocumentFile method

crayP6HXA
Explorer

Modifications to elements in document opened using OpenDocumentFile method

crayP6HXA
Explorer
Explorer

Hello!

 

I am writing an application that will be moving elements from a document opened using the OpenDocumentFile() method.

 

This has been working, but I'm copying reference callouts over which has been successful except for the geometry of the callout. I'm using the BoundingBox() method to return the min and max points, but this includes the callout heads which makes the copied callouts too large.

 

To remedy this I created a function with a transaction within that turns all callout heads to null. This then sets the BoundingBox points to the correct min and max for the callouts' insertion points. However when I try and run function to modify the document opened with the OpenDocumentFile() method, I get an exception that an attempt is being made to modify the document outside a transaction.

 

So the question arrose, can you modify a document opened in the background with this method?

If not, are there any suggestions on how I can retrieve the correct insertion points? Or any ways I can include reference call outs, sections, and view references in a simpler manner than copying the views, then copying the elements of those views including, then the call outs, sections and view refs referenced to the corresponding views in the new document?

 

Thanks in advance!

0 Likes
Reply
Accepted solutions (1)
374 Views
3 Replies
Replies (3)

jeremy_tammik
Autodesk
Autodesk
Accepted solution

OpenDocumentFile returns a Document object. You need to create a transaction on that specific document, e.g., like this:

   

  Document x = OpenDocumentFile(...)
  using( Transaction t = new Transaction(x))
  {
    ...

     

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes

crayP6HXA
Explorer
Explorer

Jeremy, thanks for the response! This helped me realize that I was accidentally trying to start this transaction in another transaction for a different document... Thank you for the help in realizing the errors of my ways!

0 Likes

jeremy_tammik
Autodesk
Autodesk

Thank you for your appreciation and glad to hear it was of use!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes