I am trying to get my ilogic code to detect if a hole feature is in the .ipt file AND active (not suppressed). Once the code decides yes or no it will populate a custom property which will end up on a BOM. Here is the code that I am currently working with:
SyntaxEditor Code Snippet
Dim oFeature As PartFeature Dim oFeatures As PartFeatures oFeatures = ThisDoc.Document.ComponentDefinition.Features i = 0 For Each oFeature In oFeatures If oFeature.Name.Contains("Hole") = True While oFeature.Name.Contains("Suppressed") = False End While i = i+1 End If Next If i > 0 iProperties.Value("Custom", "Beamline") = "YES" Else iProperties.Value("Custom", "Beamline") = "NO" End If
Everything is working as expected except for the part that checks if the feature is active...
SyntaxEditor Code Snippet
While oFeature.Name.Contains("Suppressed") = False End While
This section causes Inventor to immediately freeze. I am guessing this is the wrong way to go about it... but it was my best shot. Can anyone give me a suggestion on how to detect if a feature (without a known name) both exists and is active?
Solved! Go to Solution.
Solved by mcgyvr. Go to Solution.
To start..This just means while there is no name containing suppressed.. Do that..
and thats an endless loop if nothing contains suppressed....
The while is being met so its attempting to do "something while"...and inventor sits there waiting for the while to be true so it can exit..
While oFeature.Name.Contains("Suppressed") = False End While
and to answer your question..
If oFeature.Suppressed = True
There is what I am looking at now.
There is an error with my And statement ( not sure why).
For Each oFeature In oFeatures If oFeature.Name.Contains("Hole") = True And oFeature.Suppressed = False i = i+1 End If
I also tried without the "And". It just suppresses the hole feature.
For Each oFeature In oFeatures If oFeature.Name.Contains("Hole") = True oFeature.Suppressed = False i = i+1 End If
I have been staring at this for a long time, I am sure the answer is obvious, I'm just not getting it.
What am I missing here?
@Anonymous Sorry.. Here
Dim oFeature As PartFeature Dim oFeatures As PartFeatures oFeatures = ThisDoc.Document.ComponentDefinition.Features i = 0 For Each oFeature In oFeatures 'check if its a hole If TypeOf oFeature Is HoleFeature Then 'check if its unsuppressed If oFeature.Suppressed = False 'increment one i = i + 1 End If End If Next If i > 0 iProperties.Value("Custom", "Beamline") = "YES" Else iProperties.Value("Custom", "Beamline") = "NO" End If
Hi @Anonymous,
Additionally you can look at just the holefeatures collection, as in this example.
Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
i = 0 For Each oHole In ThisDoc.Document.ComponentDefinition.Features.HoleFeatures If oHole.suppressed = True Then i = i+1 End If Next If i > 0 Then MessageBox.Show(i & " hole(s) are suppressed", "iLogic") End If
The example from Curtis great/cleaner,etc...
I was just trying to stick with the general flow/layout of the originally posted code just because thats what they seemed to already understand..
Well that and I'm a novice and Curtis can walk all over me in the ilogic world..
@mcgyvr wrote:
The example from Curtis great/cleaner,etc...
nah, there was nothing wrong at all with your example. I'd already started to post before I noticed your solution, so I just went ahead an added it, but mostly just to add the link to the Inventor Customization forum:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120
One other thing I'll add concerning the use of "And" in the conditional statement is that the "And" needs to be inline with the if, and not on a separate line. That was likely the source of the error with "And"
Dim oFeature As PartFeature Dim oFeatures As PartFeatures oFeatures = ThisDoc.Document.ComponentDefinition.Features i = 0 For Each oFeature In oFeatures 'check if its a hole If TypeOf oFeature Is HoleFeature And oFeature.Suppressed = False 'increment one i = i + 1 End If Next If i > 0 iProperties.Value("Custom", "Beamline") = "YES" Else iProperties.Value("Custom", "Beamline") = "NO" End If
In this example I've used a space and underscore after HoleFeature to "wrap" it to the next line, which would work as well.
Dim oFeature As PartFeature Dim oFeatures As PartFeatures oFeatures = ThisDoc.Document.ComponentDefinition.Features i = 0 For Each oFeature In oFeatures 'check if its a hole If TypeOf oFeature Is HoleFeature _ And oFeature.Suppressed = False 'increment one i = i + 1 End If Next If i > 0 iProperties.Value("Custom", "Beamline") = "YES" Else iProperties.Value("Custom", "Beamline") = "NO" End If
Can't find what you're looking for? Ask the community or share your knowledge.