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

TraceBoundary sample in Python for AutoCAD

    import traceback from pyrx_imp import Rx from pyrx_imp import Ge from pyrx_imp import Gi from pyrx_imp import Db from pyrx_imp...