Hi everbody,
I've got an IPT with several features in it (extrsions, revolution, fillets ...).
Some of them are suppressed by a condition such as "suppress if parameter_A = 0".
I'd like to replace this "parameter_A" by "parameter_B" with the help of iLogic/VBA.
So I need to read-out the original parameter and then replace it with the correct new one.
However I'm stuck here not knowing how to do that.
It should have something to do with "GetSuppressionCondition" with I found somewhere.
But I don't know how to handle it.
Can anyone help me, please?
Regards
Heiko1985
I guess I'm a little confused as to what you're really wanting it to do.
So currently you have:
Suppress if Param_A = 0
I get that.
It's the replace Param_A by Param_B part that I'm not sure about... that sounds like you would just say:
Suppress if Param_B = 0
But if what you're going for is a swap when Param_A causes suppression then I'd say:
If Param_A = 0 then
Param_A = Param_B
else
End if
Is that what you're trying to do?
Thank you for your reply.
To make things more precise:
I have an IPT which is made of several features, e. g. extrusions.
Some of theese are suppressed by a condition: Right click => Properties => Suppress if ...
Each extrusion has a different suppression condition. However, their parameters are all named in a specific way, such as: Parameter1_A, Parameter2_A, Parameter3_A and so on. So, they all end with "_A".
Now, I need to apply new parameters for all theese suppression conditions. The new parameters have the same name as the old ones, but they end with "_B". But there is no reference between "_A" and "_B". And since I have to publish a cleaned up IPT, I can't just say "Parameter1_A = Parameter1_B".
So, I want to do the following:
1. Check every single feature (resp. extrusion) for its suppression condition.
2. If there is a suppression condition, read-out its parameter. The parameter's name will be "Something_A".
3. Remove the original parameter and apply the new parameter, which is called "Something_B".
4. Delete the old parameter "Something_A" which is no longer been used.
I know how to handle parameters in the parameter list. My problem is how to get and apply the parameter in the suppression condition.
Phew, hope I could express myself ...
This will replace the parameter names.
Note: There's no error checking to check if the parameter exists or the feature is valid.
Dim compDef As ComponentDefinition = ThisDoc.Document.ComponentDefinition Dim param As Inventor.Parameter Dim compareType As ComparisonTypeEnum Dim expr As Object For Each feat As Object In compDef.Features
'param Cannot be null so set to first parameter.
param = compDef.Parameters(1) If feat.GetSuppressionCondition(param, compareType, expr) Then If param.Name.EndsWith("_A") Then Dim newName As String = param.Name.Replace("_A", "_B") feat.SetSuppressionCondition(compDef.Parameters(newName), compareType, expr) End If End If Next
Thank you!
I had to edit it a bit and now it works very well - except for one issue.
Dim od As PartDocument Set od = ThisApplication.ActiveDocument Dim compDef As ComponentDefinition Set compDef = od.ComponentDefinition Dim param As Inventor.Parameter Dim compareType As ComparisonTypeEnum Dim expr As Object Dim feat As PartFeature For Each feat In compDef.Features If feat.GetSuppressionCondition(param, compareType, expr) Then oldName = param.Name If Mid(oldName, Len(oldName) - 1, Len(oldName)) = "_A" Then Dim newName As String newName = Replace(oldName, "_A", "_B") 'feat.SetSuppressionCondition(compDef.Parameters(newName), compareType, expr) '<= Error! End If End If Next
I can now check if there is a suppression condition and in case read-out its parameter.
But I can't set the new parameter.
The line feat.SetSuppressionCondition(compDef.Parameters(newName), compareType, expr) gives me a syntax error and I don't know how to deal with it. 😞
Here's a working version.
Dim od As PartDocument Set od = ThisApplication.ActiveDocument Dim compDef As ComponentDefinition Set compDef = od.ComponentDefinition Dim param As Inventor.Parameter Dim compareType As ComparisonTypeEnum Dim expr As Variant Dim feat As PartFeature For Each feat In compDef.Features Set param = compDef.Parameters(1) If feat.GetSuppressionCondition(param, compareType, expr) Then oldName = param.name If Mid(oldName, Len(oldName) - 1, Len(oldName)) = "_A" Then Dim newName As String newName = Replace(oldName, "_A", "_B") feat.SetSuppressionCondition compDef.Parameters(newName), compareType, expr End If End If Next
In VBA the line
feat.SetSuppressionCondition(compDef.Parameters(newName), compareType, expr)
Should be:
feat.SetSuppressionCondition compDef.Parameters(newName), compareType, expr