Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use iLogic Rule to delete rules and features in other parts?

17 REPLIES 17
SOLVED
Reply
Message 1 of 18
zdhrichard
9857 Views, 17 Replies

How to use iLogic Rule to delete rules and features in other parts?

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).

Rich

Autodesk Inventor Professional 2018 (64 Bit Edition)
Build: 284, Release 2018.3
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
17 REPLIES 17
Message 2 of 18
zdhrichard
in reply to: zdhrichard

No any reply yet?

 

If somebody could help, it will be much appreciated.

Rich

Autodesk Inventor Professional 2018 (64 Bit Edition)
Build: 284, Release 2018.3
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
Message 3 of 18
mrattray
in reply to: zdhrichard

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.

Mike (not Matt) Rattray

Message 4 of 18
jdkriek
in reply to: zdhrichard

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

 

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 5 of 18
zdhrichard
in reply to: jdkriek

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.

Rich

Autodesk Inventor Professional 2018 (64 Bit Edition)
Build: 284, Release 2018.3
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
Message 6 of 18
jdkriek
in reply to: zdhrichard

Can you attach the part here for me to look at?

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 7 of 18
zdhrichard
in reply to: jdkriek

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?

Rich

Autodesk Inventor Professional 2018 (64 Bit Edition)
Build: 284, Release 2018.3
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
Message 8 of 18
jdkriek
in reply to: zdhrichard

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

 

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 9 of 18
zdhrichard
in reply to: jdkriek

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?

Rich

Autodesk Inventor Professional 2018 (64 Bit Edition)
Build: 284, Release 2018.3
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
Message 10 of 18
jdkriek
in reply to: zdhrichard

It seems that it should be deleting those sketches along with the feature Robot surprised

 

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?

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 11 of 18
hunkvicky.87
in reply to: jdkriek

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

Message 12 of 18
hunkvicky.87
in reply to: jdkriek

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

Message 13 of 18
zdhrichard
in reply to: hunkvicky.87

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.

Rich

Autodesk Inventor Professional 2018 (64 Bit Edition)
Build: 284, Release 2018.3
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
Message 14 of 18
kennethadelman
in reply to: jdkriek

Kriek,

 

That worked like a charm! And how would forms be deleted?

Message 15 of 18
bmerton
in reply to: jdkriek

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

Message 16 of 18
zdhrichard
in reply to: bmerton

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.

 

Rich

Autodesk Inventor Professional 2018 (64 Bit Edition)
Build: 284, Release 2018.3
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
Message 17 of 18
dpuchta
in reply to: jdkriek

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)

Message 18 of 18
zdhrichard
in reply to: dpuchta

Both codes work great! Thanks.

Rich

Autodesk Inventor Professional 2018 (64 Bit Edition)
Build: 284, Release 2018.3
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory

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

Post to forums  

Autodesk Design & Make Report