
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I am trying to replace Bolt, Washer and Nut using ilogic, based on selection.
But i am stuck with some errors in the code. I cannot find, where i am going wrong. I got error message,shown below
Error in rule: Replace Rule, in document: Bolt_Nut_Assy
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
Sub Main()
Occ1=SelectOccurance("ISO 4018:1")
ReplaceContentCenterPart(Occ1, "Fasteners", "Bolts", "Hex Head", "ISO 4018", SNO_4018)
Occ1=SelectOccurance("ISO 7089:1")
ReplaceContentCenterPart(Occ1, "Fasteners", "Washers", "Plain", "ISO 7089", SNO_7089)
Occ1=SelectOccurance("ISO 4032:1")
ReplaceContentCenterPart(Occ1, "Fasteners", "Nuts", "Hex", "ISO 4032", SNO_4032)
Occ1=SelectOccurance("ISO 4035:1")
ReplaceContentCenterPart(Occ1, "Fasteners", "Nuts", "Hex", "ISO 4035", SNO_4035)
iLogicVb.UpdateWhenDone = True
ThisApplication.ActiveView.Fit
End Sub
Function ReplaceContentCenterPart(ByVal oOcc As ComponentOccurrence,ByVal Top_Node As String,ByVal ChildNodes1 As String,ByVal ChildNodes2 As String,ByVal Family_Name As String,ByVal No1 As Double)
' Set a reference to the active assembly document.
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
If oOcc.DefinitionDocumentType <> kPartDocumentObject Then
MsgBox( "Occurrence does not reference a content part.")
Exit Function
End If
Dim oOccDef As PartComponentDefinition
oOccDef = oOcc.Definition
If Not oOccDef.IsContentMember Then
MsgBox ("The occurrence does not reference a content part.")
Exit Function
End If
Dim fileName As String = String.Empty
Dim CustomPartDirectory= ThisDoc.Path & "\"
Dim isCustom As Boolean = m_customInfo IsNot Nothing
Dim refresh As Inventor.ContentMemberRefreshEnum = ContentMemberRefreshEnum.kUseDefaultRefreshSetting
' Set a reference to the ContentCenter object.
Dim oContentCenter As ContentCenter
oContentCenter = ThisApplication.ContentCenter
' Get the content node (category)
Dim oContentNode As ContentTreeViewNode
MsgBox(Top_Node &"" &ChildNodes1 &"" &ChildNodes2 )
oContentNode = oContentCenter.TreeViewTopNode.ChildNodes.Item(Top_Node).ChildNodes.Item(ChildNodes1).ChildNodes.Item(ChildNodes2)
' Get the Family object.
Dim oFamily As ContentFamily
For Each oFamily In oContentNode.Families
If oFamily.DisplayName = Family_Name Then
'MsgBox (oFamily.DisplayName)
Exit For
End If
Next
' Create a member based on the row no of the family.
Dim Error1 As MemberManagerErrorsEnum
Dim strContentPartFileName As String
Dim strErrorMessage As String
'fileName = IO.Path.Combine(CustomPartDirectory, MakeValidFileName(Family_Name+" " +Details + ".ipt"))
strContentPartFileName = oFamily.CreateMember(No1, Error1, strErrorMessage)
Call oOcc.Replace(strContentPartFileName, False)
End Function
Public Dim Occ1 As ComponentOccurrence
Function SelectOccurance(ByVal OccurenceName As String) As ComponentOccurrence
Dim Occurence As ComponentOccurrence
'Dim oAsmCompDef As AssemblyComponentDefinition
'oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
For Each Occurence In oAsmDoc.ComponentDefinition.Occurrences
If Occurence.Name = OccurenceName Then
Occ1=Occurence
'MsgBox(Occurence.Name)
Exit For
End If
Next Occurence
Return Occurence
End Function
Request you to kindly help, where i am going wrong...
I tried one more method...i tried to place component based on Family Name....the code below
Sub Main()
CcTest("ISO 4032")
End Sub
Public Function GetFamily( _
name As String, node As ContentTreeViewNode) _
As ContentFamily
Dim cc As ContentCenter
cc = ThisApplication.ContentCenter
If node Is Nothing Then node = cc.TreeViewTopNode
Dim cf As ContentFamily
For Each cf In node.Families
If cf.DisplayName = name Then
GetFamily = cf
'MsgBox(cf.FileNameColumn)
Exit Function
End If
Next
Dim child As ContentTreeViewNode
For Each child In node.ChildNodes
cf = GetFamily(name, child)
If Not cf Is Nothing Then
GetFamily = cf
Exit Function
End If
Next
End Function
Public Sub CcTest(ByVal FamilyName1 as String)
Dim asm As AssemblyDocument
asm = ThisApplication.ActiveDocument
Dim cf As ContentFamily
cf = GetFamily(FamilyName1, Nothing)
Dim member As String
Dim ee As MemberManagerErrorsEnum
member = cf.CreateMember(1, ee, "Problem")
Dim tg As TransientGeometry
tg = ThisApplication.TransientGeometry
Call asm.ComponentDefinition.Occurrences.Add( _
member, tg.CreateMatrix())
End Sub
I can place Bolt ( by code
CcTest("ISO 4018")
) , but not washer, nut....i get error message as shown below for the above code....
Error in rule: CC insert-based on family name, in document: Bolt_Nut_Assy
Object reference not set to an instance of an object.
Stuck with where i am going wrong......do help
Solved! Go to Solution.