.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

List CAD Standards in a DWG in VB.NET

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
btmsoftware
1230 Views, 7 Replies

List CAD Standards in a DWG in VB.NET

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 Smiley Wink

 

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

7 REPLIES 7
Message 2 of 8
Hallex
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
Message 3 of 8
btmsoftware
in reply to: Hallex

Did the trick, thanx a lot

Message 4 of 8
Hallex
in reply to: btmsoftware

You're welcome Cheers 🙂

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 5 of 8
btmsoftware
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....... 😉

Message 6 of 8
Hallex
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
Message 7 of 8
btmsoftware
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

 

Message 8 of 8
btmsoftware
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

 

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost