Hi…
Code encounters error:
Dynamo is not pointing at the current document.
Need to create new DWG files by copying an existing DWG - then add to the newly copied DWG files.
What did I miss?
Thanks for your patience,
K.
import os
import sys
import clr
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
tbl = IN[0]
ciset = IN[1] # # # 0 - file name col, 1 - alignment name col, 2 - MSX col, 3 - MSY col
pp = IN[2]
tf = IN[3]
def dwgtask (path,px,py):
if not os.path.exists(path):
return False
adoc = DocumentCollectionExtension.Open(Application.DocumentManager,path,False)
Application.DocumentManager.CurrentDocument = adoc
if adoc is None:
return False
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
MsId = SymbolUtilityServices.GetBlockModelSpaceId(adoc.Database)
ms = t.GetObject(MsId,OpenMode.ForWrite)
with Circle as ac:
ac.Radius = 150.0
ac.Center = Point3d(px,py,0)
#ac.Linetype = 'Continuous'
ms.AppendEntity(ac)
t.AddNewlyCreatedDBObject(ac,True)
t.Commit()
if adoc:
DocumentExtension.CloseAndSave(adoc, path)
return True
def main():
if not os.path.exists(pp):
return 'Prototype path is invalid or is not accessible.'
o = []
adoc = Application.DocumentManager.MdiActiveDocument
for i in range(1, len(tbl)):
fn = tbl[i][ciset[0]]
if fn:
nfp = tf + '\\' + fn + '.DWG'
if not nfp in o:
try:
nfp = tf + '\\' + fn + '.DWG'
os.system('copy ' + pp + ' ' + nfp)
o.append(nfp)
except Exception() as ex:
return ex.message
if os.path.exists(nfp):
try:
dwgtask(nfp,tbl[i][ciset[2]],tbl[i][ciset[3]])
except Exception() as ex:
return ex.message
return True
OUT = main()
copy-dwg-new-dwgs.dyn (20.2 KB)
example-info.xlsx (15.4 KB)
prototype.dwg (2.4 MB)