Does anyone know how to run the ATTSYNC command within Dynamo effectively? I have a script that I would like to run on a folder of DWGs that modifies a block attribute. So after running the script on each DWG, ATTSYNC needs to be run for the block reference to update properly. I have tried running ATTSYNC in the .scr file which hasn’t worked, and have also tried running ATTSYNC within a python node through a dynamo script which has also not worked properly when run through the batch save utility.
I’m out of ideas now. Turning to the forum for help. Thanks!
There is not an equivalent method which is exposed in the AutoCAD API, you could look at this post here which has code examples in C# and VB.
I have done DWG sideloading to process multiple files, however it can be flaky in my experience
Here’s a basic sideloading python code
import clr
clr.AddReference("AcDbMgd")
from Autodesk.AutoCAD.DatabaseServices import (
Database,
DwgVersion,
FileOpenMode,
OpenMode,
)
files = IN[0] # type: ignore
for dwg in files:
with Database(False, True) as db:
db.ReadDwgFile(dwg, FileOpenMode.OpenForReadAndWriteNoShare, True, "")
with db.TransactionManager.StartTransaction() as t:
# Update attributes
bt = t.GetObject(db.BlockTableId, OpenMode.ForRead)
if bt.Has("MyBlock"):
btr = t.GetObject(bt.get_Item("MyBlock"), OpenMode.ForRead)
for brefId in btr.GetBlockReferenceIds(True, False):
bref = t.GetObject(brefId, OpenMode.ForWrite)
for id in btr:
if id.ObjectClass.Name == "AcDbAttributeDefinition":
adef = t.GetObject(id, OpenMode.ForRead)
... # Update attributes as needed
# Commit changes before save
t.Commit()
db.SaveAs(dwg, DwgVersion.Current)
# Clean up
db.Dispose()
Years ago I used the Camber package to send a command directly to the Civil3D command line, with ATTSYNC and then \n (or similar) to make it actually send command at the end of the Dynamo script. That just worked.
The Civil packages have been majorly overhauled since then, so I cannot give you up-to-date advice on which package and which specific node But, I think if you search for something related to this here on the forum you’ll likely get some hits.