External Rule executed for all components in the assembly

External Rule executed for all components in the assembly

vkulikajevas
Advocate Advocate
3,441 Views
21 Replies
Message 1 of 22

External Rule executed for all components in the assembly

vkulikajevas
Advocate
Advocate


Can you help me write a code Ilogic Rule, that can access external rule for every body in the assembly?

External_XYZ_Rule writes extents of the part by X,Y,Z.

I need it to be executed automatically for all the Assembly parts, that Solid1, Solid2, Solid3 would have their extent parameters written in the custom parameters. 

 

See files attached:

 

0 Likes
Accepted solutions (2)
3,442 Views
21 Replies
Replies (21)
Message 2 of 22

Martin-Winkler-Consulting
Advisor
Advisor

Hi @vkulikajevas

i think it would be better to do this with VBA Makro.

I wrote some code for you which will update all Parts included in the Assembly, also in Subassemblies.

If the UserProperties are not existing in the part they will be added.

 

Copy the Code in a VBA module (run VBA with Alt+F11).

After copying the code  run the makro Extend_XYZ_Main from every Assembly you would like to update all parts.

 

Sub Extend_XYZ_Main()
    Dim oAsmDoc As AssemblyDocument
    Set oAsmDoc = ThisApplication.ActiveDocument
    Call Extend_XYZ_Traverse(oAsmDoc.ComponentDefinition.Occurrences, 1)
  End Sub

  Sub Extend_XYZ_Traverse(Occurrences As ComponentOccurrences, _
                             Level As Integer)
    ' Iterate through all of the occurrence in this collection.  This
    ' represents the occurrences at the top level of an assembly.
    Dim oOcc As ComponentOccurrence
    Dim oCustomPropSet As PropertySet
    Dim Model_X As Double
    Dim Model_Y As Double
    Dim Model_Z As Double
    
    For Each oOcc In Occurrences
     'If it is an Assembly go to next Level
     If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
      Call TraverseAssembly(oOcc.SubOccurrences, Level + 1)
     ElseIf oOcc.DefinitionDocumentType = kPartDocumentObject Then
         'Get the ranges
         Model_X = (oOcc.RangeBox.MaxPoint.x + (oOcc.RangeBox.MinPoint.x) * -1) * 10
         Model_Y = (oOcc.RangeBox.MaxPoint.Y + (oOcc.RangeBox.MinPoint.Y) * -1) * 10
         Model_Z = (oOcc.RangeBox.MaxPoint.Z + (oOcc.RangeBox.MinPoint.Z) * -1) * 10
         
         'Get the UserDefinedPropertySet
         Set oCustomPropSet = oOcc.Definition.Document.PropertySets.item(4)
         
         If CheckPropertyExists(oCustomPropSet, "ModelX") Then
          oOcc.Definition.Document.PropertySets.item(4).item("ModelX") = Model_X
         Else
          Call oCustomPropSet.Add(Model_X, "ModelX")
         End If
         
         If CheckPropertyExists(oCustomPropSet, "ModelY") Then
          oOcc.Definition.Document.PropertySets.item(4).item("ModelY") = Model_Y
         Else
          Call oCustomPropSet.Add(Model_Y, "ModelY")
         End If
         
         If CheckPropertyExists(oCustomPropSet, "ModelZ") Then
          oOcc.Definition.Document.PropertySets.item(4).item("ModelZ") = Model_Z
         Else
          Call oCustomPropSet.Add(Model_Z, "ModelZ")
         End If
      End If
     Next
End Sub

Public Function CheckPropertyExists(oProps As PropertySet, oPropName As String) As Boolean
 CheckPropertyExists = False
 Dim oProp As Property
 For Each oProp In oProps
    If oProp.Name = oPropName Then
        CheckPropertyExists = True
    End If
 Next
End Function

Martin Winkler
CAD Developer
Did you find this post helpful? Feel free to like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


EESignature

Message 3 of 22

vkulikajevas
Advocate
Advocate

Can you please help to define this Function?

 

Untitled.jpg

0 Likes
Message 4 of 22

