I made an Part with iLogic rules, let's call it "iLogicPart".
The rules inside could create lot of different part by my input.
I want save the different parts to different name as "Part 1", "Part 2", etc. I used SaveAs to get them.
My question is: I want to delete all rules and parameters in the saved parts as "Part 1", "Part 2".
And I have lot of features (the name is hard to track) which are inactive, I want to delete them at same time too.
I could manually do so, but I want to use rule to do so automaticlly.
Could somebody help the code? Thanks lot in advance. I use Inventor 2009, XP (32 bits).
Solved! Go to Solution.
No any reply yet?
If somebody could help, it will be much appreciated.
I don't think you can delete rules using rules.
You should be able to use a for each loop to cycle through all of the components features and check the suppressed property, deleting all suppressed features.
Place the following code in an external iLogic Rule.
Define the file name of the master document in the code - in your case "iLogicPart" with no extension.
Set the event trigger for the external rule to "After Open".
When you do a Save As to "Part 1", "Part 2", ect it will trigger the external iLogic rule and delete all local iLogic within that part copy. And as long as you defined the master document file name correctly, when you open that document it won't remove any iLogic.
Let me know if you have any questions.
'J.Kriek 2012 Auto = iLogicVb.Automation Dim iLogicAuto As Object iLogicAuto = Auto Dim oDoc As Document oDoc = ThisApplication.ActiveDocument 'Master file name If Not (ThisDoc.FileName(False)) = "iLogicPart" Then Dim ruleName As String Dim rules As Object rules = iLogicAuto.rules(oDoc) If Not (rules Is Nothing) Then For Each rule In rules ruleName = rule.Name iLogicAuto.DeleteRule(oDoc, ruleName) Next End If End If
Thanks lot, Jonathan.
The code is working when I run the rule manually.
But when I open the file, it gave me:
iLogic Rule Error in rule: Delete Rules, in document: Delete Rules.iLogicVb
Object reference not set to an instance of an object.
Even I set the event trigger for the external rule to "After Open".
Still, there is a little trick.
Can you attach the part here for me to look at?
Please find atatched dumb model. I just keep one rule for your testing.
Beside I want to delete all rules, and I want to delete all suppressed feature at same time. Is it possible?
It's working fine in Inventor 2011-2013, not sure what would be diffrent in 2009.
I've added the code to delete suppressed features also.
'J.Kriek 2012 Auto = iLogicVb.Automation Dim iLogicAuto As Object iLogicAuto = Auto Dim oDoc As Document oDoc = ThisApplication.ActiveDocument 'Master file name If Not (ThisDoc.FileName) = "iLogicPart" Then Dim ruleName As String Dim rules As Object rules = iLogicAuto.rules(oDoc) 'Remove rules If Not (rules Is Nothing) Then For Each rule In rules ruleName = rule.Name iLogicAuto.DeleteRule(oDoc, ruleName) Next End If Dim oFeatures As PartFeatures oFeatures = oDoc.ComponentDefinition.Features Dim oFeature As PartFeature 'Remove suppressed features For Each oFeature In oFeatures featureName = oFeature.Name If Not Feature.IsActive(featureName) Then oFeature.Delete End If Next End If
Maybe it is Inventor 2009 cannot trigger the external rule well when openning file. I need wait two or more weeks to get Inventor 2013.
And your code for deleting feature is working when I manually run the rule. Only one thing need a little more work: when we delete the features, I want to delete their relative sketches (include their location sketches) at same time. Could we do this?
It seems that it should be deleting those sketches along with the feature
The Delete() Method looks like this:
Delete([RetainConsumedSketches As Boolean = False], [RetainDependentFeaturesAndSketches As Boolean = False], [RetainDependentWorkFeatures As Boolean = False])
So by default it's not set to retain anything and you can confirm this by setting it to Delete(False)
Can anyone chime in with more information?
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register