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.
Solved by cadull_rb. Go to Solution.
Hi Carthik ,
I'd suggest you debug by VB.NET if it is not a challenge to you. The VB.NET tells cf is Nothing (after the iteration) because it did not find the family named "ISO 4032". I have no ISO library installed, so I got the same error.
I have ANSI lib installed. After I changed it to such as "ANSI/B93.98M", the code works well every time I ran it.
Hi,
I have ISO Library Installed in my system. I can replace the content center part manually, but not by ilogic.
In my project file, i have replaced "Content Center File Creation location" from default to our network location, so that everyone can share and handle the file.
i am trying to understand...what is affecting the code. still have no solution. kindly find below the image of error in the rule.
Hi,
I used the below code to Fetch CC property
Sub Main()
GetContentObject_Test()
End Sub
Sub GetContentObject_Test()
Dim oOcc As ComponentOccurrence
oOcc = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Pick occurrence")
If oOcc.DefinitionDocumentType <> kPartDocumentObject Then
MsgBox ("The occurrence is not a CC part.")
Exit Sub
End If
Dim oOccDef As PartComponentDefinition
oOccDef = oOcc.Definition
If Not oOccDef.IsContentMember Then
MsgBox ("The occurrence is not a CC part.")
Exit Sub
End If
' Set a reference to the ContentCenter object.
Dim oContentCenter As ContentCenter
oContentCenter = ThisApplication.ContentCenter
' Reference "CC Library Component
' Properties' propertyset
Dim propSet As PropertySet
propSet = oOccDef.Document.PropertySets.Item("{B9600981-DEE8-4547-8D7C-E525B3A1727A}")
' Get FamilyId property
'Dim familyId1 As Property
familyId1 = propSet.Item("FamilyId")
' Get MemberId property
Dim strMemberId As String
strMemberId = propSet("MemberId").Value
'MsgBox(strMemberId)
'Dim msgBoxResult As VbMsgBoxResult
'msgBoxResult = MsgBox _
'("Get Family ?", vbYesNo, "Yes=Family No=Row") ,
j = MessageBox.Show("Get Family??; Yes=Family;No=Row", "My iLogic Dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
If j = vbYes Then
' Get family, (Not including memberId)
Dim oContentFamily As ContentFamily
oContentFamily = oContentCenter.GetContentObject("v3#" & familyId1.Value & "#")
'MsgBox(familyId1.Value)
MsgBox("family display name: " +oContentFamily.DisplayName +vbCr +"family LibraryName name: " +oContentFamily.LibraryName)
Else
' Get Table Row, (Including memberId)
Dim oContentTableRow As ContentTableRow
oContentTableRow = oContentCenter.GetContentObject("v3#" & familyId1.Value & "#" & strMemberId)
MsgBox("RowString No: " &strMemberId/10)
Dim Str As String
Str = "Data from cells in Table Row" & vbCr &strMemberId/10
' Debug.Print oContentTableRow.count
'MsgBox(oContentTableRow.count)
For i = 1 To oContentTableRow.count
' Debug.Print i
' Debug.Print oContentTableRow.GetCellValue(i)
Str = Str &" -- " & oContentTableRow.GetCellValue(i)
Next
MsgBox (Str )
End If
End Sub
I can fetch the details of washer and table details from cc. Really don't know where i am messing up...????
Hi,
I have no more idea at this moment, but could you try with the attached VB.NET project to see if there is any ISO items could be dumped?
Hi Carthik ,
I got a machine with ISO lib installed. And I tested the iLogic code directly. It works well. The attachment is my testing video. The version I am using is Inventor 2014
Dear Sir,
Thanks for the video.....aftwer watching your video, i tried the same code by working on default project, which handles content center file creation in local hard disk. It worked for me too.......
But, i found by placing Msgbox before and after oContentNode creation & found that the oContentNode creation fails.....
MsgBox(Top_Node &"" &ChildNodes1 &"" &ChildNodes2 )
oContentNode = oContentCenter.TreeViewTopNode.ChildNodes.Item(Top_Node).ChildNodes.Item(ChildNodes1).ChildNodes.Item(ChildNodes2)
may be i am doing some thing wrong on Node Naming (or)
ReplaceContentCenterPart(occ, "Fasteners", "Washers", "Plain", "ISO 7089", SNO_7089)
may be the project file, which i have set has some problem.
Hi Carthik,
You may be encountering the same issue I had related to COM and garbage collection. Fortunately I spotted the method CompensateForComDefect at the end of http://forums.autodesk.com/autodesk/attachments/autodesk/78/429065/1/ContentCenterReplace.txt.
Private Sub CompensateForComDefect() ' The Content Center API will remember a previous child node, and it will not enumerate other siblings of the same parent. ' They are counting on the caller to release the reference. System.GC.Collect() End Sub
You need to garbage collect previously used nodes before trying to find any of their siblings. This allows COM to release the object references. I'm not sure what impact iLogic has on achieving this.
When observing the nodes in Visual Studio, a node will initially have several child nodes. After using one of the child nodes, the parent node will subsequently report only having a single child node.
Regards,
cadull