Drawing Symbol library unable to close

Drawing Symbol library unable to close

w.pepping
Advocate Advocate
453 Views
3 Replies
Message 1 of 4

Drawing Symbol library unable to close

w.pepping
Advocate
Advocate

Hello,

I hope someone can help me with this.

I'm trying to query through code how many Sketched Symbols are present in the Symbol Library folder (MySymbolLib.idw). This works and I get this info in the message box. But as soon as the messagebox is shown, a document (probably MySymbolLib.idw) opens invisible and I can't close it anymore.

How can I do this by code?

 

If I place 1 or more Sketched Symbols then this invisible document is closed correct.

The problem is only there if I quit without placing.

Knipsel.PNG

 

 

        Dim oDrawDoc As DrawingDocument = _invApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, , False)
        Dim oSymbolLibs As SketchedSymbolDefinitionLibraries = oDrawDoc.SketchedSymbolDefinitions.SketchedSymbolDefinitionLibraries
        Dim oSymbolLib As SketchedSymbolDefinitionLibrary = oSymbolLibs.Item("MySymbolLib")
MsgBox(oSymbolLib.SketchedSymbolDefinitions.Count) 
        oDrawDoc.ReleaseReference()
        oDrawDoc.Close(True)

 

 

Get control of your sheet metal files.
Download the app from matprop.com
0 Likes
Accepted solutions (1)
454 Views
3 Replies
Replies (3)
Message 2 of 4

JelteDeJong
Mentor
Mentor

you can try

ThisApplication.Documents.CloseAll()

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 4

Scott_Stubbington
Advocate
Advocate

Hello,

I may have missed a point but in my head you are opening a document, not adding a document, personally myself I would change 

Dim oDrawDoc As DrawingDocument = _invApp.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, , False)

to 

Dim oDrawDoc As DrawingDocument = _invApp.Documents.Open("Filename to MySymbolLib.idw here", False)

The picture in my head is you've just created a new file from your template drawing file and closing a new file without saving might be the issue.  I feel the remaining code should work.

I hope this helps.

Scott

0 Likes
Message 4 of 4

w.pepping
Advocate
Advocate
Accepted solution

Thanks Jelte, Scott, I appreciate the replies.

I figured out that after I do a request for information from the symbol library (MySymbolLib.idw), it is opened in the background.

If I do not insert a symbol (not possible in my case, because I do the request from a ipt/iam) it is never closed and causes an error if I exit Inventor.

So I have to close it by code after the request:

 

        For Each openDoc As Document In _invApp.Documents
            If IO.Path.GetFileNameWithoutExtension(openDoc.FullFileName) = "MySymbolLib" Then
                openDoc.Close(True)
                Exit For
            End If
        Next

 

Get control of your sheet metal files.
Download the app from matprop.com
0 Likes