Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic Code for feature detection

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
Anonymous
2367 Views, 8 Replies

iLogic Code for feature detection

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? 

 

8 REPLIES 8
Message 2 of 9
mcgyvr
in reply to: Anonymous

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


-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 3 of 9
Anonymous
in reply to: mcgyvr

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?

Message 4 of 9
mcgyvr
in reply to: Anonymous

@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

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 5 of 9
Anonymous
in reply to: mcgyvr

I see now what my issue was and learned a bit from your additions. Thank you for your assistance Sir!

Message 6 of 9
Curtis_Waguespack
in reply to: Anonymous

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
Message 7 of 9
mcgyvr
in reply to: Curtis_Waguespack

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.. Smiley Wink

 



-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 8 of 9
Curtis_Waguespack
in reply to: mcgyvr


@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

Message 9 of 9

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.

Post to forums  

Autodesk Design & Make Report