run all rules in subassemblies and parts from top level

run all rules in subassemblies and parts from top level

JimmyDoe
Collaborator Collaborator
3,230 Views
6 Replies
Message 1 of 7

run all rules in subassemblies and parts from top level

JimmyDoe
Collaborator
Collaborator

Hello all,

 

I know there are many questions and answers about this topic, but I can't find anything that helps me, so I throw myself at your mercy..please help.

 

I am creating a modular bridge, that consists of two sections that bolt together. I have a skeleton that contains many rules to control the length, width, beam size, channel spacing and many many other options. I also have many more rules in sub-assemblies and parts. Often times I will have to open up some of the sub-assemblies and run their rules manually to get everything to update. Sometimes I don't have to open the sub-assemblies to get things to update. So, it seems sometimes the rules in sub-assemblies fire and sometimes they don't?? We will be using this to show customers and I need more consistency to have confidence that it will completely update every time.

 

Everything works fine and updates as it should(once I get all the rules to run), I just don't want to have to go through the sub-assemblies to fire rules that sometimes don't seem to fire. I am looking for a way to get every rule to run, from the very top level. I've seen all sorts of posts showing long code to make this happen, but I don't quite understand them. Is there a simpler code to tell Inventor to look down through every part and sub-assembly and fire every rule that it finds?

 

I've learned quite a bit about iLogic doing this project, but with all there is to iLogic, I am still a novice.

 

Thanks in advance 🙂

 

And I have to click rebuild all two or three times to get things to update. Can someone explain why this is?

0 Likes
Accepted solutions (1)
3,231 Views
6 Replies
Replies (6)
Message 2 of 7

MechMachineMan
Advisor
Advisor
Accepted solution

Something like this is what you need. Haven't tried debugging. Nor would I use it, because there are almost certainly better approaches.... but here you go:

 

Sub Main()
      On Error Resume Next
      Dim oDoc As Document = ThisApplication.ActiveDocument

      oAuto = iLogicVb.Automation

      Call RunAllRules(oDoc)

      For Each oSubDoc in oDoc.AllReferencedDocuments
            Call RunAllRules(oSubDoc)
      Next

End Sub

Dim oAuto As Object

Sub RunAllRules(oRDoc)

      For Each oRule In oAuto.Rules(oRDoc)
            oAuto.RunRule(oRDoc, oRule.Name)
      Next

End Sub

--------------------------------------
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 3 of 7

JimmyDoe
Collaborator
Collaborator

 

It seems to be firing all the rules in lower levels. This is what I need. Thank you.

 

Just curious as to why you wouldn't use this rule?

0 Likes
Message 4 of 7

MechMachineMan
Advisor
Advisor

Because you don't necessarily know what exactly each rule contains, or how it's coded. 

 

Unless they all use ThisDoc.Document in them/if any use ThisApplication.ActiveDocument, it is possible that they could change files you don't intend.

 

Instead, I would write an external rule that iterates through the documents performing what I need to make sure that I know exactly what the rule is doing, by looking at one location.


--------------------------------------
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 5 of 7

JimmyDoe
Collaborator
Collaborator

In my case, I know what each rule does and what they contain. I have created my model from scratch and have been very diligently trouble shooting it all the way through. When I change the parameters to control it in my top level, I need all the rules to fire in all documents.

Your way probably would work well, but my iLogic code is fairly basic, but there is a lot of it.

 

Thank you for your help Smiley Happy

0 Likes
Message 6 of 7

MechMachineMan
Advisor
Advisor

Alas, if you realize you typed something wrong in a rule, or want to update what the rule does, that is a hella ton of files to go back and edit rules in. I pity the poor fellow who would get assigned this task!


--------------------------------------
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 7 of 7

JimmyDoe
Collaborator
Collaborator

This model is a modular bridge that had to be double stamped by two separate P. Engs, for government approval. This is a revised model and the reason it was revised is because the government had a whole review of these types of bridges because there was another company that designed them who's engineer was investigated due to a building he worked on had collapsed and caused a death, due to improper/shady practices. And his companies bridges were approved for a higher load than they were designed for. So there was a big review, but everything is finalized and this design will probably not change before IV is long obsolete.

 

The controls are, length, width, type of ends and type of guard rail. When one of these values changes, all rules must be fired because it affects many parts of the model. So, your code will work for me and I thank you for it.

 

Also, when a rule fails it tells you what rule failed, what assembly it is in and what the problem is...maybe I don't understand iLogic well enough to see the danger?

0 Likes