Inventor General Discussion

Inventor General Discussion

Reply
Distinguished Contributor
zdhrichard
Posts: 128
Registered: ‎05-03-2011
Message 1 of 20 (1,112 Views)
Accepted Solution

How to delete suppressed components by iLogic Rule

1112 Views, 19 Replies
01-24-2013 06:21 AM

I have an assembly which includes lot of parts (*.ipt) or sub-assembly (*.iam).

I have some ilogic rules to control to suppress or unsuppress them.

Now for the released assembly, I want delete all suppressed components by ilogic rule.

Could anybody help me the ilogic code to get this function?

Rich

Autodesk Inventor Professional 2014 (64 Bit Edition)
Build: 246, Release 2014 SP2 Update 2
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
Dim oComp As ComponentOccurrence
Dim oComps As ComponentOccurrences
oComps = ThisDoc.Document.ComponentDefinition.Occurrences
For Each oComp In oComps
If Component.IsActive(oComp.Name) = False Then oComp.Delete
Next

 

Try adding this to the end of your DeleteFeatures sub:

 

Dim oSketch As PlanarSketch
Dim oSketches As PlanarSketches
oSketches = oDoc.ComponentDefinition.Sketches
For Each oSketch In oSketches
If oSketch.Dependents.Count = 0 Then oSketch.Delete
Next
For Each oSketch In oSketches
If oSketch.Dependents.Count = 0 Then oSketch.Delete
Next

 

The reason the first code doesn't clean up all of the sketches is because it only deletes those sketches that are being consumed by the features that are being deleted.

Note that we have to run though all of your skecthes twice. This is because you have interdependencies between sketches and you cannot delete a sketch that has something else dependent on it. I'm playing around with a more elegant way to do this, but this way does work.

*Expert Elite*
mrattray
Posts: 2,538
Registered: ‎09-13-2011
Message 2 of 20 (1,103 Views)

Re: How to delete suppressed components by iLogic Rule

01-24-2013 07:26 AM in reply to: zdhrichard
Dim oComp As ComponentOccurrence
Dim oComps As ComponentOccurrences

oComps = ThisDoc.Document.ComponentDefinition.Occurrences

For Each oComp In oComps
	If Component.IsActive(oComp.Name) = False Then oComp.Delete
Next

 

Mike (not Matt) Rattray

Mentor
waynehelley
Posts: 151
Registered: ‎09-10-2012
Message 3 of 20 (1,099 Views)

Re: How to delete suppressed components by iLogic Rule

01-24-2013 07:44 AM in reply to: mrattray

Hi Mike, by any chance do you know how to do the same but for deleting suppressed features in the part environment?

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2013
Windows 7 Enterprise, 64-bit
*Expert Elite*
mrattray
Posts: 2,538
Registered: ‎09-13-2011
Message 4 of 20 (1,096 Views)

Re: How to delete suppressed components by iLogic Rule

01-24-2013 07:58 AM in reply to: waynehelley
Dim oFeature As PartFeature
Dim oFeatures As PartFeatures

oFeatures = ThisDoc.Document.ComponentDefinition.Features

For Each oFeature In oFeatures
	If Feature.IsActive(oFeature.Name) = False Then oFeature.Delete
Next

 

Mike (not Matt) Rattray

Distinguished Contributor
zdhrichard
Posts: 128
Registered: ‎05-03-2011
Message 5 of 20 (1,083 Views)

Re: How to delete suppressed components by iLogic Rule

01-24-2013 10:48 AM in reply to: mrattray

Thanks lot, Mike.

Rich

Autodesk Inventor Professional 2014 (64 Bit Edition)
Build: 246, Release 2014 SP2 Update 2
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
Distinguished Contributor
zdhrichard
Posts: 128
Registered: ‎05-03-2011
Message 6 of 20 (1,081 Views)

Re: How to delete suppressed components by iLogic Rule

01-24-2013 10:54 AM in reply to: mrattray

Hello MIke,

 

For deleting features, do you know how to delete the relative sketches?

 

I tested the codes, it could delete features, but the sketches are still in the tree.

Rich

Autodesk Inventor Professional 2014 (64 Bit Edition)
Build: 246, Release 2014 SP2 Update 2
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
*Expert Elite*
mrattray
Posts: 2,538
Registered: ‎09-13-2011
Message 7 of 20 (1,075 Views)

Re: How to delete suppressed components by iLogic Rule

01-24-2013 11:00 AM in reply to: zdhrichard

When I tested it the code deleted the consumed sketches as well as the feature. Can you attach the model?

Mike (not Matt) Rattray

Distinguished Contributor
zdhrichard
Posts: 128
Registered: ‎05-03-2011
Message 8 of 20 (1,071 Views)

Re: How to delete suppressed components by iLogic Rule

01-24-2013 11:23 AM in reply to: mrattray

Here is a simplified model.

Rich

Autodesk Inventor Professional 2014 (64 Bit Edition)
Build: 246, Release 2014 SP2 Update 2
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
*Expert Elite*
mrattray
Posts: 2,538
Registered: ‎09-13-2011
Message 9 of 20 (1,067 Views)

Re: How to delete suppressed components by iLogic Rule

01-24-2013 11:31 AM in reply to: zdhrichard

Did you already run your delete features sub on this part? The code doesn't do anything at all for me.

Mike (not Matt) Rattray

Distinguished Contributor
zdhrichard
Posts: 128
Registered: ‎05-03-2011
Message 10 of 20 (1,062 Views)

Re: How to delete suppressed components by iLogic Rule

01-24-2013 11:43 AM in reply to: mrattray

Yes, I did. This is the result after runing the code.

Rich

Autodesk Inventor Professional 2014 (64 Bit Edition)
Build: 246, Release 2014 SP2 Update 2
Windows 7 Professional Service Pack 1
Intel(R) Xeon(R) CPU E5645
12.0 GB Memory
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.