Martin-Winkler-Consulting
Advisor
Advisor

Sorry @vkulikajevas

my mistake, there also has to be a call of  Extend_XYZ_Traverse :

 

Sub Extend_XYZ_Main()
    Dim oAsmDoc As AssemblyDocument
    Set oAsmDoc = ThisApplication.ActiveDocument
    Call Extend_XYZ_Traverse(oAsmDoc.ComponentDefinition.Occurrences, 1)
  End Sub

  Sub Extend_XYZ_Traverse(Occurrences As ComponentOccurrences, _
                             Level As Integer)
    ' Iterate through all of the occurrence in this collection.  This
    ' represents the occurrences at the top level of an assembly.
    Dim oOcc As ComponentOccurrence
    Dim oCustomPropSet As PropertySet
    Dim Model_X As Double
    Dim Model_Y As Double
    Dim Model_Z As Double
    
    For Each oOcc In Occurrences
     'If it is an Assembly go to next Level
     If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
      Call Extend_XYZ_Traverse(oOcc.SubOccurrences, Level + 1)
     ElseIf oOcc.DefinitionDocumentType = kPartDocumentObject Then
         'Get the ranges
         Model_X = (oOcc.RangeBox.MaxPoint.x + (oOcc.RangeBox.MinPoint.x) * -1) * 10
         Model_Y = (oOcc.RangeBox.MaxPoint.Y + (oOcc.RangeBox.MinPoint.Y) * -1) * 10
         Model_Z = (oOcc.RangeBox.MaxPoint.Z + (oOcc.RangeBox.MinPoint.Z) * -1) * 10
         
         'Get the UserDefinedPropertySet
         Set oCustomPropSet = oOcc.Definition.Document.PropertySets.item(4)
         
         If CheckPropertyExists(oCustomPropSet, "ModelX") Then
          oOcc.Definition.Document.PropertySets.item(4).item("ModelX") = Model_X
         Else
          Call oCustomPropSet.Add(Model_X, "ModelX")
         End If
         
         If CheckPropertyExists(oCustomPropSet, "ModelY") Then
          oOcc.Definition.Document.PropertySets.item(4).item("ModelY") = Model_Y
         Else
          Call oCustomPropSet.Add(Model_Y, "ModelY")
         End If
         
         If CheckPropertyExists(oCustomPropSet, "ModelZ") Then
          oOcc.Definition.Document.PropertySets.item(4).item("ModelZ") = Model_Z
         Else
          Call oCustomPropSet.Add(Model_Z, "ModelZ")
         End If
      End If
     Next
End Sub

Martin Winkler
CAD Developer
Did you find this post helpful? Feel free to like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


EESignature

Message 5 of 22

vkulikajevas
Advocate
Advocate

 Almost @Martin-Winkler-Consulting! One more definition, if you can help with!? 🙂

 

Untitled.jpg

0 Likes
Message 6 of 22

Martin-Winkler-Consulting
Advisor
Advisor

Did you copy this also in the module?

 

Public Function CheckPropertyExists(oProps As PropertySet, oPropName As String) As Boolean
 CheckPropertyExists = False
 Dim oProp As Property
 For Each oProp In oProps
    If oProp.Name = oPropName Then
        CheckPropertyExists = True
    End If
 Next
End Function

Martin Winkler
CAD Developer
Did you find this post helpful? Feel free to like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


EESignature

Message 7 of 22

vkulikajevas
Advocate
Advocate

@Martin-Winkler-Consulting, it gives another error then 😞

