Is there a way to xref a file to multiple DWGs using Dynamo nodes? I see a camber node for adding xref. Just not sure how I would use that node to add an xref to multiple DWGs
This is possible using Python and the AutoCAD API by sideloading files as Database objects
def attachexternalreference(filepath, xrefpath, xrefname, insertpoint=Point3d(0, 0, 0)):
# Create the database and start a transaction
with Database(False, True) as db:
# Load in the file
db.ReadDwgFile(filepath, FileShare.ReadWrite, False, "")
with db.TransactionManager.StartTransaction() as t:
# Attach reference to the db
xrefid = db.AttachXref(xrefpath, xrefname)
# If a valid reference is created then continue
if not xrefid.IsNull:
bref = BlockReference(insertpoint, xrefid)
# Append the DWG reference to the current space
btr = t.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)
btr.AppendEntity(bref)
t.AddNewlyCreatedDBObject(bref, True)
# Commit the new objects to the database
t.Commit()
# Save the database back to the file
db.SaveAs(filepath, DwgVersion.Current)
Include from System.IO import FileShare
with your standard imports