Community
AutoCAD MEP Forum
Welcome to Autodesk’s AutoCAD MEP Forums. Share your knowledge, ask questions, and explore popular AutoCAD MEP topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Accessing xref via .NET

4 REPLIES 4
Reply
Message 1 of 5
Anton_O
998 Views, 4 Replies

Accessing xref via .NET

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.
4 REPLIES 4
Message 2 of 5
Martin__Schmid
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
Product Line Manager
Mechanical Detailing and Electrical Design
Architecture, Engineering, and Construction
Autodesk, Inc.

Message 3 of 5
Anton_O
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.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
Message 4 of 5
Martin__Schmid
in reply to: Anton_O

refer to the attached sample


Martin Schmid
Product Line Manager
Mechanical Detailing and Electrical Design
Architecture, Engineering, and Construction
Autodesk, Inc.

Message 5 of 5
Anton_O
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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost