Suppress

Suppress

Anonymous
Not applicable
870 Views
13 Replies
Message 1 of 14

Suppress

Anonymous
Not applicable
Hi, I am looking for some VB code that will suppress part features, dependent on the length of a parameter e.g. ( d7 in the model parameters table).

I have two features I want to suppress feat1 & feat2, so if d7 = > 20mm and <30 feat1 is suppressed, and if d7 = >30mm and <40 feat2 is suppressed.

I hope to run the code with a macro button, is there an automatic way of doing this, say when you update the model.

I hope that make sense, thanks for any help.

Cheers

Simon.
INV9
0 Likes
871 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable
This could also be achieved with Iparts. -- Sean Dotson, PE www.sdotson.com Autodesk Inventor Certified Expert Sidel, Engineering & Manufacturing Manager "simonm" wrote in message news:23159009.1096977677284.JavaMail.jive@jiveforum1.autodesk.com... > Hi, I am looking for some VB code that will suppress part features, dependent on the length of a parameter e.g. ( d7 in the model parameters table). > > I have two features I want to suppress feat1 & feat2, so if d7 = > 20mm and <30 feat1 is suppressed, and if d7 = >30mm and <40 feat2 is suppressed. > > I hope to run the code with a macro button, is there an automatic way of doing this, say when you update the model. > > I hope that make sense, thanks for any help. > > Cheers > > Simon. > INV9
0 Likes
Message 3 of 14

Anonymous
Not applicable
Thanks Sean I will have alook at that, any idea on the VB code.

Cheers
0 Likes
Message 4 of 14

Anonymous
Not applicable
Try this. Dim oParams As Parameters Set oParams = oDoc.ComponentDefinition.Parameters Dim oModelParams As ModelParameters Set oModelParams = oParams.ModelParameters Dim oFeat As PartFeature Set oFeat = oDoc.ComponentDefinition.Features(feat1) Dim dModelValue As Double dModelValue = oModelParams.Item(d7).Value *10 If 30>dModelValue >=20 Then oFeat.Suppressed = True End If "simonm" wrote in message news:23159009.1096977677284.JavaMail.jive@jiveforum1.autodesk.com... > Hi, I am looking for some VB code that will suppress part features, dependent on the length of a parameter e.g. ( d7 in the model parameters table). > > I have two features I want to suppress feat1 & feat2, so if d7 = > 20mm and <30 feat1 is suppressed, and if d7 = >30mm and <40 feat2 is suppressed. > > I hope to run the code with a macro button, is there an automatic way of doing this, say when you update the model. > > I hope that make sense, thanks for any help. > > Cheers > > Simon. > INV9
0 Likes
Message 5 of 14

Anonymous
Not applicable
Thanks, i will give it a try.
0 Likes
Message 6 of 14

Anonymous
Not applicable
oDoc Should be declared also. Dim oDoc As PartDocument Set oDoc = ThisApplication.ActiveDocument "Calimesa" wrote in message news:4162be51$1_2@newsprd01... > Try this. > > Dim oParams As Parameters > Set oParams = oDoc.ComponentDefinition.Parameters > > Dim oModelParams As ModelParameters > Set oModelParams = oParams.ModelParameters > > Dim oFeat As PartFeature > Set oFeat = oDoc.ComponentDefinition.Features(feat1) > > Dim dModelValue As Double > dModelValue = oModelParams.Item(d7).Value *10 > If 30>dModelValue >=20 Then > oFeat.Suppressed = True > End If > > > > > > > > "simonm" wrote in message > news:23159009.1096977677284.JavaMail.jive@jiveforum1.autodesk.com... > > Hi, I am looking for some VB code that will suppress part features, > dependent on the length of a parameter e.g. ( d7 in the model parameters > table). > > > > I have two features I want to suppress feat1 & feat2, so if d7 = > 20mm > and <30 feat1 is suppressed, and if d7 = >30mm and <40 feat2 is suppressed. > > > > I hope to run the code with a macro button, is there an automatic way of > doing this, say when you update the model. > > > > I hope that make sense, thanks for any help. > > > > Cheers > > > > Simon. > > INV9 > >
0 Likes
Message 7 of 14

Anonymous
Not applicable
I dont get errors, but the code does not seem to work, any ideas ?

Heres the code so far,

Public Sub feats_new()

Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oParams As Parameters
Set oParams = oDoc.ComponentDefinition.Parameters

Dim oModelParams As ModelParameters
Set oModelParams = oParams.ModelParameters

Dim oFeat As PartFeature
Set oFeat = oDoc.ComponentDefinition.Features("Extrusion2")

Dim dModelValue As Double
dModelValue = oModelParams.Item("d7").Value * 10
If 30 > dModelValue <= 20 Then
oFeat.Suppressed = True

End If

End Sub

I think the above code is designed for one feature, basicly I am trying to suppress either extrusion1 or extrusion 2 depending on wether the size distance "d7" from my sketch is between 20 and 29mm or 30 and 40mm. i.e if the size is between 20-29mm extrusion 1 is suppressed and if the size is between 30 and 40mm feature 2 is suppressed

Thanks again
Simon.
0 Likes
Message 8 of 14

Anonymous
Not applicable
Change this:
if 30 > dModelValue <= 20 Then
oFeat.Suppressed = True
End If

To this:
if dModelValue > 30 and dModelValue <= 20 Then
oFeat.Suppressed = True
End If


Mike
0 Likes
Message 9 of 14

Anonymous
Not applicable
Thanks Mike and every one else who has helped that works great 🙂
0 Likes
Message 10 of 14

Anonymous
Not applicable
Yep that worked fine with a single part file, but when I try to apply it to my full assembly it does not work. Do I need to add another parameter object? to link to the sub assy.

Assembly break down as follows:-

Main Assy - subassy - part - feature

I am learning all be it slow !

Thanks Again

Simon
0 Likes
Message 11 of 14

Anonymous
Not applicable
You'll need to change all the parameters to a name that will be common throughout your assembly. Inventor by default will assign the numerical values to all dimensions (d7,d8, d9 etc), you can change for example d7 to be " ExtrudePar" in one model, in another the part which would change the same as the previous may have a d22 value. In that model change the d22 value to "ExtrudePar".

Now the other side of your program will need to iterate through the whole assemblies parts looking for parts with those particular parameter names to change.

Not that I've thought about any of this before .

Mike
0 Likes
Message 12 of 14

Anonymous
Not applicable
You'd better create some user parameters if you want the code to be run for both files "simonm" wrote in message news:27514791.1097076408495.JavaMail.jive@jiveforum1.autodesk.com... > Yep that worked fine with a single part file, but when I try to apply it to my full assembly it does not work. Do I need to add another parameter object? to link to the sub assy. > > Assembly break down as follows:- > > Main Assy - subassy - part - feature > > I am learning all be it slow ! > > Thanks Again > > Simon
0 Likes
Message 13 of 14

Anonymous
Not applicable
Thanks Calimesa but how do I apply that to my code?

Public Sub feats_new()

Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oParams As Parameters
Set oParams = oDoc.ComponentDefinition.Parameters

Dim oModelParams As ModelParameters
Set oModelParams = oParams.ModelParameters

Dim oFeat As PartFeature
Set oFeat = oDoc.ComponentDefinition.Features("Extrusion2")

Dim dModelValue As Double
dModelValue = oModelParams.Item("d7").Value * 10
If dModelValue < 22 And dModelValue >= 20 Then
oFeat.Suppressed = True
ElseIf dModelValue < 30 And dModelValue >= 23 Then
oFeat.Suppressed = False


End If

End Sub










Message was edited by: simonm
0 Likes
Message 14 of 14

Anonymous
Not applicable
I have had a go with this code, but it does not work, i am not sure were i am going wrong

Public Sub feats_new()

Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oParams As Parameters
Set oParams = oDoc.ComponentDefinition.Parameters

Dim oModelParams As ModelParameters
Set oModelParams = oParams.ModelParameters

Dim oOccurance As ComponentOccurrence
Set oOccurance = oDoc.ComponentDefinition.Occurrences("test:1")

Dim oFeat As PartFeature
Set oFeat = oDoc.ComponentDefinition.Features("Extrusion2")

Dim dModelValue As Double
dModelValue = oModelParams.Item("d7").Value * 10
If dModelValue < 22 And dModelValue >= 20 Then
oFeat.Suppressed = True
ElseIf dModelValue < 30 And dModelValue >= 23 Then
oFeat.Suppressed = False


End If

End Sub
0 Likes