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

    .NET

    Reply
    Active Contributor
    Posts: 30
    Registered: ‎09-06-2007
    Accepted Solution

    List CAD Standards in a DWG in VB.NET

    361 Views, 7 Replies
    04-25-2012 01:03 AM

    Hi there,

     

    I'm quite new to .NET in AutoCAD, usual story, boss need somebody to do something, no time for trainings (yet), etc...  so please, bare with me :smileywink:

     

    Here is the story. in an Acad plug-in, I need to get the list of standards associated to the current drawing

     

    So far, I've got:

    Dim nod As DBDictionary = tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead)
    
    Dim id As ObjectId = nod.Item("AcStStandard")

     

    I do get the object ID of the AcstStandard dictinary. So far so good

     

    but then ???

     

    Can't seem to find an object type to do the tr.GetObject(id, OpenMode.ForRead)

     

    There's stuff for layouts etc... but not for standards.


    TIA

    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,331
    Registered: ‎10-08-2008

    Re: List CAD Standards in a DWG in VB.NET

    04-25-2012 06:01 AM in reply to: btmsoftware

    Something like this may helps

     

    Dim nod As DBDictionary = tr.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForRead)

    Dim id As ObjectId = nod.Item("AcStStandard")

    Dim dict as DBDictionary= tr.Getobject(id, OpenMode.ForRead)

     

    Not tested though....

     

    ~'J'~

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    Active Contributor
    Posts: 30
    Registered: ‎09-06-2007

    Re: List CAD Standards in a DWG in VB.NET

    04-27-2012 12:46 AM in reply to: Hallex

    Did the trick, thanx a lot

    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,331
    Registered: ‎10-08-2008

    Re: List CAD Standards in a DWG in VB.NET

    04-27-2012 01:17 AM in reply to: btmsoftware

    You're welcome Cheers :smileyhappy:

     

    ~'J'~

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    Active Contributor
    Posts: 30
    Registered: ‎09-06-2007

    Re: List CAD Standards in a DWG in VB.NET

    04-27-2012 01:21 AM in reply to: Hallex

    Actually, I've got another one, related

     

    Once I've done that, I get an xRecord with the data with the file name. The thing is that it's the original file path when the CAD standard file was attached.

     

    However, it can (and it does happen alot with my users) that the files are moved around (the support path are changed in this case).

     

    AutoCAd can resolve the new path from the support paths, however, I couldn't find any method to get this resolved path, do you know of one or do I have to loop thru all the support path and find the one i nwhich my file is found (with the risk that there might be multiple files with the same name in different paths, bad practicve I know but users....... ;-)

    Please use plain text.
    *Expert Elite*
    Hallex
    Posts: 1,331
    Registered: ‎10-08-2008

    Re: List CAD Standards in a DWG in VB.NET

    04-27-2012 04:38 AM in reply to: btmsoftware

    Do you want to get template file?

    If so try this quick code:

               Dim db As Database = HostApplicationServices.WorkingDatabase
                Dim newPath As String = HostApplicationServices.Current.FindFile("acadiso.dwt", db, FindFileHint.Default)
                MsgBox(newPath)

     

    ~'J'~

    _____________________________________
    C6309D9E0751D165D0934D0621DFF27919
    Please use plain text.
    Active Contributor
    Posts: 30
    Registered: ‎09-06-2007

    Re: List CAD Standards in a DWG in VB.NET

    04-28-2012 11:07 PM in reply to: Hallex

    Unfortunately, it gives me an eFilerError

     

    thing is that the CAD standard file is not in any support path defined in the AutoCAD options, it is in the same path than the drawing itself.

     

    I guess I´ll have to implement my own FindFile to include the drawing´s path in it. Thanx ofr the help anyways

     

    Please use plain text.
    Active Contributor
    Posts: 30
    Registered: ‎09-06-2007

    Re: List CAD Standards in a DWG in VB.NET

    05-28-2012 11:57 PM in reply to: btmsoftware

    Made my own stuff to look into the active drawing's path and in the support paths

     

    Here it is, for those looking for a similar solution

     

    ' Takes a file name (without path) and returns the 1st dull file name (with path) in which the file is found
    ' Return empty string if not found

    Private Function getPath(name As String) As String Dim Result As String = "" Dim sPath As String Try Console.WriteLine("Looking for " & name) ' Getting active drawing path sPath = New FileInfo(Application.DocumentManager.MdiActiveDocument.Name).Directory.FullName Console.WriteLine(" in " & sPath) sPath = Path.Combine(sPath, name) If File.Exists(sPath) Then Result = sPath Console.WriteLine(" Found") return Result Else Console.WriteLine(" Not found") End If ' Getting all support paths in an array Dim pathPrefs As AcadPreferencesFiles = Application.Preferences.Files Dim supportPaths() As String = pathPrefs.SupportPath.Split(";") For Each sPath In supportPaths Console.WriteLine(" in " & sPath) sPath = Path.Combine(sPath, name) If File.Exists(sPath) Then Result = sPath Console.WriteLine(" Found") Return Result Else Console.WriteLine(" Not found") End If Next Catch ex As Exception Result="" System.Windows.Forms.MessageBox.Show(ex.ToString, "My App", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Stop) End Try Return Result End Function

     

    Please use plain text.