Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ilogic to count features

22 REPLIES 22
SOLVED
Reply
Message 1 of 23
jletcher
3377 Views, 22 Replies

ilogic to count features

I have 8 holes each a single feature is there a way for ilogic to count the active ones even if they change to inactive without a ten mile long code?

 

 

Hole 1  true

Hole 2 true

Hole 3 true

Hole 4 False

Hole 5 False

Hole 6 False

Hole 7 true

Hole 8 true

 

Count should be 5

 

If I change to

 

Hole 1  true

Hole 2 true

Hole 3 true

Hole 4 False

Hole 5 true

Hole 6 False

Hole 7 true

Hole 8 true

 

Count should be 6

 

 

Hole 1  False

Hole 2 False

Hole 3 False

Hole 4 False

Hole 5 true

Hole 6 False

Hole 7 true

Hole 8 true

 

Count should be 3

 

Can this be done with short code?

 

Many Thanks

 

22 REPLIES 22
Message 2 of 23
thomaskennedy
in reply to: jletcher

You can use a For Each Loop to iterate through all the hole features. Something like this should do it :

 

NoOfHoles = 0

For Each HFeature As HoleFeature In ThisDoc.Document.ComponentDefinition.Features.HoleFeatures		

	If HFeature.Suppressed = False Then NoOfHoles = NoOfHoles + 1
	
Next HFeature

MsgBox(NoOfHoles)

 

Hope this helps

Tom

Message 3 of 23
jletcher
in reply to: thomaskennedy

This gives me an error "end of statement expected"

 

For Each HFeature As HoleFeature In ThisDoc.Document.ComponentDefinition.Features.HoleFeatures

 

 

Message 4 of 23
jletcher
in reply to: thomaskennedy

Also this will count all holes right? I only need 8 of the holes to be count if they are active or not if it counts all holes it will give me the wrong count.. Unless I minus the others correct?

Message 5 of 23
jletcher
in reply to: thomaskennedy

One more thinfg I want this to go to a ipro in my custom so do I just take out the MsgBox (NoOfHoles)

and put in the code to fill in my custom iproperty?

Message 6 of 23
jletcher
in reply to: jletcher

Autodesk if your not going to step in and help then make samples and help files for ilogic PLEASE.

Message 7 of 23
thomaskennedy
in reply to: jletcher

Yes, that code will count all active hole features.

 

Yes, change Msgbox(NoOfHoles) to iProperties.Value("Custom", "HoleCount") = NoOfHoles.

 

Not sure why your're getting an error, did the code paste correctly into your rule?

 

Tom

 

ps. There is lots of help and sample code in the 'Programming Help' in Inventor. This is the API help area, which is where you should be looking for this sort of thing.

Note that the examples are given in VBA but it's easy to convert them for use in iLogic.

Message 8 of 23
thomaskennedy
in reply to: jletcher

Yes you can subtract a value from the hole count to give you the count you need (if this is workable for you) otherwise you can do some checks against the hole name.

 

For example, if you named the holes that need counting "CountMe Hole 1" / "CountMe Hole 2" etc. you could do :

 

NoOfHoles = 0

For Each HFeature As HoleFeature In ThisDoc.Document.ComponentDefinition.Features.HoleFeatures		

	If HFeature.Suppressed = False Then
		If Left(HFeature.Name,7) = "CountMe" Then
			NoOfHoles = NoOfHoles + 1
		End If
	End If
	
Next HFeature

iProperties.Value("Custom", "HoleCount") = NoOfHoles

 

Which will only add the hole to the count if the first 7 chars are "CountMe" 

Message 9 of 23
jdkriek
in reply to: thomaskennedy

I attest to that code working in 2011, 2012, and 2013 iLogic 😉

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


Message 10 of 23
jletcher
in reply to: thomaskennedy

Well hard to say if it pasted right seeing I don't know what it looks like it copied just like you posted.

 

And API is where I try to get help but I am not having much luck converting it to ilogic.

Message 11 of 23
jletcher
in reply to: jletcher

now I did rename the hole feature could this be the reason it's not working.

Message 12 of 23
jletcher
in reply to: jletcher

Here is a screen shot to show error

 

Error.JPG

Message 13 of 23
jletcher
in reply to: jletcher

Holes I would like to have count if active and remove from count if inactive

 

holes.JPG

Message 14 of 23
thomaskennedy
in reply to: jletcher

Hmmm..

 

Which line is Line 64 in your rule?

Message 15 of 23
jletcher
in reply to: thomaskennedy

its the for each statement that you supplied..

Message 16 of 23
thomaskennedy
in reply to: jletcher

Could you post your entire rule ? I can't see why it wouldn't work.

 

Or even better you could post your model...

Message 17 of 23
jletcher
in reply to: thomaskennedy

Here is the model

Message 18 of 23
thomaskennedy
in reply to: jletcher

Im not sure why it didnt work first time, I re copied the code back in and now its working.

 

I also added a line that checks if the last char of the hole name is a number - if it is a number then it doesnt get added to the count.

 

Hope this works OK for you.

Message 19 of 23
jletcher
in reply to: thomaskennedy

Thats it great thanks...

Message 20 of 23
kmiller
in reply to: jletcher

Just guessing but you where probably just missing the "End If" statement right above the Line that says "Next HFeature".  If you where wondering why it wasn't working the first time. 

 

PS - Thanks for the link to this on my post. 

-------------------------------------------------------------------------------------------------

If this response answers your question please click "Accept as Solution".

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report