Run Dynamo Script on entire folder of dwg's

What comes next is the core of the inner function and might have been done differently. I’ve tried to put together a little bit of everything to show how to safely access a document via context managers (the “with” statements to LockDocument, Database and Transaction), check and create layers, check and import a block from an external DWG, iterate through the Entities of the Model Space, test for the type of an Entity (isinstance() L146), erase an entity from the Database, create a BlockReference, deal with Transforms in AutoCAD API (Matrix3d objects L159-162) and finally add the new objects to the Database. After all that the transaction must be committed to validate the changes made and the Document must be saved in the same location.


4 Likes