Some adjustment may be required for your needs.
Some comments are done by me in dutch, where you find dutch comments I edited some things to the original code. Here you should also make edits I guess.
Private Sub WN_RF(ByVal oAsmDoc As AssemblyDocument,
ByVal oAsmDef As AssemblyComponentDefinition,
ByRef oPipeDiameter As String,
ByRef oFlangeHeight As String,
ByRef oFlangeChange As Boolean)
Dim i As Integer
' get the some occurrence - should be a custom CC member
Dim oOcc As ComponentOccurrence
oOcc = oAsmDef.Occurrences.ItemByName("Noz_Flange")
Dim oDef As PartComponentDefinition
oDef = oOcc.Definition
'check: if this component is custom or standard?
If oDef.IsContentMember Then
MsgBox("this sample works with the custom CC member only")
Exit Sub
Else
Debug.Print("It's a Custom CC member")
End If
Dim oDoc As PartDocument
oDoc = oDef.Document
'reference to the CC properties - oProps
Dim oProps As PropertySet
oProps = oDoc.PropertySets.Item("Content Library Component Properties")
'get the family id
Dim oProp As Inventor.Property
oProp = oProps.Item("FamilyId")
Dim FamilyId As String
FamilyId = oProp.Value
Debug.Print("--------------------------------------------")
Debug.Print("*** Content Family Info from iProperties ***")
Debug.Print("--------------------------------------------")
For i = 1 To oProps.Count
oProp = oProps.Item(i)
Debug.Print(oProp.Name & " = " & oProp.Value)
Next i
'reference to the CC family
Dim oContentCenter As ContentCenter
oContentCenter = oInvApp.ContentCenter
Dim oFamily As ContentFamily
oFamily = oContentCenter.GetContentObject("v3#" + FamilyId + "#")
'information on the family from the ContentFamily object
Debug.Print("-----------------------------------------------------")
Debug.Print("*** Content Family Info from ContentFamily object ***")
Debug.Print("-----------------------------------------------------")
Call PrintFamilyInfo(oFamily)
'----------------------------------------
' get the current MemberId
oProp = oProps.Item("MemberId")
Dim MemberId As String
MemberId = oProp.Value
Debug.Print("Current MemberId (row): " & MemberId)
' search for the new row ID
Dim newRow As Integer
newRow = -1
Dim oSizeColumnIndex As Integer
oSizeColumnIndex = -1
Dim oRatingColumnIndex As Integer
oRatingColumnIndex = -1
' Zoeken naar de sturende kolommen
For i = 1 To oFamily.TableColumns.Count
If oFamily.TableColumns.Item(i).InternalName = "ND" Then
oSizeColumnIndex = i
ElseIf oFamily.TableColumns.Item(i).InternalName = "Rating" Then
oRatingColumnIndex = i
End If
' Controleren als de sturende kolommen gevonden zijn
If oSizeColumnIndex > 0 And oRatingColumnIndex > 0 Then
Exit For
End If
Next
' Stoppen als de juiste kolommen niet gevonden zijn
If oSizeColumnIndex = -1 Or oRatingColumnIndex = -1 Then
MsgBox("Something has gone wrong. Search column(s) not found.",
MsgBoxStyle.Critical, "Error: Change flange size")
Exit Sub
End If
' Zoeken naar de rij met de juiste afmetingen van flens
For i = 1 To oFamily.TableRows.Count
If oFamily.TableRows.Item(i).Item(oSizeColumnIndex).Value = WN_ND.Text And
oFamily.TableRows.Item(i).Item(oRatingColumnIndex).Value = WN_RATING.Text Then
newRow = i
Debug.Print("The row searched for = " & newRow)
Exit For
End If
Next
' Controleren als de rij gevonden is
If newRow = -1 Then
MsgBox("The dimensions are not found in the librairy." & vbLf &
"Please change size or add the dimensions in the Content center.",
MsgBoxStyle.Information, "Info: Flange not found")
Exit Sub
ElseIf MemberId = newRow Then
oFlangeChange = False
Debug.Print("Same component size. No change needed")
Exit Sub
End If
'ask user for the new row number:
'Dim newRow As Integer
'newRow = InputBox("Current Family row is " & MemberId _
' & vbNewLine & vbNewLine & "New Family row:", _
' "New Family Row:", MemberId)
'Debug.Print("newRow: " & newRow)
'----------------------------------------
Dim oRow As ContentTableRow
oRow = oFamily.TableRows.Item(newRow)
Dim nCol As Integer 'table column for this oPar
Dim oColumn As ContentTableColumn
'read CC table row data and update user parameters
'"""""""""""""""""""""""""""""""""""""""""""""""""
Dim oPar As UserParameter
Dim x As Double = 0 ' flens hoogte optellen
Dim y As String = "" ' flens hoogte eenheid
For Each oPar In oDef.Parameters.UserParameters
'ignore parameters that depends on the other parameters
If oPar.DrivenBy.Count = 0 Then
Debug.Print("Par name: " & oPar.Name)
Debug.Print("Current value: " & oPar.Value)
'find nCol - table column for oPar.Name
nCol = -1
For i = 1 To oFamily.TableColumns.Count
If oFamily.TableColumns.Item(i).InternalName = oPar.Name Then
nCol = i
Exit For
End If
Next
If nCol = -1 Then
Debug.Print("Column not found, so parameter was not changed")
Else
oColumn = oFamily.TableColumns.Item(nCol)
If oColumn.KeyColumnOrder > 0 Then
'leave this value untouched
'e.g., "B_L" (Bar Length)
Debug.Print("Key value (not changed): " & oPar.Expression)
Else
Dim units As String
units = oColumn.Units
Dim oCell As ContentTableCell
oCell = oRow.Item(nCol)
Dim value As String
value = oCell.Value & " " & units
oPar.Expression = value
Debug.Print("New value: " & value)
If oPar.Name = "A" Then
oPipeDiameter = value
Debug.Print("Diameter pipe = " & value)
End If
If oPar.Name = "Y" Or oPar.Name = "RF_t" Then
x = x + oCell.Value
y = units
End If
End If
End If
End If 'oPar is not driven by other parameters
Next
oFlangeHeight = x & " " & y
Debug.Print("Flens hoogte = " & oFlangeHeight)
'----------------------------------------
'--------------------------
' Update iProperties
'--------------------------
Debug.Print(vbNewLine & "*** Update iProperties ***" & vbNewLine)
'1) "Content Library Component Properties"
'update iProperty "MemberId"
oProp = oProps.Item("MemberId")
oProp.Value = newRow
Debug.Print("MemberId = " & newRow)
' update iProperty "Member Revision" with new GUID
oProp = oProps.Item("Member Revision")
oProp.Value = CreateGuid()
Debug.Print("Member Revision = " & oProp.Value)
'2) "Design Tracking Properties"
Dim oDesignProps As PropertySet
oDesignProps = oDoc.PropertySets.Item("Design Tracking Properties")
' update iProperty "Part Number"
Dim partNumber As String
partNumber = NewPropertyValue(oDef, oFamily, newRow, "PARTNUMBER")
oProp = oDesignProps.Item("Part Number")
oProp.Value = partNumber
Debug.Print("Part Number = " & partNumber)
' update iProperty "Description"
Dim Description As String
Description = NewPropertyValue(oDef, oFamily, newRow, "Description")
oProp = oDesignProps.Item("Description")
oProp.Value = partNumber
Debug.Print("Description = " & Description)
' update iProperty "Stock Number"
Dim stockNumber As String
stockNumber = NewPropertyValue(oDef, oFamily, newRow, "STOCKNUMBER")
oProp = oDesignProps.Item("Stock Number")
oProp.Value = stockNumber
Debug.Print("Stock Number = " & stockNumber)
'----------------------------------------
oDoc.Update()
oDoc.Save()
Debug.Print(vbNewLine & "member document updated and saved")
'update component name in the browser
On Error Resume Next
oOcc.Name = "Noz_Flange"
'If Err() Then
'name is already used
'oOcc.Name = partNumber & ":1"
'End If
On Error GoTo 0
oAsmDoc.Update()
End Sub 'CustomMember_ChangeRow
'********************************************
Private Sub PrintFamilyInfo(ByRef oFamily As ContentFamily)
' Print Content Family Info
Dim st As String
Debug.Print("Family DisplayName: " + oFamily.DisplayName)
Debug.Print("Description : " & oFamily.Description)
'what type of family this family is: part or feature?
Select Case oFamily.FamilyType
Case ContentFamilyTypeEnum.kContentFeatureFamily
Debug.Print("Family Type: " & "Content Feature Family")
Case ContentFamilyTypeEnum.kContentPartFamily
Debug.Print("Family Type: " & "Content Part Family")
End Select
Debug.Print("Internal name : " + oFamily.InternalName)
Debug.Print("Is Custom : " & oFamily.IsCustom)
Debug.Print("Is Modifiable : " & oFamily.IsModifiable)
Debug.Print("Family Library Name : " & oFamily.LibraryName)
Debug.Print("Family Library InternalName: " & oFamily.LibraryInternalName)
Debug.Print("Library Manufacturer : " & oFamily.Manufacturer)
Debug.Print("Family MemberDirectory : " & oFamily.MemberDirectory)
Debug.Print("Family RevisionId : " & oFamily.RevisionId)
Debug.Print("Family Standard : " & oFamily.Standard)
Debug.Print("Family StandardOrganization: " & oFamily.StandardOrganization)
Debug.Print("Family StandardRevision : " & oFamily.StandardRevision)
Debug.Print("Family Columns : " & oFamily.TableColumns.Count)
Debug.Print("Family Rows : " & oFamily.TableRows.Count)
Debug.Print("")
Debug.Print("-------------------------------")
Debug.Print("***** Family Columns Info *****")
Debug.Print("-------------------------------")
Dim i As Integer
Dim oCol As ContentTableColumn
For i = 1 To oFamily.TableColumns.Count
oCol = oFamily.TableColumns.Item(i)
' the name of this column.
Debug.Print(i & "" & oCol.InternalName)
' the type of value defined for this column.
Select Case oCol.DataType
Case ValueTypeEnum.kIntegerType
st = "Integer"
Case ValueTypeEnum.kDoubleType
st = "Double"
Case ValueTypeEnum.kStringType
st = "String"
Case ValueTypeEnum.kBooleanType
st = "Boolean"
End Select
Debug.Print(st)
'display name of this column.
Debug.Print("DisplayHeading: " & oCol.DisplayHeading)
'units of the column.
If oCol.Units <> "" Then _
Debug.Print(" Units: " & oCol.Units)
'indicates if this column is mapped to an iProperty
If oCol.HasPropertyMap Then _
Debug.Print(" HasPropertyMap: " & oCol.HasPropertyMap)
'KeyColumnOrder: specifies if this column is a key column
'and what order this column should be in the key column list.
'The key columns are displayed on the Select tab when placing a content part.
If oCol.KeyColumnOrder > 0 Then
Debug.Print("KeyColumnOrder: " & oCol.KeyColumnOrder)
Else
Debug.Print(" ")
End If
'Expression: is used to automatically populate the rows of this column.
If TypeOf oCol.Expression Is ExpressionLimits Then
Dim limits As ExpressionLimits
limits = oCol.Expression
Debug.Print(" Expression limits.DefaultValue = " & limits.DefaultValue)
Debug.Print(" Expression limits.MaximumValue = " & limits.MaximumValue)
Debug.Print(" Expression limits.MinimumValue = " & limits.MinimumValue)
ElseIf oCol.Expression = Nothing Then
'Debug.Print " Expression: empty"
Else
Dim expr As Object
expr = oCol.Expression
Debug.Print(" Expression: " & expr)
End If
Next
Debug.Print("--------------------------------")
End Sub 'PrintFamilyInfo
'********************************************
Private Function NewPropertyValue( _
ByRef oDef As PartComponentDefinition, _
ByRef family As ContentFamily, _
ByRef newRow As Integer, _
ByVal ColumnName As String) As String
'fills the template expressions in PARTNUMBER
'and STOCKNUMBER columns with actual data.
'to update the corresponding member's iProperties
'(Part Number and Stock Number)
Debug.Print("")
Debug.Print("enter f-n NewPropertyValue")
Debug.Print("ColumnName = " & ColumnName)
Dim nCol As Integer
nCol = GetColumnByName(family, ColumnName)
If nCol = -1 Then
'error - column not found :-(
NewPropertyValue = ""
Exit Function
End If
Dim oColumn As ContentTableColumn
oColumn = family.TableColumns.Item(nCol)
Dim expr As String
expr = oColumn.Expression
Debug.Print("Column.Expression (template) = " & expr)
'CC table row for this member
Dim oRow As ContentTableRow
oRow = family.TableRows.Item(newRow)
'fill template string with values from oRow
expr = FillPropWithValues(oDef, family, oRow, expr)
Debug.Print("Template filled with data = " & expr)
NewPropertyValue = expr
End Function
'********************************************
Private Function FillPropWithValues( _
ByRef oDef As PartComponentDefinition, _
ByRef oFamily As ContentFamily, _
ByRef oRow As ContentTableRow, _
ByVal template As String) As String
' Replaces placeholders in the column 'template' expression
' with the actual data from the given family row.
' Example:
' template: "Angle {Size Designation}-{B_L} GOST 13617-97"
' result : "Angle 511349-23 GOST 13618-97"
' Important note: this code doesn't analyse nested curly braces
Debug.Print("*** FillPropWithValues ***")
Debug.Print("template = " & template)
Dim s As String
Dim oColl As New Collection
'concatenation
'from: "AISC" & " - " & {G_D} & " - " & {B_L}
'to: AISC - {G_D} - {B_L}
template = Replace(Replace(template, " & ", ""), Chr(34), "")
Call GetNames(template, oColl)
'replace parameters' names with values
Dim ss As Object
For Each ss In oColl
s = GetValueByColumnName(oDef, oFamily, oRow, ss)
template = Replace$(template, "{" & ss & "}", s)
Next
Debug.Print("Final property value: " & template)
FillPropWithValues = template
oColl = Nothing
End Function 'FillPropWithValues
'********************************************
Private Sub GetNames(ByVal inS As String, ByRef oColl As Collection)
' Finds all the column names in curly braces that exist in the string inS,
' and adds them to the collection oColl.
' Example: for the template
' inS = "Angle {Size Designation}-{B_L} GOST 13617-97"
' it will add two column names to oColl:
' Size Designation
' B_L
'
' Will give an error if inS contains nested curly braces.
Dim s As String
Dim i As Integer, j As Integer
Do
' next pair of {..}
i = InStr(1, inS, "{")
j = InStr(1, inS, "}")
If (i = 0) Or (j = 0) Then Exit Do
'what is inside curly braces?
s = Mid$(inS, i + 1, j - i - 1)
If s <> "" Then
'add name s to the collection
Call oColl.Add(s)
inS = Mid$(inS, j + 1, Len(inS))
End If
Loop Until s = ""
End Sub 'GetNames
'********************************************
Private Function GetValueByColumnName( _
ByRef oDef As PartComponentDefinition, _
ByRef family As ContentFamily, _
ByRef row As ContentTableRow, _
ByVal ColumnName As String) As String
'returns the value that is stored in the CC family table
'in the row in the column with the given ColumnName
Dim nCol As Integer
nCol = GetColumnByName(family, ColumnName)
If nCol = -1 Then
GetValueByColumnName = ""
Exit Function
End If
Dim oColumn As ContentTableColumn
oColumn = family.TableColumns.Item(nCol)
If (oColumn.KeyColumnOrder > 0) Then
'value should be taken from user parameters as it could be overridden
On Error Resume Next
Dim oPar As UserParameter
oPar = oDef.Parameters.UserParameters.Item(ColumnName)
'If Err Then
'GetValueByColumnName = row.Item(nCol).Value
'Err.Clear()
'Else
Dim s As String
s = oPar.Expression
'remove units of measure
'GetValueByColumnName = Left(s, InStr(s, " ") - 1)
'End If
On Error GoTo 0
Else
GetValueByColumnName = row.Item(nCol).Value
End If
End Function 'GetValueByColumnName
'********************************************
Private Function GetColumnByName( _
ByRef family As ContentFamily, _
ByVal ColumnName As String) As Integer
'find CC family table column by its name ColumnName
Dim i As Integer
For i = 1 To family.TableColumns.Count
If family.TableColumns.Item(i).InternalName = ColumnName Then
Debug.Print("f-n GetColumnByName: " & i & " " & family.TableColumns.Item(i).InternalName)
GetColumnByName = i
Exit Function
End If
Next
GetColumnByName = -1
End Function
Private Function CreateGuid()
' Returns a unique Guid on every call. Removes any cruft.
' https://msdn.microsoft.com/en-us/subscriptions/sh9ete15(v=vs.84).aspx
' http://stackoverflow.com/questions/968756/how-to-generate-a-guid-in-vbscript
CreateGuid = Mid$(CreateObject("Scriptlet.TypeLib").GUID, 2, 36)
End Function
Please kudo if this post was helpfull
Please accept as solution if your problem was solved
Inventor 2014 SP2