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: 

Run ilogic rule to all part in the assembly

31 REPLIES 31
Reply
Message 1 of 32
zaidi_drafter
3358 Views, 31 Replies

Run ilogic rule to all part in the assembly

Hi,

 

I have one question how to run ilogic rule to all part in assembly? Mean when your run the rule in assembly environment the rule will automatically go to each part in the assembly. not need to open one by one for run the rule.

Any update very appreciated.

 

Regards

Zaidi

31 REPLIES 31
Message 2 of 32
Cadmanto
in reply to: zaidi_drafter

Zaidi,

I am not much good at writing iLogic, but as far as implementing the rules, if you copy the rule from your part into the "Edit Rule" dialog

rule.JPG

Then just have the iLogic browser open in your regular browser

rule.JPG

It will always be there to run in your assembly.  I would setup this arrangement in your part as well as your assembly templates so every new part or assembly model you create will have this there for oyu.

 

check.PNGIf this solved your issue please mark this posting "Accept as Solution".

Or if you like something that was said and it was helpful, Kudoskudos.PNG are appreciated. Thanks!!!! Smiley Very Happy

 

New EE Logo.PNG

Inventor.PNG     vault.PNG

 

Best Regards,
Scott McFadden
(Colossians 3:23-25)


Message 3 of 32
ChristinaForest
in reply to: Cadmanto

hi 🙂

 

Ithink your looking for that

oCompDef = ThisDoc.Document.ComponentDefinition
oAssyOccurrences  = oCompDef.Occurrences
Dim oOccurrence As ComponentOccurrence
Dim oSubOccurrence1 As ComponentOccurrence
For Each oOccurrence In oAssyOccurrences
If oOccurrence.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
iLogicVb.RunRule(oOccurrence.Name,"YOURRULENAME")
For Each oSubOccurrence1 In oOccurrence.SubOccurrences
If oSubOccurrence1.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
iLogicVb.RunRule(oSubOccurrence1.Name,"YOURRULENAME")
Next
End If
Next
End If
iLogicVb.UpdateWhenDone = True

 

Message 4 of 32

First code seems to work but it cannot find the rule I'm calling for ("YOURRULENAME"):

 

RunRule("Part1:1", "Test.iLogicVb"): Cannot find a rule with the name: "Test.iLogicVb".

Message 5 of 32

Because in the code you are trying to use there are 2 occurrence of the line in which you need to change the rule name, and APPARENTLY you only changed one.


--------------------------------------
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
Message 6 of 32

Yes thank you for realizing my silly mistake.

 

I am trying to do something amazingly simple. I'm just trying to flip the "Part Number" and the "Description" in the iProperties project tab for both the asssembly properties and each part properties.

 

Here is the code I have borrowed:

 

oCompDef = ThisDoc.Document.ComponentDefinition
oAssyOccurrences  = oCompDef.Occurrences

Dim oOccurrence As ComponentOccurrence
Dim oSubOccurrence1 As ComponentOccurrence
For Each oOccurrence In oAssyOccurrences
If oOccurrence.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
iLogicVb.RunRule(oOccurrence.Name,"Test")

For Each oSubOccurrence1 In oOccurrence.SubOccurrences
If oSubOccurrence1.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
iLogicVb.RunRule(oSubOccurrence1.Name,"Test")

End If
Next
End If
Next

And here is the "Test" that I'm calling.

 

TempString = iProperties.Value("Project", "Part Number")
iProperties.Value("Project", "Description") = TempString
iProperties.Value("Project", "Part Number") = ""

It runs but doesn't do a thing.

 

Message 7 of 32

For 1; proper nesting makes things easier to read and understand.

 

For 2; your code only goes 2 levels deep in the assembly, and it becomes evident you are not a programmer.

- To dig through all levels of assembly, you almost certainly need recursion. See the attached link that will provide you some better guidance on the topic.

 

http://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html

 

Proper nesting shown below:

 

oCompDef = ThisDoc.Document.ComponentDefinition
oAssyOccurrences  = oCompDef.Occurrences

Dim oOccurrence As ComponentOccurrence
Dim oSubOccurrence1 As ComponentOccurrence
For Each oOccurrence In oAssyOccurrences If oOccurrence.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
iLogicVb.RunRule(oOccurrence.Name,"Test") For Each oSubOccurrence1 In oOccurrence.SubOccurrences If oSubOccurrence1.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then iLogicVb.RunRule(oSubOccurrence1.Name,"Test") End If Next End If Next

 


--------------------------------------
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
Message 8 of 32

I agree with both of your statements.

 

But considering my inexperience, I'm trying to keep this simple for now - An assembly file with just one part in it. no recursion. Inefficient code for the sake of simplicity.

 

Having said that, can you comment on why this code is not doing what I want it to do? which is make the iProperties descriptions equal the part number and then delete the part numbers in both the assembly instance and the part instance.

 

 

Message 9 of 32
tdant
in reply to: zaidi_drafter

Your rule starts by looking at the part, not the parent assembly file. Since the part type is not a kAssemblyDocumentObject, the IF is ignored and your rule has no effect at all. Try this.

 

oCompDef = ThisDoc.Document.ComponentDefinition
oAssyOccurrences  = ThisDocument.ComponentDefinition.Occurrences

