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
Solved! Go to Solution.
Solved by Vladimir.Ananyev. Go to Solution.
Solved by Vladimir.Ananyev. Go to Solution.
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
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 degcheers,
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
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,