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.
Solved by jdkriek. Go to Solution.
Solved by jdkriek. Go to Solution.
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.
Hello Jonathan,
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?
Hi
I just made some changes in there as i needed and its working but one more thing i waana do is delete all parameters
either user parameters or model
Auto = iLogicVb.Automation
Dim iLogicAuto As Object
iLogicAuto = Auto
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
'Master file name
If Not (ThisDoc.FileName) = "iLogic" 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
Else
i = MessageBox.Show("No Rules are in File")
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
i = MessageBox.Show("Click Yes to delete all Fetures or No to Suppressed or Cancel to abort", "My iLogic Dialog", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
' If Not Feature.IsActive(featureName) Then
If i=vbYes Then
i = MessageBox.Show("Deleting All Features ")
oFeature.Delete
Else If i=vbNo Then
' i = MessageBox.Show("Deleting Supressed Features ")
If Not Feature.IsActive(featureName) Then
oFeature.Delete
End If
Else
i = MessageBox.Show("Action canceled ")
End If
Next
End If
'but now something i wanna do is
'Remove all Parameters too
If Not (param Is Nothing) Then
For Each param In params
i = MessageBox.Show("Checking for Parameter in File")
i = MessageBox.Show("No.of Parameters exists are ="& param.count)
paramname=param.Name
On Error Resume Next
param.delete(oDoc, paramName)
paramName =ThisDoc.Document.ComponentDefinition.Parameters
iLogicAuto.Deleteparam(oDoc, paramName)
Next
Else
i = MessageBox.Show("No Parameter are in File")
'Please help me in the I will be greatful
'Thanks and regards
"vicky
hi dear sir/Buddy.................
A solution u did give earlier to some helped me alot what i wanna achive , Imade some chages according my need
and its working but i wanna little more help from u please......
Auto = iLogicVb.Automation
Dim iLogicAuto As Object
iLogicAuto = Auto
Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
'Master file name
If Not (ThisDoc.FileName) = "iLogic" 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
Else
i = MessageBox.Show("No Rules are in File")
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
i = MessageBox.Show("Click Yes to delete all Fetures or No to Suppressed or Cancel to abort", "My iLogic Dialog", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1)
' If Not Feature.IsActive(featureName) Then
If i=vbYes Then
i = MessageBox.Show("Deleting All Features ")
oFeature.Delete
Else If i=vbNo Then
' i = MessageBox.Show("Deleting Supressed Features ")
If Not Feature.IsActive(featureName) Then
oFeature.Delete
End If
Else
i = MessageBox.Show("Action canceled ")
End If
Next
End If
'but now something more i wanna do is...... delete parameters
If Not (param Is Nothing) Then
For Each param In params
i = MessageBox.Show("Checking for Parameter in File")
i = MessageBox.Show("No.of Parameters exists are ="& param.count)
paramname=param.Name
On Error Resume Next
param.delete(oDoc, paramName)
paramName =ThisDoc.Document.ComponentDefinition.Parameters
iLogicAuto.Deleteparam(oDoc, paramName)
Next
Else
i = MessageBox.Show("No Parameter are in File")
End If
'Regards
'vicky
Removing all Parameters is what I wanna too.
Thanks lot for your contribution, Vicky.
I tested your code, but I do not know what is happened, code cannot get into "For .... Next" Loop.
That means: "If Not (param Is Nothing) Then" gives me "False" although I have lot of parameters in my model. I could use "Delete All Rules and iLogic Parameters" to delete them. But the codes which you provided does not work.
Maybe it is because I am using Inventor 2009 if it is working in your side.
Any does anybody know how to delete suppressed components in *.iam by iLogic code?
Thank, anyhow.
Hi Jonathan,
This looks like exactly what I need but I can't get it to work. I keep getting this error:
Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.PartFeatures'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{DA33F1A5-7C3F-11D3-B794-0060B0F159EF}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
whenever I run this rule. Do you have any ideas on what might be causing the problem?
Ben
I do not know whether my issue is same with you but I do have similar error after I ran some rules in one model and open other model which includes rules.
What I do is before opening the new model, I close Inventor and re-start a new session. When I do this, I do not have the error.
It looks like some bugs in Inventor memory assignment.
Hi,
if somebody wants to delete only all rules in one document, there is more effective way.
You don´t have to use for cycle. In iLogic, there is a command that deletes all rules in document. It is better because it deletes also rule from which it was triggered (no rule will be in the document after this command will be done).
The command is:
ïLogicVb.Automation.DeleteAllRulesInDocument(oDoc)
with defined Doc
or
ïLogicVb.Automation.DeleteAllRulesInDocument(ThisApplication.ActiveDocument)
Can't find what you're looking for? Ask the community or share your knowledge.