Suppress Feature using a Range

Suppress Feature using a Range

Anonymous
Not applicable
713 Views
6 Replies
Message 1 of 7

Suppress Feature using a Range

Anonymous
Not applicable
I need to be able to suppress a feature in a part using a range. I've looked at the property of a feature and I can only select a single operation (>, <, etc.). I've tried writing some code but I'm getting an error. I would appreciate any help on the code or another way to suppress a feature in a range.

Public Function SupHole(CASE_HT As Double) As Double
CASE_HT = CASE_HT / 2.54
Dim oDoc As PartDocument
Dim oFeat As PartFeature
Set oFeat = oDoc.ComponentDefinition.Features("Hole22")
If CASE_HT > 109 And CASE_HT < 89 Then
oFeat.Suppressed = True
End If
End Function

Thanks for any help

Chris
0 Likes
714 Views
6 Replies
Replies (6)
Message 2 of 7

alewer
Advocate
Advocate
First of all, when I glance at your code, I notice that you will never supress the feature, as CASE_HT cannot be both greater than 109 and less than 89. You need to replace the "And" with "Or."

Edit: At second glance, I see that this is one of several problems with your code. You initialize but do not set oDoc (for example, "Set oDoc = ThisApplication.ActiveDocument"), your function returns nothing (should return a value or be a sub). You also divide by 2.54, which suggests a units conversion, in which case you should probably be using unitsofmeasure. I suggest you work through some of the example files in programming help.

You can probably do this without VBA by using sign(). There is a tutorial out there somewhere, but I can't seem to dig it up. I'll try to explain instead... Create a parameter that will be used to control the feature's suppression. The parameter equation, for your example, should read something like: sign(89.0001 ul - d0 / 1 in) + sign(d0 / 1 in - 108.9999 ul). If it returns a nonzero value, supress the feature. I've attached an example (2010) part. Edited by: alewer on Sep 4, 2009 1:57 PM
0 Likes
Message 3 of 7

Anonymous
Not applicable
Thanks for your help. Using the sign() solved my problem. That's a very clever idea. If you ever find the tutortial on it, I'd like to read it. The code I posted had been changed to try and solve an error I was getting. Orginally it had Set oDoc = ThisApplication.ActiveDocument. Listed below is the code I orginally started with. I get an error on Set oDoc = ThisApplication.ActiveDocument. I added the Inventor references thru Tools/References but I still get the error. I've listed the code below. If you see something really wrong with it, I would appreciate your comments. Finally, you mentioned about / 2.54. I have to do this because Inventor is in metric and I need to convert it to decimal.

Public Function SupHole(CASE_HT As Double) As Double
CASE_HT = CASE_HT / 2.54
Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition
Set oCompDef = oDoc.ComponentDefinition
Dim oFeat As PartFeature
Set oFeat = oDoc.ComponentDefinition.Features("Hole22")
If CASE_HT > 109 Or CASE_HT < 89 Then
oFeat.Suppressed = True
End If
End Function

Thanks again for your help,

Chris
0 Likes
Message 4 of 7

Anonymous
Not applicable

Using the sign()
solved my problem.  That's a very clever idea.  If you ever find the
tutorial on it, I'd like to read it.

 

See attached.

 

 

 

I get an error on Set oDoc
= ThisApplication.ActiveDocument
.

 

You've written this as a function, but I don't
know why.  Nowhere in your code do you return a value for the
function.  I'm guessing that you're trying to use this as an expression in
a parameter, like d2=VBA:SupHole(16).  If so, you
can't do that.  You're forbidden from accessing the Inventor API in a VBA
function.  This is covered very well in the Inventor API
documentation.

 

 

 

Finally, you mentioned about /
2.54.

 

It is considered very bad practice to perform
your own unit conversion with respect to programming Inventor.  The
Inventor API already provides a UnitsOfMeasure object that, among other things,
can convert units for you.  However, if I'm right about you trying to use
this as a VBA expression for a parameter, you can't access the
UnitsOfMeasure object for the aforementioned reason.  It would actually be
better to use the line of code

 

    If CASE_HT
> 276.86 or CASE_HT < 226.06 Then

 

thus doing the comparison in Inventor's native
centimeters.






brian r.
iwaskewycz


style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">inventor
specialist

0 Likes
Message 5 of 7

Anonymous
Not applicable
Thanks for the reply. The goal of the function was to set the suppress flag if a certain condition was meet and when the part was updated, it would be suppressed. That's why it didn't return a value. That was one reason I took out the Set oDoc = active part because I knew the part was active. I will keep reading up on it. It would be nice if a VBA/Inventor book existed, but I have not found one yet.

Thanks for the pdf file, unfortunally when I try to open it, it saids the file is damaged and cannot be opened. Here is my email address c.riley@mtcworldwide.com. If you get a chance, I would appreciate it if you could email the file or reattach it to a reply.

Thanks,

Chris
0 Likes
Message 6 of 7

Anonymous
Not applicable






brian r.
iwaskewycz


style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">inventor
specialist


style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">
href="http://www.corefurnace.com/">core furnace systems

0 Likes
Message 7 of 7

Anonymous
Not applicable

Well, I'd sure like to know what the cause of my
apparent inability to post a PDF is.

 







brian r.
iwaskewycz


style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">inventor
specialist


style="FONT-SIZE: 14pt; FONT-FAMILY: Verdana">core furnace
systems
0 Likes