Inventor General

Reply
Distinguished Contributor
zdhrichard
Posts: 120
Registered: ‎05-03-2011
Message 1 of 13 (1,082 Views)
Accepted Solution

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

1082 Views, 12 Replies
08-10-2012 08:14 AM

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 2013 (64 Bit) SP2
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
Distinguished Contributor
zdhrichard
Posts: 120
Registered: ‎05-03-2011
Message 2 of 13 (1,051 Views)

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

08-14-2012 05:57 AM in reply to: zdhrichard

No any reply yet?

 

If somebody could help, it will be much appreciated.

Rich

Autodesk Inventor Professional 2013 (64 Bit) SP2
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
*Expert Elite*
mrattray
Posts: 2,217
Registered: ‎09-13-2011
Message 3 of 13 (1,042 Views)

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

08-14-2012 09:33 AM 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

*Expert Elite*
jdkriek
Posts: 527
Registered: ‎03-29-2007
Message 4 of 13 (1,027 Views)

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

08-15-2012 06:31 AM 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

Autodesk Inventor Certified Expert
Microsoft Certified Application Developer
_____________________________________________________
Did I help you? Please choose Accept as Solution or Kudos below

Distinguished Contributor
zdhrichard
Posts: 120
Registered: ‎05-03-2011
Message 5 of 13 (1,008 Views)

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

08-15-2012 12:22 PM 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 2013 (64 Bit) SP2
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
*Expert Elite*
jdkriek
Posts: 527
Registered: ‎03-29-2007
Message 6 of 13 (987 Views)

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

08-16-2012 08:54 AM in reply to: zdhrichard

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

Jonathan D. Kriek

Autodesk Inventor Certified Expert
Microsoft Certified Application Developer
_____________________________________________________
Did I help you? Please choose Accept as Solution or Kudos below

Distinguished Contributor
zdhrichard
Posts: 120
Registered: ‎05-03-2011
Message 7 of 13 (978 Views)

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

08-16-2012 11:24 AM 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 2013 (64 Bit) SP2
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
*Expert Elite*
jdkriek
Posts: 527
Registered: ‎03-29-2007
Message 8 of 13 (971 Views)

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

08-16-2012 01:47 PM 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

Autodesk Inventor Certified Expert
Microsoft Certified Application Developer
_____________________________________________________
Did I help you? Please choose Accept as Solution or Kudos below

Distinguished Contributor
zdhrichard
Posts: 120
Registered: ‎05-03-2011
Message 9 of 13 (960 Views)

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

08-17-2012 05:19 AM 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 2013 (64 Bit) SP2
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
*Expert Elite*
jdkriek
Posts: 527
Registered: ‎03-29-2007
Message 10 of 13 (926 Views)

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

08-20-2012 06:54 AM in reply to: zdhrichard

It seems that it should be deleting those sketches along with the feature :robotsurprised:

 

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

Autodesk Inventor Certified Expert
Microsoft Certified Application Developer
_____________________________________________________
Did I help you? Please choose Accept as Solution or Kudos below

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube