Tuesday, November 7, 2023

Use Python to Insert or redefine blocks in multiple drawings

 

This example reads in the block and the target drawings as side databases

import PyRx as Rx
import PyGe as Ge
import PyGi as Gi
import PyDb as Db
import PyAp as Ap
import PyEd as Ed
import traceback

def redef(paths, newBlock):
    for path in paths:
        try:
            sideDb = Db.Database(False,True)
            sideDb.readDwgFile(path)
            id = Db.ObjectId()
            #insert the new block
            sideDb.insert(id,"screw", newBlock, True)
            sideDb.saveAs(path)
        except:
            pass #_TODO_ log failures
   
def PyRxCmd_doit():
    try:
        paths = ["e:\\06457Submittal.dwg",
                 "e:\\06457Submittal2.dwg",
                 "e:\\06457Submittal3.dwg"]
       
        blockdb = Db.Database(False,True)
        #blockdb.readDwgFile("e://Screw_6_CS.dwg")
        blockdb.readDwgFile("e://North Arrow.dwg")
        blockdb.closeInput(True)
       
        #adds a scope
        redef(paths,blockdb)
   
    except Exception as err:
        traceback.print_exception(err)
 
 
 


       

No comments:

Post a Comment

Fine-Tuning Selection Set Filtering with Callbacks in PyRx

As of version 2.2.58, most selection set actions in PyRx have received a powerful overload that allows developers to attach a When executing...