Hi,
I have a couple of dozen features in my part, of which only one will be active at any time. The feature tree may be subject to additions, so I am looking for an ilogic rule that will first suppress all of the features in the part, and then switch on the specific feature I require (using a parameter). Does anyone have any code to suppress ALL features? Thank you very much for your time.
Solved! Go to Solution.
Solved by harco. Go to Solution.
Doesn't anyone know how to do this? Surely this is a regularly requested command?
I don't have time right now to search or write code for you, but what you would be looking for is a for each loop that cycles through each feature in the features collection and toggles the feature.isactive property to false. Ty doing some searching in this forum and on google, if you can't find anything I'll throw something together for you.
Hi CadlineSupport,
Here is an example that will Suppress or Unsuppress all of the features in a part. There are a couple of other ways to do this as well, but those methods might require you to determine if a feature is dependent upon another. This method adds all features to a selection set, and suppresses or unsuppresses them all at once, so dependencies are not a factor.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
qSuppress = InputRadioBox("Do you want to Suppress or Unsuppress all features?", "Suppress", "UnSuppress", True, "iLogic") Dim oDoc As PartDocument oDoc = ThisApplication.ActiveDocument Dim oParams As Parameters oParams = oDoc.ComponentDefinition.Parameters Dim oFeatures As PartFeatures oFeatures = oDoc.ComponentDefinition.Features Dim oSelectSet As SelectSet oSelectSet = oDoc.SelectSet oSelectSet.Clear Dim oFeature As PartFeature For each oFeature in oFeatures oSelectSet.Select(oFeature) Next If qSuppress = True then ThisApplication.CommandManager.ControlDefinitions.Item("PartSuppressCtxCmd").Execute Else ThisApplication.CommandManager.ControlDefinitions.Item("PartUnSuppressCtxCmd").Execute End If
Hi Curtis,
Thank you very much for your reply. I have tried the code - it works brilliantly in the part itself, but when the rule is run from the assembly I get the following error:
Unable to cast COM object of type 'System.__ComObject' to interface type 'Inventor.PartDocument'.
I've tried running the rule from the assembly explicitly (rather than just using the parameter change event to drive it) but I get the same error. Is this going to be possible from an assembly?
Many thanks
I always wonder what crazy workarounds some people do with Inventor.. What are you doing that you need to be supressing features like that?
Hi CadlineSupport,
How will the part be identified / targeted from the assembly?
Do you want the user to select the part first, and run the rule on just the selected part?
Or should the rule run on multiple selected parts?
Or is the part to be identified by name?
Or should the rule run on all instances of that part file found in the assembly?
Or is it to run on all parts in the assembly?
Or some other scenario?
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
@mcgyvr wrote:I always wonder what crazy workarounds some people do with Inventor.. What are you doing that you need to be supressing features like that?
Hi CadlineSupport,
I would be interested in the "WHY" of this as well. It could be that you're creating an iLogic solution for something that Inventor can handle via a built in solution.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
I appreciate everyone's interest in this topic! All good questions, and yes I apologise for not mentioning that the rule would be run from an assembly.
Here's my workflow:
Lets say we have an assembly of several parts. Each of these parts will have one machining operation (a simple routed profile) performed on it at any given time, and I want to easily switch between these profiles (from the assembly file) to check fit etc. The profile to be used is specified using a parameter in the assembly. As there may be a dozen or so possible machining operations to choose from, they have all been created as features in the parts (with the profile for each machining being brought in as blocks in a derived master part), and I am looking for the simplest way to suppress ALL the other profile extrusions, and then simply make active the ONE profile specified by my parameter. Its a shame that you can't place features in folders to group them and control their suppression that way...
Thanks again for everyone's interest.
Another option is to use the suppress "if" option in the feature RMB properties.
Though you won't be able to drive it from the assembly as it will create a loop.
You can drive the part and assembly from Excel which will give easy multi parameter changes thereby allowing you to suppress all features at once.
It does need an excel save and an assembly update to force changes.
You could also use your master profile part to hold parameters but would mean editing to switch profiles although this is no more troublesome than editing excel.
Just an idea, maybe won't suit your workflow though.
Hope this helps.
See image
Harco this is brilliant stuff. I didn't twig that you could use the RMB properties on a feature for this (suppress feature if driving parameter ISN'T the right value. This is exactly what I need and perfect for switching a large number of profiles. Thanks to everyone for your help, the system works!
Sub Main
SuppressAllFeatures
UnsuppressAllFeatures
SupressFeaturesByNames({"Feature2", "Feature1", "Feature3"})
UnupressFeaturesByNames({"Feature5", "Feature6", "Feature4"})
SupressFeaturesByIndices({3, 2, 1})
UnupressFeaturesByIndices({6, 4, 5})
SupressFeaturesByNames({"Feature2", _
"Feature6", _
"Feature3", _
"Feature4", _
"Feature1", _
"Feature5"}) 'This format might be more readable?
'Cannot check feature depenency, however these functions are relatively fast given that they can take in array elements in any order. Suppressing/unsuppressing in a blind order is generally slower if there are lots of depencies.
End Sub
Sub SuppressAllFeautures()
For i = ThisDoc.Document.ComponentDefinition.Features.Count To 1 Step -1
ThisDoc.Document.ComponentDefinition.Features(i).Suppressed = True
Next i
End Sub
Sub UnsuppressAllFeautures()
For i = 1 To ThisDoc.Document.ComponentDefinition.Features.Count
ThisDoc.Document.ComponentDefinition.Features(i).Suppressed = True
Next i
End Sub
Sub SupressFeaturesByNames(Names() As String)
Dim FeatureList As New SortedList
For Each Name As String In Names
For i As Integer = 1 To ThisDoc.Document.ComponentDefinition.Features.Count
If ThisDoc.Document.ComponentDefinition.Features(i).Name = Name Then FeatureList.Add(-i, Name)
Next i
Next Name
For Each Key As Integer In FeatureList.Keys
Feature.IsActive(FeatureList(Key)) = False
Next Key
End Sub
Sub UnupressFeaturesByNames(Names() As String)
Dim FeatureList As New SortedList
For Each Name As String In Names
For i As Integer = 1 To ThisDoc.Document.ComponentDefinition.Features.Count
If ThisDoc.Document.ComponentDefinition.Features(i).Name = Name Then FeatureList.Add(i, Name)
Next i
Next Name
For Each Key As Integer In FeatureList.Keys
Feature.IsActive(FeatureList(Key)) = True
Next Key
End Sub
Sub SupressFeauturesByIndices(Indices() As Integer)
System.Array.Sort(Indices)
For i = UBound(Indices) To 0 Step -1
If Indices(i) Mod 1 = 0 And Indices(i) >= 1 And Indices(i) <= ThisDoc.Document.ComponentDefinition.Features.Count Then ThisDoc.Document.ComponentDefinition.Features(Indices(i)).Suppressed = True
Next i
End Sub
Sub UnsupressFeauturesByIndices(Indices() As Integer)
System.Array.Sort(Indices)
For i = 0 To UBound(Indices)
If Indices(i) Mod 1 = 0 And Indices(i) >= 1 And Indices(i) <= ThisDoc.Document.ComponentDefinition.Features.Count Then ThisDoc.Document.ComponentDefinition.Features(Indices(i)).Suppressed = False
Next i
End Sub