Danielm103 Posted June 5 Posted June 5 (edited) as a response to this thread https://www.cadtutor.net/forum/topic/86222-script-to-change-status-stamp-block-across-300-drawings-please/#comment-642701 uses https://github.com/CEXT-Dan/PyRx changes the drawings found in a folder import traceback from pyrx_imp import Rx, Ge, Gs, Gi, Db, Ap, Ed import wx import os, pathlib def findIdsByName(db, blkname):# -> list: ids = [] allids = db.objectIds(Db.BlockReference.desc()) for id in allids: ref = Db.BlockReference(id) if ref.getBlockName() == blkname: ids.append(id) return ids def changeit(db : Db.Database, blkname): refids = findIdsByName(db, blkname) for id in refids: dyn = Db.DynBlockReference(id) if not dyn.isDynamicBlock(): continue for prop in dyn.getBlockProperties(): if prop.propertyName() != 'Visibility1': continue vals = dict([(p.getString(), p) for p in prop.getAllowedValues()]) prop.setValue(vals['AS CONSTRUCTED']) def openSideDrawing(path, blkname): print("\nProcessing {} ".format(path)) db = Db.Database(False, True) db.readDwgFile(path) db.closeInput(True) changeit(db,blkname) db.saveAs(path) def PyRxCmd_doit(): try: blkname = 'PTA_Stamp_Dynamic' dlg = wx.DirDialog(None, "Choose input directory","", wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST) if dlg.ShowModal() != wx.ID_OK: print("You Cancelled The Dialog!") return fnames = next(os.walk(dlg.GetPath()), (None, None, []))[2] dwgex = ".dwg".casefold() for fname in fnames: ext = pathlib.Path(fname).suffix.casefold() if ext != dwgex: continue fpath = '{}\\{}'.format(dlg.GetPath(),fname) openSideDrawing(fpath, blkname) print("yay") except Exception as err: traceback.print_exception(err) Edited June 5 by Danielm103 context 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.