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: 

VBA iPart - Value from iPart table

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
KlausetLaila5105
2599 Views, 5 Replies

VBA iPart - Value from iPart table

Hello,

 

I am wondering if there is way how to get custom value from existing custom member inserted in assembly.  

Why I need this: I am writing a code which will change row of a ipart member (.ChangeRow(sLine, iPartCustom) but I need to change some of the custom values as well. And before it I want to list the current values.

 

Thanks

5 REPLIES 5
Message 2 of 6

Hello again,
anybody who knows if possible?

thanks

Message 3 of 6

Could you please consider the following code sample.

It gets the first component in the active assembly document  and assuming that it’s an iPartMember it prints all the iPartFactory table content.  You should use iPartTableCell.Value property to get or set the value of the cell (if this cell does not contain formula, to check this fact you may use the HasFormula property).  This sample changes the custom values in the 4th table row and save the new iPart member on the disk.

Finally ComponentOccurrence.Replace method is used to replace the current iPart member with the new one.

 

Sub Replace_iPartMember_in_Asm()
    'active assembly
    Dim oAssyDoc As Inventor.Document
    Set oAssyDoc = ThisApplication.ActiveDocument
    Call oAssyDoc.Update
    'assembly definition
    Dim oAssyDef As AssemblyComponentDefinition
    Set oAssyDef = oAssyDoc.ComponentDefinition
    'reference to the occurrence that represent iPart member
    '(here it is the first component in the browser)
    Dim oOcc As ComponentOccurrence
    Set oOcc = oAssyDef.Occurrences.Item(1)
    'part definition
    Dim oDef As PartComponentDefinition
    Set oDef = oOcc.Definition

    Dim oRow As iPartTableRow
    Dim oColumn As iPartTableColumn
    Dim i As Integer, j As Integer
    
    'reference to the iPart member
    Dim oMember As iPartMember
    Set oMember = oDef.iPartMember
    'reference to the iPart factory
    Dim oFactory As iPartFactory
    Set oFactory = oMember.ParentFactory
    'table columns list
    Dim oColumns As iPartTableColumns
    Set oColumns = oFactory.TableColumns
    'table rows list
    Dim oRows As iPartTableRows
    Set oRows = oFactory.TableRows
    
    'print the  current table content
    'headers
    Debug.Print "i",
    For j = 1 To oColumns.Count
        Set oColumn = oColumns.Item(j)
        Debug.Print oColumn.DisplayHeading,
    Next j
    Debug.Print
    'table cells' values
    For i = 1 To oRows.Count
        Set oRow = oRows.Item(i)
        Debug.Print i,
        For j = 1 To oColumns.Count
            Debug.Print oRow.Item(j).value,
        Next j
        Debug.Print
    Next
    
    'current custom values in the given row (4th here)
    Set oRow = oRows.Item(4)
    Debug.Print oRow.Item(3).value, oRow.Item(4).value
    'set new custom values
    oRow.Item(3).value = "2 in"
    oRow.Item(4).value = "25 deg"
    Debug.Print oRow.Item(3).value, oRow.Item(4).value
    
    'new filename
    Dim newFilename As String
    newFilename = oFactory.MemberCacheDir & "\" & "A" & oMember.Name
    Debug.Print "newFilename = " & newFilename
    
    'create new member
    Dim oNewMember As iPartMember
    Set oNewMember = oFactory.CreateCustomMember(newFilename, 4)
    oFactory.Parent.Update
    oFactory.Parent.Save

    'replace file reference
    Call oOcc.Replace(newFilename, False)

    'print the  current table content
    'headers
    Debug.Print "i",
    For j = 1 To oColumns.Count
        Set oColumn = oColumns.Item(j)
        Debug.Print oColumn.DisplayHeading,
    Next j
    Debug.Print
    'table cells' values
    For i = 1 To oRows.Count
        Set oRow = oRows.Item(i)
        Debug.Print i,
        For j = 1 To oColumns.Count
            Debug.Print oRow.Item(j).value,
        Next j
        Debug.Print
    Next
    
    Beep
End Sub

 

before                                                           after

1.png  2.png

 

Debug print:

i             Member        Part Number   d0            d1            
 1            Part1-01      Part1-01      3             0 deg         
 2            Part1-03      Part1-03      2 in          5 deg         
 3            Part1-04      Part1-04      3 in          10 deg        
 4            Part1-02      Part1-02      4 in          10 deg        
4 in          10 deg
2 in          25 deg
newFilename = C:\PR\iPart_Demo\iPart_Custom\APart1-042.ipt
i             Member        Part Number   d0            d1            
 1            Part1-01      Part1-01      3             0 deg         
 2            Part1-03      Part1-03      2 in          5 deg         
 3            Part1-04      Part1-04      3 in          10 deg        
 4            Part1-02      Part1-02      2 in          25 deg
cheers,

Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 4 of 6

Hello Vladimir,

thanks!

 

Is there any way to get the current row of the iPart inserted in the assembly?

 

'current custom values in the given row (4th here)
    Set oRow = oRows.Item(4)

 

 

Thanks

Jiri

Message 5 of 6

No problem.  iPartTableRow object gives you access to any row properties:

Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oDef As PartComponentDefinition
Set oDef = oDoc.ComponentDefinition

'reference to the iPart member
Dim oMember As iPartMember
Set oMember = oDef.iPartMember
'reference to the table row
Dim oRow As iPartTableRow
Set oRow = oMember.Row
'print some row properties
Debug.Print "MemberName: " & oRow.MemberName
Debug.Print "PartName: " & oRow.PartName
Debug.Print "Index: " & oRow.index

 cheers,


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 6 of 6

thank you for your help!

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

Post to forums  

Autodesk Design & Make Report