Message 1 of 27
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello again,
I'm trying to create a rule which can be run from an assembly and update/create all the ilogics of each part in that assembly. I have a macro that works fine when I open a part one by one. This macro creates or updates all the ilogic rules, parameters and iproperties needed, no problem here.
The problem comes when I try to run a simple rule from an assembly and iterate through all the part or occurrecces.
This code is from hoppend.nl, I simply modified it a bit.
Sub Main()
'Define the Assembly Document
Dim oDoc As AssemblyDocument
Dim RuleName As String = "Check"
' check if active document is an assembly
Try
oDoc = ThisApplication.ActiveDocument
Catch
MessageBox.Show("Please run on assembly", "Run Rule")
End Try
Dim oOcc As ComponentOccurrence
GoThrough:
For Each oOcc In oDoc.ComponentDefinition.Occurrences
'Get Document from Occurrence
Dim oOccDoc As Document
oOccDoc = oOcc.Definition.Document
'Check if document is a part
If oOccDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
oOccDoc = oOcc.Definition.Document
Try
InventorVb.RunMacro("Default", "Importar_ilogic", "Importar_ilogic")
iLogicVb.RunRule(oOccDoc.DisplayName, RuleName)
'MessageBox.Show("Rule run in: " & oOccDoc.DisplayName, "Message for debugging purposes")
Catch
'MessageBox.Show("Rule not present in: " & oOccDoc.DisplayName, "Message for debugging purposes")
End Try
'if the document is an assembly we need to run the same code in each occurrence of that assembly (we uses a goto function)
Else If oOccDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
oDoc = oOccDoc
GoTo GoThrough
End If
Next
End Sub
And I also tried this code (just ignore the vendor check):
Dim openDoc As Document
openDoc = ThisDoc.Document
Dim docFile As Document
If openDoc.DocumentType = 12291 Then
On Error Resume Next
For Each docFile In openDoc.AllReferencedDocuments
If docFile.DocumentType = 12290 Then
prov_data = iProperties.Value(docFile.DisplayName, "Project", "Vendor")
If prov_data = "Prov1" Then
InventorVb.RunMacro("Default", "Importar_ilogic", "Importar_ilogic")
'iLogicVb.RunRule("PartA:1", "ruleName")
End If
End If
Next
End If
Any idea how I can solve this?
Thank you a lot in advance.
Solved! Go to Solution.