Actually I noticed, that the code just gives the 3 dimensions, parallel to X, Y, Z. I actually need more complicated code, which add extents to one parameter, and it sorts from the longest dimension to shortest. I have this code written in Ilogic. And it is stored under the External Rules. I just need to activate it in some ways for every component in an assembly. (

 

Alternatively I had an idea, if it is possible to create a rule inside the part and copy everything from external rule automatically via Ilogic or VBA.
Thank you for your code it does seem logical, defining the parameters and extents in VBA.

Untitled.jpg

 

In Ilogic this rule that I am trying to use looks like this.

 

 

Model_X=Round(Measure.ExtentsLength) 'X-axis BB length
Model_Y=Round(Measure.ExtentsWidth)  'Y-axis BB length
Model_Z=Round(Measure.ExtentsHeight) 'Z-axis BB length'Add / Update Bounding Box measurements to model's Custom Properties
iProperties.Value("Custom", "ModelX")=Model_X
iProperties.Value("Custom", "ModelY")=Model_Y
iProperties.Value("Custom", "ModelZ")=Model_Z


If Model_X > Model_Y And Model_Y > Model_Z Then 
iProperties.Value("Custom", "DIM")= Model_X & "x" & Model_Y & "x" & Model_Z

ElseIf Model_X > Model_Z And Model_Z > Model_Y Then 
iProperties.Value("Custom", "DIM")= Model_X & "x" & Model_Z & "x" & Model_Y

ElseIf Model_Y > Model_X And Model_X > Model_Z Then
iProperties.Value("Custom", "DIM")= Model_Y & "x" & Model_X & "x" & Model_Z

ElseIf Model_Y > Model_Z And Model_Z > Model_X Then
iProperties.Value("Custom", "DIM")= Model_Y & "x" & Model_Z & "x" & Model_X

ElseIf Model_Z > Model_X And Model_X >= Model_Y Then
iProperties.Value("Custom", "DIM")= Model_Z & "x" & Model_X & "x" & Model_Y

ElseIf Model_Z > Model_Y And Model_Y > Model_X Then
iProperties.Value("Custom", "DIM")= Model_Z & "x" & Model_Y & "x" & Model_X

End If
0 Likes
Message 8 of 22

Martin-Winkler-Consulting
Advisor
Advisor

I think it would be more usefull coding all in a VBA makro.

Try to adapt and integrate your iLogic code into the VBA Sample like this:

 Sub Extend_XYZ_Traverse(Occurrences As ComponentOccurrences, _
                             Level As Integer)
    ' Iterate through all of the occurrence in this collection.  This
    ' represents the occurrences at the top level of an assembly.
    Dim oOcc As ComponentOccurrence
    Dim oCustomPropSet As PropertySet
    Dim Model_X As Double
    Dim Model_Y As Double
    Dim Model_Z As Double
    
    For Each oOcc In Occurrences
     'If it is an Assembly go to next Level
     If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
      Call Extend_XYZ_Traverse(oOcc.SubOccurrences, Level + 1)
     ElseIf oOcc.DefinitionDocumentType = kPartDocumentObject Then
         'Get the ranges
         Model_X = (oOcc.RangeBox.MaxPoint.x + (oOcc.RangeBox.MinPoint.x) * -1) * 10
         Model_Y = (oOcc.RangeBox.MaxPoint.Y + (oOcc.RangeBox.MinPoint.Y) * -1) * 10
         Model_Z = (oOcc.RangeBox.MaxPoint.Z + (oOcc.RangeBox.MinPoint.Z) * -1) * 10
         
         'Get the UserDefinedPropertySet
         Set oCustomPropSet = oOcc.Definition.Document.PropertySets.item(4)
		 		  
         If CheckPropertyExists(oCustomPropSet, "ModelX") Then
          oCustomPropSet.item("ModelX") = Model_X
         Else
          Call oCustomPropSet.Add(Model_X, "ModelX")
         End If
         
         If CheckPropertyExists(oCustomPropSet, "ModelY") Then
          oCustomPropSet.item("ModelY") = Model_Y
         Else
          Call oCustomPropSet.Add(Model_Y, "ModelY")
         End If
         
         If CheckPropertyExists(oCustomPropSet, "ModelZ") Then
          oCustomPropSet.item("ModelZ") = Model_Z
         Else
          Call oCustomPropSet.Add(Model_Z, "ModelZ")
         End If
		 
		 'here you can insert your if statement
		 'check wether User iProperty DIM exists as shown above
		 'use oCustomPropSet.item("DIM") instead of iLogic code iProperties.Value("Custom", "DIM")
	






      End If
     Next
End Sub

If you would like to use external rules calling them from an iLogic Rule in the part there is a possibility to call them with

iLogicVB.RunExternalRule("ruleFilename")

Martin Winkler
CAD Developer
Did you find this post helpful? Feel free to like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


EESignature

Message 9 of 22

vkulikajevas
Advocate
Advocate

Thank you @Martin-Winkler-Consulting for your help. The code seems to work one time, and after there are custom parameters created it just receives the same error. 

Can I run that 

 

iLogicVB.RunExternalRule("ruleFilename")

In iterations with VBA for every Assembly part?

 

 

 

 

0 Likes
Message 10 of 22

Martin-Winkler-Consulting
Advisor
Advisor

This is an iLogic command and you can use it in an iLogicRule, not in VBA.

May be an iteration like in the VBA Sample is in iLogic also possible but i prefer VBA.

 

I had a look on the VBA Code again and get the error when running second time.

Please try this:

 

Sub Extend_XYZ_Traverse(Occurrences As ComponentOccurrences, _
                             Level As Integer)
    ' Iterate through all of the occurrence in this collection.  This
    ' represents the occurrences at the top level of an assembly.
    Dim oOcc As ComponentOccurrence
    Dim oCustomPropSet As PropertySet
    Dim Model_X As Double
    Dim Model_Y As Double
    Dim Model_Z As Double
    
    For Each oOcc In Occurrences
     'If it is an Assembly go to next Level
     If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
      Call TraverseAssembly(oOcc.SubOccurrences, Level + 1)
     ElseIf oOcc.DefinitionDocumentType = kPartDocumentObject Then
         'Get the ranges
         Model_X = (oOcc.RangeBox.MaxPoint.x + (oOcc.RangeBox.MinPoint.x) * -1) * 10
         Model_Y = (oOcc.RangeBox.MaxPoint.Y + (oOcc.RangeBox.MinPoint.Y) * -1) * 10
         Model_Z = (oOcc.RangeBox.MaxPoint.Z + (oOcc.RangeBox.MinPoint.Z) * -1) * 10
         
         'Get the UserDefinedPropertySet
         Set oCustomPropSet = oOcc.Definition.Document.PropertySets.item(4)
         
         If CheckPropertyExists(oCustomPropSet, "ModelX") Then
          oCustomPropSet.item("ModelX").Expression = Model_X
         Else
          Call oCustomPropSet.Add(Model_X, "ModelX")
         End If
         
         If CheckPropertyExists(oCustomPropSet, "ModelY") Then
          oCustomPropSet.item("ModelY").Expression = Model_Y
         Else
          Call oCustomPropSet.Add(Model_Y, "ModelY")
         End If
         
         If CheckPropertyExists(oCustomPropSet, "ModelZ") Then
          oCustomPropSet.item("ModelZ").Expression = Model_Z
         Else
          Call oCustomPropSet.Add(Model_Z, "ModelZ")
         End If
      End If
     Next
End Sub

Martin Winkler
CAD Developer
Did you find this post helpful? Feel free to like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


EESignature

0 Likes
Message 11 of 22

vkulikajevas
Advocate
Advocate

Still, doesn't work 😞

 

Untitled.jpg

0 Likes
Message 12 of 22

MechMachineMan
Advisor
Advisor

@vkulikajevas That's because if you call a function that has arguments, you need to provide those arguments. Arguments are those things in the brackets that you are given a type for. Your argument needs to also match that type.

 

In your case, above the Sub ExtendXYZ, you should have:

 

Sub Main()
    Dim oDoc As Document
    oDoc = THisApplicaiton.ActiveDocument
    
    Call Extend_XYZ_Traverse(oDoc.ComponentDefinition.Occurrences, 0)
End SUb
Sub Extend_XYZ_Traverse(Occurrences As ComponentOccurrences, _ Level As Integer) ' Iterate through all of the occurrence in this collection. This ' represents the occurrences at the top level of an assembly. Dim oOcc As ComponentOccurrence Dim oCustomPropSet As PropertySet Dim Model_X As Double Dim Model_Y As Double Dim Model_Z As Double For Each oOcc In Occurrences 'If it is an Assembly go to next Level If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then Call TraverseAssembly(oOcc.SubOccurrences, Level + 1) ElseIf oOcc.DefinitionDocumentType = kPartDocumentObject Then 'Get the ranges Model_X = (oOcc.RangeBox.MaxPoint.x + (oOcc.RangeBox.MinPoint.x) * -1) * 10 Model_Y = (oOcc.RangeBox.MaxPoint.Y + (oOcc.RangeBox.MinPoint.Y) * -1) * 10 Model_Z = (oOcc.RangeBox.MaxPoint.Z + (oOcc.RangeBox.MinPoint.Z) * -1) * 10 'Get the UserDefinedPropertySet oCustomPropSet = oOcc.Definition.Document.PropertySets.item(4) If CheckPropertyExists(oCustomPropSet, "ModelX") Then oCustomPropSet.item("ModelX").Expression = Model_X Else Call oCustomPropSet.Add(Model_X, "ModelX") End If If CheckPropertyExists(oCustomPropSet, "ModelY") Then oCustomPropSet.item("ModelY").Expression = Model_Y Else Call oCustomPropSet.Add(Model_Y, "ModelY") End If If CheckPropertyExists(oCustomPropSet, "ModelZ") Then oCustomPropSet.item("ModelZ").Expression = Model_Z Else Call oCustomPropSet.Add(Model_Z, "ModelZ") End If End If Next End Sub
Public Function CheckPropertyExists(oProps As PropertySet, oPropName As String) As Boolean CheckPropertyExists = False Dim oProp As Property For Each oProp In oProps If oProp.Name = oPropName Then CheckPropertyExists = True End If Next End Function

 


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 13 of 22

Martin-Winkler-Consulting
Advisor
Advisor

@vkulikajevas

You can not copy VBA Code 1:1 to iLogic

Also read some Tutorials with basic skills in writing iLogic and VBA.

 

You can find good stuff at http://modthemachine.typepad.com/my_weblog/

or in german language https://inventorfaq.blogspot.de/

and many other sites.

 

Hope this will help you.

 

 

Martin Winkler
CAD Developer
Did you find this post helpful? Feel free to like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


EESignature

Message 14 of 22

Martin-Winkler-Consulting
Advisor
Advisor
Accepted solution

one mistake (from me) in the code again....the copy paste devil......

 

it has to be:

Sub Main()
    Dim oDoc As Document
    oDoc = THisApplicaiton.ActiveDocument
    
    Call Extend_XYZ_Traverse(oDoc.ComponentDefinition.Occurrences, 0)
End SUb

Sub Extend_XYZ_Traverse(Occurrences As ComponentOccurrences, _
                             Level As Integer)
    ' Iterate through all of the occurrence in this collection.  This
    ' represents the occurrences at the top level of an assembly.
    Dim oOcc As ComponentOccurrence
    Dim oCustomPropSet As PropertySet
    Dim Model_X As Double
    Dim Model_Y As Double
    Dim Model_Z As Double
    
    For Each oOcc In Occurrences
     'If it is an Assembly go to next Level
     If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
      Call Extend_XYZ_Traverse(oOcc.SubOccurrences, Level + 1)
     ElseIf oOcc.DefinitionDocumentType = kPartDocumentObject Then
         'Get the ranges
         Model_X = (oOcc.RangeBox.MaxPoint.x + (oOcc.RangeBox.MinPoint.x) * -1) * 10
         Model_Y = (oOcc.RangeBox.MaxPoint.Y + (oOcc.RangeBox.MinPoint.Y) * -1) * 10
         Model_Z = (oOcc.RangeBox.MaxPoint.Z + (oOcc.RangeBox.MinPoint.Z) * -1) * 10
         
         'Get the UserDefinedPropertySet
         oCustomPropSet = oOcc.Definition.Document.PropertySets.item(4)
         
         If CheckPropertyExists(oCustomPropSet, "ModelX") Then
          oCustomPropSet.item("ModelX").Expression = Model_X
         Else
          Call oCustomPropSet.Add(Model_X, "ModelX")
         End If
         
         If CheckPropertyExists(oCustomPropSet, "ModelY") Then
          oCustomPropSet.item("ModelY").Expression = Model_Y
         Else
          Call oCustomPropSet.Add(Model_Y, "ModelY")
         End If
         
         If CheckPropertyExists(oCustomPropSet, "ModelZ") Then
          oCustomPropSet.item("ModelZ").Expression = Model_Z
         Else
          Call oCustomPropSet.Add(Model_Z, "ModelZ")
         End If
      End If
     Next
End Sub

Public Function CheckPropertyExists(oProps As PropertySet, oPropName As String) As Boolean
 CheckPropertyExists = False
 Dim oProp As Property
 For Each oProp In oProps
    If oProp.Name = oPropName Then
        CheckPropertyExists = True
    End If
 Next
End Function

Martin Winkler
CAD Developer
Did you find this post helpful? Feel free to like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


EESignature

0 Likes
Message 15 of 22

vkulikajevas
Advocate
Advocate
Accepted solution

@Martin-Winkler-Consulting and @MechMachineMan thank you for your support! 🙂 I have managed to complete the code with your help.

 

Maybe someone will have use for it too.

This code creates X, Y, Z measurements of the bounding box of a part (Part must be perpendiculart to X, Y, Z axises) and can create dimensions DIMALL which has the longest, shorter, and shortest dimensions consequently.

Sub Bounding_Box_Main()
    Dim oAsmDoc As AssemblyDocument
    Set oAsmDoc = ThisApplication.ActiveDocument
    Call Bounding_Box(oAsmDoc.ComponentDefinition.Occurrences, 1)
    
  End Sub

  Sub Bounding_Box(Occurrences As ComponentOccurrences, _
                             Level As Integer)
    ' Iterate through all of the occurrence in this collection.  This
    ' represents the occurrences at the top level of an assembly.
    Dim oOcc As ComponentOccurrence
    Dim oCustomPropSet As PropertySet
    Dim modX As Double
    Dim modY As Double
    Dim modZ As Double
    
    For Each oOcc In Occurrences
     'If it is an Assembly go to next Level
    Set oCustomPropSet = oOcc.Definition.Document.PropertySets.Item(4)
     If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
      Call Bounding_Box(oOcc.SubOccurrences, Level + 1)
     ElseIf oOcc.DefinitionDocumentType = kPartDocumentObject Then
         'Get the ranges Model X, Model Y, Model Z
         modX = (oOcc.RangeBox.MaxPoint.X + (oOcc.RangeBox.MinPoint.X) * -1) * 10
         modY = (oOcc.RangeBox.MaxPoint.Y + (oOcc.RangeBox.MinPoint.Y) * -1) * 10
         modZ = (oOcc.RangeBox.MaxPoint.Z + (oOcc.RangeBox.MinPoint.Z) * -1) * 10
         
         'Round to 0
         modXr = Round(modX, 0)
         modYr = Round(modY, 0)
         modZr = Round(modZ, 0)
         
         

'Get the UserDefinedPropertySet
         Set oCustomPropSet = oOcc.Definition.Document.PropertySets.Item(4)
         
         ' For X
         If CheckPropertyExists(oCustomPropSet, "ModX") Then
          oCustomPropSet.Item("ModX").Expression = modXr
         Else
          Call oCustomPropSet.Add(modXr, "ModX")
         End If
         
         ' For Y
         If CheckPropertyExists(oCustomPropSet, "ModY") Then
          oCustomPropSet.Item("ModY").Expression = modYr
         Else
          Call oCustomPropSet.Add(modYr, "ModY")
         End If
         
        ' For Z
          If CheckPropertyExists(oCustomPropSet, "ModZ") Then
          oCustomPropSet.Item("ModZ").Expression = modZr
         Else
          Call oCustomPropSet.Add(modZr, "ModZ")
         End If

'Create DIMALLLL L x W x H

If modXr >= modYr And modYr >= modZr Then
DIMALL = modX & "x" & modY & "x" & modZ

ElseIf modXr >= modZr And modZr >= modYr Then
DIMALL = modXr & "x" & modZr & "x" & modYr

ElseIf modYr >= modZr And modZr >= modXr Then
DIMALL = modYr & "x" & modZr & "x" & modXr

ElseIf modYr > modXr And modXr > modZr Then
DIMALL = modYr & "x" & modXr & "x" & modZr

ElseIf modZr > modXr And modXr > modYr Then
DIMALL = modZr & "x" & modXr & "x" & modYr

ElseIf modZr > modYr And modYr > modXr Then
DIMALL = modZr & "x" & modYr & "x" & modXr

End If


If CheckPropertyExists(oCustomPropSet, "DIMALL") Then
          oCustomPropSet.Item("DIMALL").Expression = DIMALL
         Else
          Call oCustomPropSet.Add(DIMALL, "DIMALL")
         End If

         

    End If
     Next
End Sub


Public Function CheckPropertyExists(oProps As PropertySet, oPropName As String) As Boolean
 CheckPropertyExists = False
 Dim oProp As Property
 For Each oProp In oProps
    If oProp.Name = oPropName Then
        CheckPropertyExists = True
    End If
 Next
End Function

0 Likes
Message 16 of 22

Anonymous
Not applicable

I tried to apply your rule and it works perfectly fine for all sub assemblies. Thank you very much for this. But can this also apply to ipt files under the sub assemblies? We actually have some properties that we added to our illogic form and want it to run in all ipt files also so it can take the basic brand name, etc. is it possible to run this rule so those properties also apply to the ipt files besides just the sub assemblies? thanks in advance

 

 


 


 

0 Likes
Message 17 of 22

Martin-Winkler-Consulting
Advisor
Advisor

Hi @Anonymous

Normally the iProperties are also changed in the ipts. The distinction between iam and ipt takes place at this point in the code:

If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
      Call Extend_XYZ_Traverse(oOcc.SubOccurrences, Level + 1)
     ElseIf oOcc.DefinitionDocumentType = kPartDocumentObject Then
.......

Do you have an example and can you give a more detailed description of your problem?

Martin Winkler
CAD Developer
Did you find this post helpful? Feel free to like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


EESignature

0 Likes
Message 18 of 22

danielvdeleito
Contributor
Contributor

Hello Martin.

 

I'm pretty sure you can help me. I have a very simple question which is basically the main question on this post. How can I run an external rule in each sub assembly and/or parts from the main Assembly? I already have my rule working perfect, but normally I need to open each of one of the assemblies and run it. What I need is a rule to run that rule in every sub component 

 

Thanks

0 Likes
Message 19 of 22

Martin-Winkler-Consulting
Advisor
Advisor

@danielvdeleito

here as a Quick response some code in VBA. You can adapt it to iLogic.

One way of calling all Occurrences of an assembly is using a recursive call.

Here is a sample

Public Sub TraverseAssemblySample()
    ' Get the active assembly.
    Dim oAsmDoc As AssemblyDocument
    Set oAsmDoc = ThisApplication.ActiveDocument
    Debug.Print oAsmDoc.DisplayName

    ' Call the function that does the recursion.
    Call TraverseAssembly(oAsmDoc.ComponentDefinition.Occurrences, 1)
End Sub

Private Sub TraverseAssembly(Occurrences As ComponentOccurrences, _
                             Level As Integer)
    ' Iterate through all of the occurrence in this collection.  This
    ' represents the occurrences at the top level of an assembly.
    Dim oOcc As ComponentOccurrence
    For Each oOcc In Occurrences
        ' Print the name of the current occurrence.
        Debug.Print Space(Level * 3) & oOcc.Name
  
        ' Check to see if this occurrence represents a subassembly
        ' and recursively call this function to traverse through it.
        If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
            Call TraverseAssembly(oOcc.SubOccurrences, Level + 1)
        End If
    Next
End Sub

Another sample could be found at the API Help. Search for "Traverse an Assembly "

Martin Winkler
CAD Developer
Did you find this post helpful? Feel free to like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


EESignature

0 Likes
Message 20 of 22

danielvdeleito
Contributor
Contributor

Martin, many thanks

0 Likes