When using AttachXref api, received following message AutoCAD message - Warning: an error ocurred during Save

When using AttachXref api, received following message AutoCAD message - Warning: an error ocurred during Save

Anonymous
Not applicable
714 Views
2 Replies
Message 1 of 3

When using AttachXref api, received following message AutoCAD message - Warning: an error ocurred during Save

Anonymous
Not applicable

As mentioned in the title, when I try to attach an X-ref layer to my Drawing file, received the following error:Screenshot 2021-06-04 200616.png

 

But, I am able to save the drawing successfully. Is there any way how to adress the above error. Following is my code snippet for attaching Xref:

using (Transaction tr = destDb.TransactionManager.StartTransaction())
                {
                    ObjectId XrefID = destDb.AttachXref(filepath1, filepath);
                    BlockReference bref = new BlockReference(Point3d.Origin, XrefID);
                    BlockTable table = tr.GetObject(destDb.BlockTableId, OpenMode.ForWrite) as BlockTable;
                    BlockTableRecord ms1 = tr.GetObject(table[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                    ms1.AppendEntity(bref);
                    tr.AddNewlyCreatedDBObject(bref, true);
                    LayerTable acLyrTbl;
                    acLyrTbl = tr.GetObject(destDb.LayerTableId, OpenMode.ForRead) as LayerTable;
                    if (acLyrTbl.Has("G-XREF"))
                        bref.Layer = "G-XREF";
                    tr.Commit();
                }

 

Thanks,

Ranjan

0 Likes
715 Views
2 Replies
Replies (2)
Message 2 of 3

pendean
Community Legend
Community Legend
Why don't you just use RECOVER command (and more if needed) to fix the file as the pop-up suggests?
0 Likes
Message 3 of 3

Anonymous
Not applicable

Here, I would like to see an api based solution as I am reading Autodesk Database using autocad apis. I believe the recover solution is through the editor which I cant use as I am not working on an active document.
I have been able to debug the source problem. This occurs when I am trying to attach Xref as mentioned above. And the xref itself has been using layers from a .las file which was imported previously. When I do not use this method of importing layers in xref model the above program works fine.
But, currently the issue is solved from my end without any programming by modifying my CAD dwg at the source by including the required layers instead of using a .las file through the backend program.

 

Anyways, would love to hear if any solutions are there through api programming.

0 Likes