Hi everyone,
I was a bit surprised there is no topic on this one. I am currently trying to purge a bunch of drawings (Layers and unused Blockreferences). For this I couldn’t find nodes. First of all: Am I overlooking something? Is the a super easy way I am not aware of? Secondly: with the basics of Paolo
(thanks again for the work) in Run Dynamo Script on entire folder of dwg's - #17 by Paolo_Emilio_Serra1 I managed to get a Python script working. See below and attached.
def python_purge(path):
adoc = DocumentCollectionExtension.Open(acapp.DocumentManager, path, False) # Open for Write
acapp.DocumentManager.CurrentDocument = adoc
if adoc is None:
return False
ret = True
err = []
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite) # Get BlockTable
oid_coll = ObjectIdCollection()
for oid in bt:
oid_coll.Add(oid)
db.Purge(oid_coll)
for oid in oid_coll:
acSymTblRec = t.GetObject(oid, OpenMode.ForWrite)
try:
acSymTblRec.Erase(True)
except Exception as e:
pass
lt = t.GetObject(db.LayerTableId, OpenMode.ForWrite) # Get LayerTable
lid_coll = ObjectIdCollection()
for lid in lt:
lid_coll.Add(lid)
db.Purge(lid_coll)
for lid in lid_coll:
acSymTblRec = t.GetObject(lid, OpenMode.ForWrite)
try:
acSymTblRec.Erase(True)
except Exception as e:
err.append(e)
t.Commit()
if adoc:
DocumentExtension.CloseAndSave(adoc, path)
if len(err) > 0:
ret = err
return ret
PurgeExternalDrawing.dyn (10.1 KB)