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: 

help - cannot replace Washer & Nut in assy by ilogic

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
Carthik_Babu
1526 Views, 12 Replies

help - cannot replace Washer & Nut in assy by ilogic

Hi,

 

I am trying to replace Bolt, Washer and Nut using ilogic,  based on selection.

screw1.jpg

 

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

 

Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Tags (1)
12 REPLIES 12
Message 2 of 13
Carthik_Babu
in reply to: Carthik_Babu

Today the code worked and replaced every part file only once...then later on started pinging the same error......am i missing some code...????
Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Message 3 of 13
Carthik_Babu
in reply to: Carthik_Babu

Any Help regarding this error....... 😞
Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Message 4 of 13

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.

Message 5 of 13

Hi,
I have ISO Library Installed in my system. I can replace the content center part manually, but not by ilogic.

 

cc.png

 

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.

proj set.png

 

i am trying to understand...what is affecting the code. still have no solution. kindly find below the image of error in the rule.

 

cc error.png

 

 

 

 

 

 

Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Message 6 of 13

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

ISO 7089.png

 

I can fetch the details of washer and table details from cc. Really don't know where i am messing up...????

 

Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Message 7 of 13

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? 

Message 8 of 13

Hi,
Thanks,I tried your VB 2010 code and it inserted - ISO CC Files into my assembly. I tried my ilogic code after that too....it shows same error.....VB Code works fine for all CC components.....hmm... i have to check out ilogic error....??
Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Message 9 of 13

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

Message 10 of 13

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.

 

 

Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Message 11 of 13

Can you please check my assembly file, which i have posted in the first post
Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/
Message 12 of 13
cadull_rb
in reply to: Carthik_Babu

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

Message 13 of 13
Carthik_Babu
in reply to: cadull_rb

Hi,
Thanks a lot for the solution. Sorry for the delayed reply, I was bit busy in implementing the same in my project.
Carthik Babu M.S, Asst Manager - Machine Building,
Gabriel India Ltd,Hosur, TN, INDIA
Email:carthik_ms@yahoo.co.in ,
https://grabcad.com/carthik-1/projects
"May all beings be happy" http://www.dhamma.org/

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

Post to forums  

Autodesk Design & Make Report