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 delete suppressed components by iLogic Rule

20 REPLIES 20
SOLVED
Reply
Message 1 of 21
zdhrichard
6131 Views, 20 Replies

How to delete suppressed components by iLogic Rule

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 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
20 REPLIES 20
Message 2 of 21
mrattray
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

Message 3 of 21
waynehelley
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 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 4 of 21
mrattray
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

Message 5 of 21
zdhrichard
in reply to: mrattray

Thanks lot, Mike.

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 21
zdhrichard
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 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 7 of 21
mrattray
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

Message 8 of 21
zdhrichard
in reply to: mrattray

Here is a simplified model.

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 9 of 21
mrattray
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

Message 10 of 21
zdhrichard
in reply to: mrattray

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

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 11 of 21
mrattray
in reply to: zdhrichard

Can you post a version without the code having been ran?

Mike (not Matt) Rattray

Message 12 of 21
zdhrichard
in reply to: mrattray

This is the ipt which I took the rule off.

 

I hope it is what you want.

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 13 of 21
mrattray
in reply to: zdhrichard

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.

Mike (not Matt) Rattray

Message 14 of 21
zdhrichard
in reply to: mrattray

Great.

It is nice and clean now.

 

Thanks lot, Mike.

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 15 of 21
waynehelley
in reply to: mrattray

Thanks Mike,

 

If you come up with a tidier way of doing it can you post it on here please.

 

The code seems to do it's job for me but gives an error message.  Does this happen for you too? I will attach my code

 

Error in rule: DeleteSuppressedFeatures, in document: DeleteSuppressedFeatures.iLogicVb

Object variable or With block variable not set.

 

System.NullReferenceException: Object variable or With block variable not set.

   at Microsoft.VisualBasic.CompilerServices.Symbols.Container..ctor(Object Instance)

   at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)

   at LmiRuleScript.Main()

   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)

   at p.b(String A_0)

 

I can bypass this by using 'On Error Resume Next' but I would rather have a real fix.  I am maybe going to be using this code later to write a rule which will seperate ipart members into standard part files.

 

Thanks,

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 16 of 21
mrattray
in reply to: waynehelley

You have oDoc dimmed as DrawingDocument and you didn't set it equal to anything. If you just replace "oDoc" in my code snippet with "ThisDoc.Document" you should be OK. I'm surprised it still works at all like that.

 

Are you trying to run this from a drawing?

Mike (not Matt) Rattray

Message 17 of 21
waynehelley
in reply to: mrattray

Thanks for your help Mike,

 

I just got a bit confussed as I am still getting my head around dimming things (i had coppied that line of code from a program I have that runs in a drawing)

Wayne Helley
Inventor 2013 Certified Professional

Autodesk Inventor Professional 2023
Visual Studio 2022
Windows 10 Pro, 64-bit
Message 18 of 21
AERE
in reply to: mrattray

Hi Mike,

Thank you for posting those rules. They work fine on different features but not on the Coil feature (the sketch is not deleted by the rule) and I am totally puzzled by that...please take a lok at the attached file. 

Do you have any idea why? - I would greatly appreciate any response.

 

Tags (1)
Message 19 of 21
mrattray
in reply to: AERE

I can't look at it right now as I'm working in 2013 and that's a 2014 file. If I have some free time next week I'll take a look at it.
Mike (not Matt) Rattray

Message 20 of 21
achmidt
in reply to: mrattray

Hi Mike,

 

I have a simple assembly with supressed parts, I used the code above (2nd post) for the supressed parts, not sure why, but i`m getting a error:


The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
   at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn)
   at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn)
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Can you please help? Is this because I have Patterns with supressed elements?

 

 

Thank you

Inventor Virtual Parts Addin

http://apps.exchange.autodesk.com/INVNTOR/en/Detail/Index?id=appstore.exchange.autodesk.com%3Avirtualpartsadd-in_windows32and64%3Aen

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

Post to forums  

Autodesk Design & Make Report