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?
Solved! Go to Solution.
Solved by mrattray. Go to Solution.
Solved by mrattray. Go to Solution.
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
Hi Mike, by any chance do you know how to do the same but for deleting suppressed features in the part environment?
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
Thanks lot, Mike.
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.
When I tested it the code deleted the consumed sketches as well as the feature. Can you attach the model?
Here is a simplified model.
Did you already run your delete features sub on this part? The code doesn't do anything at all for me.
Yes, I did. This is the result after runing the code.
Can you post a version without the code having been ran?
This is the ipt which I took the rule off.
I hope it is what you want.
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.
Great.
It is nice and clean now.
Thanks lot, Mike.
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,
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?
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)
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.
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