AutoCAD MEP
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Accessing xref via .NET
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
592 Views, 4 Replies
05-20-2009 03:17 AM
Hi.
Is there any way to access xref dwg and make some changes, without opening it? My approach is to make some sort of “Edit referenced property set data”. I’m able to get data from xref, but not to make or save changes to it.
Can someone advise some classes for that problem? Any sample code would be appreciated. I’m using C#.
Thanks.
Is there any way to access xref dwg and make some changes, without opening it? My approach is to make some sort of “Edit referenced property set data”. I’m able to get data from xref, but not to make or save changes to it.
Can someone advise some classes for that problem? Any sample code would be appreciated. I’m using C#.
Thanks.
Re: Accessing xref via .NET
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-20-2009 07:26 AM in reply to:
Anton_O
you'd probably be better off posting in the AutoCAD .NET forum:
http://discussion.autodesk.com/forums/forum.jspa?f orumID=152
However, I'll take a stab:
Get the path from the PathName property from the BlockTableRecord for the xref.
Create a Database:
Database db = new Database();
db.ReadDwgFile(); // need to use proper overload to pass in the path
edit the db like any other, then save its changes and dispose of it.
There is:
Autodesk.AutoCAD.DatabaseServices.Database.ReloadX refs(Autodesk.AutoCAD.DatabaseServices.ObjectIdCol lection);
which you'd probably pass in an ObjectIdCollection of all the blocktablerecord objectids that you need to reload, in this case, it would only be the one that you are modifying. You might need to then tell the view to regen.

Martin Schmid, P.E.
Product Manager - Analysis and Countrification
Architecture, Engineering, and Construction
Autodesk, Inc.
http://discussion.autodesk.com/forums/forum.jspa?f
However, I'll take a stab:
Get the path from the PathName property from the BlockTableRecord for the xref.
Create a Database:
Database db = new Database();
db.ReadDwgFile(); // need to use proper overload to pass in the path
edit the db like any other, then save its changes and dispose of it.
There is:
Autodesk.AutoCAD.DatabaseServices.Database.ReloadX
which you'd probably pass in an ObjectIdCollection of all the blocktablerecord objectids that you need to reload, in this case, it would only be the one that you are modifying. You might need to then tell the view to regen.

Martin Schmid, P.E.
Product Manager - Analysis and Countrification
Architecture, Engineering, and Construction
Autodesk, Inc.
Re: Accessing xref via .NET
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-21-2009 12:41 AM in reply to:
Anton_O
Thanks for answering, Martin. You’re helping me, again 
I’ll try to post such problems in .NET forum ). But to end current thread:
When I try to save referenced database I get exception “eFileInternalErr”. Database is loaded like this : xrefDb.ReadDwgFile(fileName, FileOpenMode.OpenForReadAndWriteNoShare, true, "")
Also I’ve tried:
xrefDb.ReadDwgFile(fileName, System.IO.FileShare.Write, true, ""), but then exception is thrown when reading dwg file “eInvalidInput”.
And calling Autodesk.AutoCAD.DatabaseServices.Database.ReloadX refs(Autodesk.AutoCAD.DatabaseServices.ObjectIdCol lection) throws exception of “eWrongObjectType”. ObjectIdCollection passed into ReloadXrefs contains only ObjectId of xref.
Can you suggest something?
Edited by: Anton_O on May 21, 2009 8:19 AM
I’ll try to post such problems in .NET forum ). But to end current thread:
When I try to save referenced database I get exception “eFileInternalErr”. Database is loaded like this : xrefDb.ReadDwgFile(fileName, FileOpenMode.OpenForReadAndWriteNoShare, true, "")
Also I’ve tried:
xrefDb.ReadDwgFile(fileName, System.IO.FileShare.Write, true, ""), but then exception is thrown when reading dwg file “eInvalidInput”.
And calling Autodesk.AutoCAD.DatabaseServices.Database.ReloadX
Can you suggest something?
Edited by: Anton_O on May 21, 2009 8:19 AM
Re: Accessing xref via .NET
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-21-2009 05:43 AM in reply to:
Anton_O
refer to the attached sample

Martin Schmid, P.E.
Product Manager - Analysis and Countrification
Architecture, Engineering, and Construction
Autodesk, Inc.

Martin Schmid, P.E.
Product Manager - Analysis and Countrification
Architecture, Engineering, and Construction
Autodesk, Inc.
Re: Accessing xref via .NET
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
05-25-2009 01:44 AM in reply to:
Anton_O
I was getting xref like BlockReference, instead of BlockTableRecord. That seems to be the cause of those exceptions.
Thanks again. Everything works fine now.
Thanks again. Everything works fine now.