iLogicVb.RunRule("Test")

Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAssyOccurrences If oSubOccurrence1.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then iLogicVb.RunRule(oSubOccurrence1.Name,"Test") End If Next

 

Message 10 of 32

http://modthemachine.typepad.com/my_weblog/2010/02/accessing-iproperties.html

 

 

Sub Main() 

    Dim oAsmDoc As AssemblyDocument 
    oAsmDoc = ThisDoc.Document
Dim oRefDoc As Document For Each oRefDoc In oAsmDoc.AllReferencedDocuments

oDTP = oRefDoc.PropertySet("Design Tracking Properties")

TempString =oDTP("Part Number").Value
oDTP("Part Number").Value = oDTP("Description").Value
oDTP("Description").Value = oTempString
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
Message 11 of 32

Doesn't compile.. see pic

Error.png

Message 12 of 32
shakeNbake444
in reply to: tdant

This doesn't run..

 

Error2.png

Message 13 of 32
tdant
in reply to: shakeNbake444

Sorry, I typoed. Try this one instead:

 

oCompDef = ThisDoc.Document.ComponentDefinition
oAssyOccurrences  = ThisDoc.Document.ComponentDefinition.Occurrences

iLogicVb.RunRule("Test")

Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAssyOccurrences If oSubOccurrence1.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then iLogicVb.RunRule(oSubOccurrence1.Name,"Test") End If Next
Message 14 of 32

So debug it...

--------------------------------------
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
Message 15 of 32
shakeNbake444
in reply to: tdant

Not really sure what directory it's looking at but it can't find it

 



RunRule: Cannot find a rule with the name: "Test.iLogicVB".

Message 16 of 32
tdant
in reply to: shakeNbake444

I can run "Rule0" by calling iLogicVb.RunRule("Rule0") from Rule1 (see below). If your "Test" rule is called "Test" and is in the parent file, it should work, but it's hard to tell without being able to look at the file. Any chance you can upload a copy?

Capture.PNG

Message 17 of 32
shakeNbake444
in reply to: tdant

well we are getting somewhere...

 

So my first issue is that I was trying all these from external rules. Which is what I want in the end rather than having to browse for this rule every time i make a part. I am also not allowed to change our part templates here.. forbidden.

 

My other issue is that I get a new cryptic error that I don't know where to begin with..

 

Error:

Error in rule: Rule1, in document: test.iam

Object reference not set to an instance of an object.

 

More Info:

System.NullReferenceException: Object reference not set to an instance of an object.
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

 

Message 18 of 32
tdant
in reply to: shakeNbake444

I'll do what I can, but all this is much, much easier if you provide a copy of your assembly file.

 

Open your assembly fresh, delete the previous troublesome rules, and go to your iLogic browser. click the far-right tab "External Rules", and right-click "Manually Added", then select "Create New External Rule". Navigate to the directory where you want the external rule saved. Name the first rule "DescriptionEditor". Paste in the following:

 

 

SyntaxEditor Code Snippet

TempString = iProperties.Value("Project", "Part Number")
iProperties.Value("Project", "Description") = TempString
iProperties.Value("Project", "Part Number") = ""

Now create another external rule, save it in the same directory, and call it "ChangeDescription". Paste in the following:

 

SyntaxEditor Code Snippet

oCompDef = ThisDoc.Document.ComponentDefinition
oAssyOccurrences  = ThisDoc.Document.ComponentDefinition.Occurrences

iLogicVb.RunRule("Test")

Dim oOccurrence As ComponentOccurrence

For Each oOccurrence In oAssyOccurrences
    If oSubOccurrence1.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
          iLogicVb.RunExternalRule("ChangeDescription")
    End If
Next

 Now go to your "Manage" tab at the top, and look in the iLogic section of the ribbon. Click "Event Triggers". Make sure the top-left box (Run these rules when events occur) is checked. Highlight "Before Save Document" and click the "Select Rules..." button at the bottom. Check the box beside the line that ends in "ChangeDescription" and click OK.

 

Now that all of that is done, when you save your file, the iProperty "Description" should be the previous part number, and "Part Number" should be blank.

Message 19 of 32

Staying consistent with your programming environment definitely helps.

 

Try running what I posted from a RULE, not Vba macros. It's coded in vb.net, which is evident from the lack of SET statements when assigning objects to variables.

 


@shakeNbake444 wrote:

Doesn't compile.. see pic

Error.png


 


--------------------------------------
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
Message 20 of 32
shakeNbake444
in reply to: tdant

I really appreciate helping out. However, it's still not working. I attached the assembly and files.

 

Doing it exactly how you shown I get:

Error on Line 11 : 'oSubOccurrence1' is not declared. It may be inaccessible due to its protection level.

 

So if i try to declare it with the following code:

oCompDef = ThisDoc.Document.ComponentDefinition
oAssyOccurrences  = ThisDoc.Document.ComponentDefinition.Occurrences

iLogicVb.RunRule("DescriptionEditor")

Dim oSubOccurrence1 As ComponentOccurrence
Dim oOccurrence As ComponentOccurrence

For Each oOccurrence In oAssyOccurrences
    If oSubOccurrence1.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
          iLogicVb.RunExternalRule("DescriptionEditor")
    End If
Next

i still get:

RunRule: Cannot find a rule with the name: "DescriptionEditor".

 

Did everything you said:

image.png

 

image.png

 

 

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

Post to forums  

Autodesk Design & Make Report