Suppressed Assemblies stop my iterate command

Suppressed Assemblies stop my iterate command

SharkDesign
Mentor Mentor
610 Views
7 Replies
Message 1 of 8

Suppressed Assemblies stop my iterate command

SharkDesign
Mentor
Mentor

I have this code that works perfectly, but as soon as I suppress an assembly the rule will no longer work and I get an error. "Error in rule: Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))"

Works fine with suppressed parts. 

Any ideas?

 

Sub Main()
Dim oAsmDoc As AssemblyDocument 
oAsmDoc = ThisApplication.ActiveDocument  
Call Iterate(oAsmDoc.ComponentDefinition.Occurrences, 1)
End Sub 

Private Sub Iterate(Occurrences As ComponentOccurrences, Level As Integer) 
'Iterate through Assembly

Dim oOcc As ComponentOccurrence 
For Each oOcc In Occurrences 

'Find Parts in Assembly
Dim Part As String
Part = oOcc.Name

'Set parameter
Try
Parameter(Part, "ConExL")=ConExL
Catch
End Try
Try
Parameter(Part, "TotalBedLength")=TotalBedLength
Catch
End Try
Try
Parameter(Part, "Join")=Join
Catch
End Try
             
'Run through the sub assemblies 
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Call Iterate(oOcc.SubOccurrences, Level + 1) 
InventorVb.DocumentUpdate()
End If 
Next 
End Sub

Inventor 2018

  Inventor Certified Professional
0 Likes
Accepted solutions (2)
611 Views
7 Replies
Replies (7)
Message 2 of 8

Sergio.D.Suárez
Mentor
Mentor

I don't have your internal parameters, nor your assembly to test if the error occurs.
At first glance I see a situation that does not convince me. When the colors are bluish in ilogic, they internally refer to the parameters of the active file. If you look at the image "join" appears in red, it may conflict with the internal ilogic instructions. Imagine if we created a user parameter with the name "Try" or "Catch" maybe we could get errors.
You could try the following code, if you find an error you will not do anything, maybe you would have to approach the problem in another way.
I hope this helps. regards

 

Sub Main()
Dim oAsmDoc As AssemblyDocument 
oAsmDoc = ThisApplication.ActiveDocument  
Call Iterate(oAsmDoc.ComponentDefinition.Occurrences, 1)
End Sub 

Private Sub Iterate(Occurrences As ComponentOccurrences, Level As Integer) 


oJoin = ThisDoc.Document.Componentdefinition.Parameters("Join").Value


Dim oOcc As ComponentOccurrence 
For Each oOcc In Occurrences 

'Find Parts in Assembly
Dim Part As String = oOcc.Name

'Set parameter
Try
Parameter(Part, "ConExL")=ConExL
Catch
End Try
Try
Parameter(Part, "TotalBedLength")=TotalBedLength
Catch
End Try
Try
Parameter(Part, "Join")= oJoin
Catch
End Try
             
'Run through the sub assemblies 
If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Try
Call Iterate(oOcc.SubOccurrences, Level + 1)
InventorVb.DocumentUpdate()
Catch
End Try
End If
Next End Sub

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 3 of 8

Sergio.D.Suárez
Mentor
Mentor
Accepted solution

 

 

Sub Main
Dim oDoc As AssemblyDocument = ThisDoc.Document
oConExL = oDoc.ComponentDefinition.Parameters("ConExL").Value
oTotalBedLength = oDoc.ComponentDefinition.Parameters("TotalBedLength").Value
oJoin = oDoc.ComponentDefinition.Parameters("Join").Value

For Each doc As Document In oDoc.AllReferencedDocuments
On Error Resume Next
    doc.ComponentDefinition.Parameters("ConExL").Value = oConExL
	doc.ComponentDefinition.Parameters("TotalBedLength").Value = oTotalBedLength
	doc.ComponentDefinition.Parameters("TotalBedLength").Value = oJoin
Next
Parameter.UpdateAfterChange = True
iLogicVb.UpdateWhenDone = True
End Sub

Maybe an approach like this could be useful. 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 4 of 8

SharkDesign
Mentor
Mentor

The words in red are just parameter references.

I have attached a test assembly that you can test with any parts, the problem happens with any assembly put into it. 

 

 

 

 

  Inventor Certified Professional
0 Likes
Message 5 of 8

SharkDesign
Mentor
Mentor

Also I updated the original post because I realised it was assemblies not patterns that break it. 

  Inventor Certified Professional
0 Likes
Message 6 of 8

CCarreiras
Mentor
Mentor

Hi!

 

When you suppress a part, automatically a LOD is created.

Some kind of rules only work in Master LOD.

If it is the case, you have to find a way to set the LOD to master before run the rule and then set again the custom LOD after run the rule.

 

 

CCarreiras

EESignature

0 Likes
Message 7 of 8

SharkDesign
Mentor
Mentor
Accepted solution

Think I fixed it. 

Just removed all the trys and replaced it with the 'On Error Resume Next' command and it seems to have done it. 

  Inventor Certified Professional
0 Likes
Message 8 of 8

SharkDesign
Mentor
Mentor

I assume this rule goes through everything, is there a way to skip 'purchased' parts?

  Inventor Certified Professional
0 Likes