• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    AutoCAD MEP

    Reply
    Member
    Posts: 5
    Registered: ‎03-19-2009

    Accessing xref via .NET

    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.
    Please use plain text.
    Employee
    Posts: 1,278
    Registered: ‎11-16-2005

    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 - Analysis and Countrification
    Architecture, Engineering, and Construction
    Autodesk, Inc.

    Please use plain text.
    Member
    Posts: 5
    Registered: ‎03-19-2009

    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
    Please use plain text.
    Employee
    Posts: 1,278
    Registered: ‎11-16-2005

    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 - Analysis and Countrification
    Architecture, Engineering, and Construction
    Autodesk, Inc.

    Please use plain text.
    Member
    Posts: 5
    Registered: ‎03-19-2009

    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.
    Please use plain text.