Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Close invisible drawing

Anonymous

Close invisible drawing

Anonymous
Not applicable

Hi all,

I'm programming an AddIn with VB.NET.

I work with drawing documents and I open they without show the document. The problem is close the drawing! If I active the drawing and call method Drawing.Close() it work fine, if I call the same method with the drawing document invisible it doesn't work and the document stays opened.

Somebody know the problem?

 

Thanks

 

Valerio Pittavino

0 Likes
Reply
Accepted solutions (1)
1,030 Views
7 Replies
Replies (7)

Owner2229
Advisor
Advisor

Hey, it wouldn't hurt to post your code... Anyway, to be able to control the drawing (and avoid leftover documents) your code should look like this:

 

Dim oDoc As Document = InventorApplication.Documents.Open("MyDrawingPath", False)
'Or:
Dim oDoc As Document = InventorApplication.ActiveDocument
Try 'Your code working with the drawing Catch End Try oDoc.Save() 'Optional save oDoc.Close()

You can also use "DrawingDocument" instead of "Document" if you know what it will work with is drawing, or add a simple check:

 

If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Exit Sub  

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes

Anonymous
Not applicable

Hi,

thanks for your reply.

The code i'm using is this

''' <summary>
''' Chiude tutti i disegni che sono nascosti
''' </summary>
''' <remarks></remarks>
    Public Sub ChiudiDisegniNascosti(ByVal mDis As List(Of DrawingDocument))
        Dim ElencoAperti As New List(Of DrawingDocument)
        For i As Integer = 1 To g_inventorApplication.Documents.VisibleDocuments.Count
            Dim temp As Document = g_inventorApplication.Documents.VisibleDocuments.Item(i)
            If temp.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
                ElencoAperti.Add(temp)
            End If
        Next
        For Each d As DrawingDocument In mDis
            If ElencoAperti.IndexOf(d) = -1 Then
                Try
                    d.Views.Add() 'THIS IS TO SHOW THE DOCUMENT ELSE IT CANNOT BE CLOSE
                    'd.Apri()
                    d.Close(True)
                Catch

                End Try
            End If
        Next
    End Sub

I pass a list of drawing to close and the method must close only the invisible documents. To know if the document is visible I check the visibledocuments by inventor.

If I don't show the document by "d.Views.Add()" it will not closed.

I don't want save.

0 Likes

Owner2229
Advisor
Advisor

So, this is your workflow, right?

1) Open some drawings as invisible

2) Do some operations with the invisible drawing

3) Close all invisible drawings

 

Now, this is how it should be:

1) Open ONE drawing as invisible and bind it as variable (e.g. "oDoc" as in my sample)

2) Do some operations with the binded drawing

3) Close the binded drawing

4) Open another drawing

 

Also, to close all invisible drawings, you could use this:

 

Public Sub ChiudiDisegniNascosti()
'List through all documents For Each oDoc As Document In g_inventorApplication.Documents
'Skip other than drawings If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Continue For
'Skip visible drawings If oDoc.Visible Then Continue For oDoc.Close(True) Next End Sub

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes

Anonymous
Not applicable

Thanks but don't work.

Method or property .Visible doesnt exist.

I tryed your code without .visible but the problem is same, if you watch the number of open file don't change

 

Public Sub ChiudiDisegniNascostiAAAA()
        'List through all documents
        For Each oDoc As Document In g_inventorApplication.Documents
            'Skip other than drawings
            If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then Continue For
            'Skip visible drawings
            MsgBox("chiudo " + oDoc.Nome)
            oDoc.Close(True)
        Next
    End Sub

if you try to open any drawing as invisible you can't close it, you must before make it visible.

Smiley Frustrated

 

0 Likes

Owner2229
Advisor
Advisor

Hmm, that's strange. The documents actually don't have the "visible" property and they can't be closed this way (form the Documents enumerator) while they're invisible. I guess that's a bug.

 

Anyway, you SHOULD stick to the workflow I've suggested you above. This way you'll avoid issues like this.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods

Anonymous
Not applicable

I also think which is a bug, I will send a message to autodesk.

I solved yesterday the problem making drawing visible and close just after open.

 

Thanks for your replies.

0 Likes

Anonymous
Not applicable
Accepted solution

Hi,

I'm writing because I solved the problem.

To close an invisible drawing is need to activete it and after to close it, this is same to before but reading in the API documentation I found the application's property ScreenUpdating, this property allow to not update the screen when you are doing operation then:

lock screen

active the drawing

close the drawing

unlock screen

 

Thanks for your help

 

 

Valerio Pittavino

0 Likes