[VB.net] check drawing properties of referenced part from an assembly

[VB.net] check drawing properties of referenced part from an assembly

ChristianAndersenIsmyname
Advocate Advocate
669 Views
4 Replies
Message 1 of 5

[VB.net] check drawing properties of referenced part from an assembly

ChristianAndersenIsmyname
Advocate
Advocate

Hello!

 

I have a code that populate 3 different listboxes.

1st listbox = Displayname of part if drawing is approved

2nd listbox = Displayname of part if drawing exists but not approved

3rd listbox = DIsplayname of part if drawing doesnt exist

 

The 2nd and 3rd listbox works perfectly, but grabbing value of "Mfg Approved By" from the drawing is a bit more tricky it seems.

 

My code so far:

        Dim invapp As Inventor.Application
        invapp = GetObject(, "Inventor.Application")
        Dim asmDoc As AssemblyDocument
        asmDoc = invapp.ActiveDocument
        If asmDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
            For Each Doc In asmDoc.AllReferencedDocuments
                If Doc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
                    Try
                        Dim drawing As String = Doc.FullFileName
                        drawing = drawing.Substring(0, drawing.Length - 3)
                        If System.IO.File.Exists(drawing & "idw") Then

                            If drawing.PropertySets("Design Tracking Properties").Item("Mfg Approved By").Value <> "" Then
                                ListBox1.Items.Add(Doc.DisplayName)
                            Else
                                ListBox2.Items.Add(Doc.displayname)
                            End If
                        End If
                        ListBox3.Items.Add(Doc.DisplayName)
                    Catch ex As Exception
                        MsgBox(Doc & " : failed to check part")
                    End Try
                End If
            Next
End if

 This code won't work cause I've placed a dummy text in " If drawing.propertysets .." just to illustrate what I want to achieve.

 

Can anyone help me with this?

 

Thanks!

0 Likes
Accepted solutions (1)
670 Views
4 Replies
Replies (4)
Message 2 of 5

yan.gauthier
Advocate
Advocate

Shouldn't it be:

If Doc.PropertySets("Design Tracking Properties").Item("Mfg Approved By").Value <> "" Then

 

drawing is a String in your code.

 

Also, use System.IO.Path.GetFileNameWithoutExtension() to get the file name. Doc.FullFileName will contain the extension only if you set windows to display it.

 

 

0 Likes
Message 3 of 5

ChristianAndersenIsmyname
Advocate
Advocate

This will check the property of the referenced part of the assembly, and not the its drawing?

0 Likes
Message 4 of 5

yan.gauthier
Advocate
Advocate
Accepted solution

You are right. 

 

what I meant is that your string object cannot be handled like a DrawingDocument Object.

 

you need to find the drawing file and then open it before you can interact with it.

 

drawingFileName = InvApp.DesignProjectManager.ResolveFile(System.IO.Path.GetDirectoryName(Doc.FullFileName), System.IO.Path.ChangeExtension(Doc.FullFileName, ".idw"));

if drawingFileName <> "" then
    dim drawingDocument as DrawingDocument
    drawingDocument = invApp.Documents.Open(drawingFileName, false) //false to open invisible
end if

 

some method are copied from my C# code. It might still need some fine tuning to work in VB.NET.

 

From there, you should be able to get in the PropertySets. Remember to call drawingDocument.close() when you are done.

 

In your catch statement, test if drawingDocument to see if it is open so you can close it.

 

0 Likes
Message 5 of 5

ChristianAndersenIsmyname
Advocate
Advocate

Thank you 🙂

I was hoping it was a other way instead of opening the drawings, as I was afraid this would be a very slow operation. But it is a lot faster than I expected.

0 Likes