See the top rated post in this thread. Click here

Results 1 to 4 of 4

Thread: Reading DWGPROPS from C#

  1. #1
    Member
    Join Date
    2013-04
    Posts
    16
    Login to Give a bone
    0

    Talking Reading DWGPROPS from C#

    Hello,

    I am trying to access the DWG properties from within ACAD, there's lots of resources on how to write custom ones but I cannot seem to simply read them.
    The code below dosen't show any errors and fails to read anything resulting in empty strings.
    Also I would like to eventually read the properties without opening the file, for example:

    http://through-the-interface.typepad...ing-dwg-f.html

    Code:
    Database db = HostApplicationServices.WorkingDatabase;
    Editor ed = MgdAcApplication.DocumentManager.MdiActiveDocument.Editor;
    DatabaseSummaryInfoBuilder infobuilder = newDatabaseSummaryInfoBuilder();
    DatabaseSummaryInfo info = newDatabaseSummaryInfo();
    info = db.SummaryInfo;
    try
    {
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
    Debug.WriteLine("METADATA ran.");
    ed.WriteMessage("METADATA ran.\n");
    string Author = info.Author;
    ed.WriteMessage("Author is ", Author);
    Author = infobuilder.Author;
    ed.WriteMessage("Author is ", Author);
    tr.Commit();
    }
    }
    catch (System.Exception ex)
    {
    Debug.WriteLine(ex.ToString());
    ed.WriteMessage(ex.ToString());
    }
    }
    }
    }
    
    Last edited by John Allan; 2014-03-03 at 10:46 AM.

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    1

    Default Re: Reading DWGPROPS from C#

    Quote Originally Posted by John Allan View Post
    I am trying to access the DWG properties from within ACAD, there's lots of resources on how to write custom ones but I cannot seem to simply read them.
    Give this a try:

    Code:
            void _ReadSummaryInfo(Document doc)
            {
                Database db = doc.Database;
                Editor ed = doc.Editor;
    
                DatabaseSummaryInfo info = db.SummaryInfo;
    
                ed.WriteMessage("\nTitle: {0}", info.Title);
                ed.WriteMessage("\nSubject: {0}", info.Subject);
                ed.WriteMessage("\nAuthor: {0}", info.Author);
                ed.WriteMessage("\nKeywords: {0}", info.Keywords);
                ed.WriteMessage("\nComments: {0}", info.Comments);
                ed.WriteMessage("\nHyperlinkBase: {0} \n", info.HyperlinkBase);
            }
    Last edited by BlackBox; 2014-03-03 at 01:15 PM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Member
    Join Date
    2013-04
    Posts
    16
    Login to Give a bone
    0

    Default Re: Reading DWGPROPS from C#

    That worked great, bit embarasing with the simple C# mistake there.
    Thank you for your help... here is the code am using to grab data from other drawings that might be useful for somone else.

    Code:
                string FilePath = "d:\\drawing1.dwg";
                Database db = new Database(false, true);
    
                using (db)
                {
                    try
                    {
                        db.ReadDwgFile(FilePath, System.IO.FileShare.Read, false, "");
                    }
                    catch (System.Exception)
                    {
                        ed.WriteMessage("\nUnable to read drawing file.");
                        return;
                    }
                    Transaction tr = db.TransactionManager.StartTransaction();
                    using (tr)
                    {
    
                        DatabaseSummaryInfo info = db.SummaryInfo;
                        ed.WriteMessage("\nTitle: {0}", info.Title);
                        ed.WriteMessage("\nSubject: {0}", info.Subject);
                        ed.WriteMessage("\nAuthor: {0}", info.Author);
                        ed.WriteMessage("\nKeywords: {0}", info.Keywords);
                        ed.WriteMessage("\nComments: {0}", info.Comments);
                        ed.WriteMessage("\nHyperlinkBase: {0} \n", info.HyperlinkBase);
                    }
                }
    Partly taken from here

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Reading DWGPROPS from C#

    Quote Originally Posted by John Allan View Post
    Thank you for your help...
    You're welcome; I'm happy to help.

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Similar Threads

  1. Replies: 5
    Last Post: 2015-07-22, 10:55 PM
  2. 3rd party file management vs. DWGPROPS
    By hvysteel in forum CAD Management - General
    Replies: 2
    Last Post: 2009-01-26, 07:00 PM
  3. dwgprops dictionary
    By dnovak.90006 in forum AutoLISP
    Replies: 6
    Last Post: 2007-08-22, 12:50 PM
  4. DWGPROPS command
    By elowe494 in forum AutoLISP
    Replies: 2
    Last Post: 2006-01-05, 10:12 PM
  5. Dwgprops, and vlax functions
    By JasonSelf in forum AutoLISP
    Replies: 1
    Last Post: 2004-09-04, 01:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •