Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

read item in udp of a part from assy using vba

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
akosi
589 Views, 7 Replies

read item in udp of a part from assy using vba

im looking for an item "customer code" in the custom prop of a part

normally, i have 10+ parts in an assy.

 can vba access the udp of a part from assy?

and show which part doesnt have that item?

or vise versa or both? Smiley Frustrated

 

 

 

7 REPLIES 7
Message 2 of 8
ekinsb
in reply to: akosi

What you want to do is certainly possible using the API but to be able to give you as good of a sample as possible some more information would be useful.

 

When looking for this particular property in parts, do you want to look at all levels of the assembly or only the top-level. Do you want to look for this only in parts or also sub assemblies?


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 8
akosi
in reply to: ekinsb

i only need the top level.
ex.
1.assy
1.1 part<--- i need this
1.2 sub assy <---and this
1.2.1 part

thanks in advance .
Message 4 of 8
ekinsb
in reply to: akosi

Here's one way to do it.

 

Public Sub GetiPropertiesOfTopLevel()
    ' Get the active assembly.
    Dim asmDoc As AssemblyDocument
    Set asmDoc = ThisApplication.ActiveDocument
    
    ' Iterate through the files referenced by the assembly.
    ' These are only direct references so parts and assemblies
    ' in subassemblies will be ignored.
    Dim doc As Document
    For Each doc In asmDoc.ReferencedFiles
        ' Get the "Customer Code" iProperty
        Dim customPropSet As PropertySet
        Set customPropSet = doc.PropertySets.item( _
                            "Inventor User Defined Properties")
        
        Dim prop As Inventor.Property
        On Error Resume Next
        Set prop = customPropSet.item("Customer Code")
        If Err.Number = 0 Then
            Debug.Print "The file """ & doc.FullFileName & """ has the value: " & prop.Value
        Else
            Debug.Print "The file """ & doc.FullFileName & _
                                          """ does not have the ""Customer Code"" iProperty"
        End If
        On Error GoTo 0
    Next
End Sub

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 5 of 8
akosi
in reply to: ekinsb

thank you so much ...works perfectlySmiley Happy

Message 6 of 8
akosi
in reply to: ekinsb

can i print the whole output to a text file or messagebox?

Message 7 of 8
ekinsb
in reply to: akosi

Here's a modified version of the previous program that writes the results to a file. I'm formatting with commas and using a .csv extension so it will open in Excel but you can easily modify it to output it any way you want.

Public Sub GetiPropertiesOfTopLevel()
    ' Get the active assembly.
    Dim asmDoc As AssemblyDocument
    Set asmDoc = ThisApplication.ActiveDocument
    
    ' Open the file to write the results.
    Dim filename As String
    filename = "C:\Temp\PropertyResults.csv"
    Open filename For Output As #1
    
    Print #1, "Filename,Has Customer Code,Value"
    
    ' Iterate through the files referenced by the assembly.
    ' These are only direct references so parts and assemblies
    ' in subassemblies will be ignored.
    Dim doc As Document
    For Each doc In asmDoc.ReferencedFiles
        ' Get the "Customer Code" iProperty
        Dim customPropSet As PropertySet
        Set customPropSet = doc.PropertySets.item( _
                            "Inventor User Defined Properties")
        
        Dim prop As Inventor.Property
        On Error Resume Next
        Set prop = customPropSet.item("Customer Code")
        If Err.Number = 0 Then
            Print #1, doc.FullFileName & ",True," & prop.Value
        Else
            Print #1, doc.FullFileName & ",False,"
        End If
        On Error GoTo 0
    Next
    
    Close #1
    MsgBox "Finished processing." & vbCrLf & _
           "Results written to """ & filename & """"
End Sub

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 8 of 8
akosi
in reply to: ekinsb

this is so perfect !!!

 

thank you so much...

 

ive change the message to give user option to choose to open the csv file

but i get error when it reaches to the point where it about to open the file.

i think my code for opening a csv is wrong.

 

can you help me pls Smiley Sad

 

ive been googling and cant find some example...

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

Post to forums  

Autodesk Design & Make Report