Inventor Customization

Reply
*Pro
jletcher
Posts: 1,866
Registered: ‎05-18-2011
Message 1 of 23 (603 Views)
Accepted Solution

ilogic to count features

603 Views, 22 Replies
08-14-2012 01:10 PM

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

 


Please mark this response as "Accept as Solution" if it answers your question.

James Letcher
2012 Factory Design Suite ( will not load 2013)
What happen to my Inventor :-(
Distinguished Contributor
thomaskennedy
Posts: 110
Registered: ‎09-27-2010
Message 2 of 23 (587 Views)

Re: ilogic to count features

08-15-2012 01:07 AM 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

*Pro
jletcher
Posts: 1,866
Registered: ‎05-18-2011
Message 3 of 23 (583 Views)

Re: ilogic to count features

08-15-2012 04:13 AM in reply to: thomaskennedy

This gives me an error "end of statement expected"

 

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

 

 


Please mark this response as "Accept as Solution" if it answers your question.

James Letcher
2012 Factory Design Suite ( will not load 2013)
What happen to my Inventor :-(
*Pro
jletcher
Posts: 1,866
Registered: ‎05-18-2011
Message 4 of 23 (581 Views)

Re: ilogic to count features

08-15-2012 04:15 AM 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?


Please mark this response as "Accept as Solution" if it answers your question.

James Letcher
2012 Factory Design Suite ( will not load 2013)
What happen to my Inventor :-(
*Pro
jletcher
Posts: 1,866
Registered: ‎05-18-2011
Message 5 of 23 (577 Views)

Re: ilogic to count features

08-15-2012 04:32 AM 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?


Please mark this response as "Accept as Solution" if it answers your question.

James Letcher
2012 Factory Design Suite ( will not load 2013)
What happen to my Inventor :-(
*Pro
jletcher
Posts: 1,866
Registered: ‎05-18-2011
Message 6 of 23 (568 Views)

Re: ilogic to count features

08-15-2012 06:43 AM in reply to: jletcher

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


Please mark this response as "Accept as Solution" if it answers your question.

James Letcher
2012 Factory Design Suite ( will not load 2013)
What happen to my Inventor :-(
Distinguished Contributor
thomaskennedy
Posts: 110
Registered: ‎09-27-2010
Message 7 of 23 (559 Views)

Re: ilogic to count features

08-15-2012 08:28 AM 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.

Distinguished Contributor
thomaskennedy
Posts: 110
Registered: ‎09-27-2010
Message 8 of 23 (554 Views)

Re: ilogic to count features

08-15-2012 08:36 AM 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" 

*Expert Elite*
jdkriek
Posts: 527
Registered: ‎03-29-2007
Message 9 of 23 (553 Views)

Re: ilogic to count features

08-15-2012 08:37 AM in reply to: thomaskennedy

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

Jonathan D. Kriek

Autodesk Inventor Certified Expert
Microsoft Certified Application Developer
_____________________________________________________
Did I help you? Please choose Accept as Solution or Kudos below

*Pro
jletcher
Posts: 1,866
Registered: ‎05-18-2011
Message 10 of 23 (551 Views)

Re: ilogic to count features

08-15-2012 08:38 AM 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.


Please mark this response as "Accept as Solution" if it answers your question.

James Letcher
2012 Factory Design Suite ( will not load 2013)
What happen to my Inventor :-(

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you interested in helping shape the Autodesk Community?
We’re looking at a few different ways to improve the “All Forums” landing page and need your feedback! If interested, please take a few minutes to fill out the following Usability Study. Thank you for your time!

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube