I have a code working that is not very efficient.
It works, but it is very slow, i suspect it can be 28x faster, but I don't know how
What I have:
I have a plate with many hole patterns.
I calculated how many holes each pattern has
Parameters: Excel_Holes_Row_0 to Excel_Holes_Row 27
For each Row i have 4 features:
Pipe Hole
Rectangular array of Pipe Holes
Product Hole
Rectangular array of Product holes
What I want to do:
I want to suppress/unsuppress features with a rule
If Excel_Holes_Row_20 < 2 It means Suppress the rectangular arrays on this row
If Excel_Holes_Row_20 = 0 It means suppress the hole features on this row
This is my code:
Dim oDoc As Document = ThisDoc.Document
Dim PFeats As PartFeatures = oDoc.ComponentDefinition.Features
Dim PFeat As PartFeature
For Each PFeat In PFeats
i = 0
For i = 0 To 27 Step 1
If PFeat.Name = "Pipe Hole " & i Then
If Parameter("Excel_Holes_Row_"&i) = 0 Then
PFeat.Suppressed = True
Else
PFeat.Suppressed = False
End If
End If
If PFeat.Name = "Product Hole " & i Then
If Parameter("Excel_Holes_Row_"& i ) = 0 Then
PFeat.Suppressed = True
Else
PFeat.Suppressed = False
End If
End If
If PFeat.Name = "Pipe Row " & i Then
If Parameter("Excel_Holes_Row_"& i ) < 2 Then
PFeat.Suppressed = True
Else
PFeat.Suppressed = False
End If
End If
If PFeat.Name = "Product Row " & i Then
If Parameter("Excel_Holes_Row_"& i ) < 2 Then
PFeat.Suppressed = True
Else
PFeat.Suppressed = False
End If
End If
How can I make this more efficient?
Thanks in advance,
Arnold
Solved! Go to Solution.
Solved by thomaskennedy. Go to Solution.
I've found that feature / component / constraint suppression can be extremely slow.
One thing you can do to improve performance is to set the End of Part to the top before you begin the feature suppresion, then set it to the bottom when you have finished.
This will set either the End of Part or End of Features (depending on document type) to the bottom :
Dim oCompDef As Inventor.ComponentDefinition oCompDef = ThisDoc.Document.ComponentDefinition If TypeOf oCompDef Is Inventor.AssemblyComponentDefinition Then oCompDef.SetEndOfFeaturesToTopOrBottom(True) ElseIf TypeOf oCompDef Is Inventor.PartComponentDefinition Then oCompDef.SetEndOfPartToTopOrBottom(True) End If
This will set the EOP to the bottom :
Dim oCompDef As Inventor.ComponentDefinition oCompDef = ThisDoc.Document.ComponentDefinition If TypeOf oCompDef Is Inventor.AssemblyComponentDefinition Then oCompDef.SetEndOfFeaturesToTopOrBottom(False) ElseIf TypeOf oCompDef Is Inventor.PartComponentDefinition Then oCompDef.SetEndOfPartToTopOrBottom(False) End If
Hopefully this will improve performance for you, it did for me.
Cheers
Tom
ps. There is an alternative way to control feature suppression at a part level - right click on the feature and go to properties. From there you can control if the feature is suppreseed based on the value of a Parameter, probably not the answer for your issue, but it's a good one to know.
Place End of Part at top truly helps a lot with speed
(it would normally build up each row in 2 sec (28 times)
Now its like 5-10 seconds
I also renamed all features with row number in front. Eg.: 20 - Pipe hole.
With Val(PFeat.Name) I get 20 as result.
Previously i check for each value from 0 to 27
oCompDef.SetEndOfPartToTopOrBottom(True)
For Each PFeat In PFeats
i = Val(PFeat.Name)
If PFeat.Name = i & " - Pipe Hole" Then
If Parameter("Excel_Holes_Row_"&i) = 0 Then
Placing End of Part on top does not affect dimension in drawing
Thanks for the help