Keep x-ref layer settings
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
So I've got some code to copy a drawing including references files. This means in the copy, the path to the reference-files have to be set to the copies of the references.
In Autocad you can then simply can change the 'saved path' field in the reference manager.
Tried to do this in C# with:
Database dat = new Database(false, true);
using (dat)
{
dat.ReadDwgFile(tek.padNIEUW, System.IO.FileShare.ReadWrite, true, "");
using (Transaction tr = dat.TransactionManager.StartTransaction())
{
XrefGraph xg = dat.GetHostDwgXrefGraph(true);
int count = xg.NumNodes;
if (count > 1) //anders loopt die vast als er 0 xrefs zijn in een tek.
{
for (int i = 1; i < count; i++)
{
XrefGraphNode xrNode = xg.GetXrefNode(i);
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(xrNode.BlockTableRecordId, OpenMode.ForWrite);
dat.XrefEditEnabled = true;
string naam = btr.Name;
if (btr.IsResolved == false)
{
string nieuwpad = "";
foreach (Xref xr in gebruikteXrefs)
{
if (xr.naam == naam)
{
nieuwpad = xr.vollepadNIEUW;
}
}
btr.PathName = nieuwpad;
}
}
tr.Commit();
}
}
dat.SaveAs(tek.padNIEUW, DwgVersion.Current);
}
however this isn't working correctly. it does set the new path to the new x-ref yes, but all the layersettings and stuff are forgotten. so for example, when in the drawing setting layercolor of an x-ref-layer to blue (while in the x-ref itself it is yellow), after changing the x-ref-path the setting is forgotten, so in the drawing i see an yellow layer instead of a blue. This doesn't happen when you change the path in autocad itself (so without .net).
What is going wrong here? And more important how to solve this?