AutoCAD MEP General Discussion

AutoCAD MEP General Discussion

Reply
Member
Anton_O
Posts: 5
Registered: ‎03-19-2009
Message 1 of 5 (717 Views)

Accessing xref via .NET

717 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.
Employee
martin.schmid
Posts: 1,299
Registered: ‎11-16-2005
Message 2 of 5 (717 Views)

Re: Accessing xref via .NET

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?forumID=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.ReloadXrefs(Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection);
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 - Revit MEP
Architecture, Engineering, and Construction
Autodesk, Inc.

Member
Anton_O
Posts: 5
Registered: ‎03-19-2009
Message 3 of 5 (717 Views)

Re: Accessing xref via .NET

05-21-2009 12:41 AM in reply to: Anton_O
Thanks for answering, Martin. You’re helping me, again :smileyhappy:



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.ReloadXrefs(Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection) 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
Employee
martin.schmid
Posts: 1,299
Registered: ‎11-16-2005
Message 4 of 5 (717 Views)

Re: Accessing xref via .NET

05-21-2009 05:43 AM in reply to: Anton_O
refer to the attached sample


Martin Schmid, P.E.
Product Manager - Revit MEP
Architecture, Engineering, and Construction
Autodesk, Inc.

Member
Anton_O
Posts: 5
Registered: ‎03-19-2009
Message 5 of 5 (717 Views)

Re: Accessing xref via .NET

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.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions to get help installing your software.

New AutoCAD MEP Category!

The AutoCAD MEP forum has moved into it's very own category page, and can no longer be found within the Additional Product Forums.

Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.