- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Then just have the iLogic browser open in your regular browser
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.
If this solved your issue please mark this posting "Accept as Solution".
Or if you like something that was said and it was helpful, Kudos are appreciated. Thanks!!!!
![]()
Scott McFadden
(Colossians 3:23-25)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
@Anonymous wrote:
Doesn't compile.. see pic
--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
Nexti still get:
RunRule: Cannot find a rule with the name: "DescriptionEditor".
Did everything you said: