iLogic counts the number extrusions of a specific feature

iLogic counts the number extrusions of a specific feature

Alex.Shechter
Contributor Contributor
2,073 Views
14 Replies
Message 1 of 15

iLogic counts the number extrusions of a specific feature

Alex.Shechter
Contributor
Contributor

Hello everyone,

 

The Problem:
I am trying to figure out a way how to automate a text in drawing to count the number of feature extrusions just like Hole Table does.

 

Cause of the problem:
Very often we have a part that has slots and this slots number varies.
I always count manually those slots and type it as a “static” txt in the drawing and when someone else works later on this part it is very often that we forget to update that static text.

 

My idea for a solution:
An iLogic rule in the part. This rule counts the number of extrusions that a feature with a specific name creates and writes it down in User Parameters.
For example:  “Slots1” (extrusion feature) has extruded 25 slots. The code writes in the User Parameters “Extrusion_Slots1” = 25
If “Slots1” for whatever reason after a change extrudes only 5 slots now then the parameter “Extrusion_Slots1” in the User Parameters should get automatically updated.
Then in the drawing I can add text and select User Parameters and add the “Extrusion_Slots1” as a variable that gets me the automatically updated value.

 

The question is how I get Inventor to count the number of extrusions that a specific feature does.

 

 

0 Likes
Accepted solutions (2)
2,074 Views
14 Replies
Replies (14)
Message 2 of 15

A.Acheson
Mentor
Mentor

That's simple enough to achieve. I have assumed this is in a part. Each extrusion name will need to be unique so something like SL1-1, SL1-2 etc SL1 to identify the slot size and 1,2,3 to uniquely identify each one . 

Quicky modified it from this post.

https://forums.autodesk.com/t5/inventor-forum/ilogic-feature-counting/td-p/8659430

 

If you place this rule in the document and set event trigger to on Save or model parameter change.

The down side is you need to rename the extrusion name in the browser. 

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim ExtrusionList As New ArrayList

' If a feature is Active (not suppressed), it is added the FeatureList array
For Each oExtrusion In oDoc.ComponentDefinition.Features.ExtrudeFeatures
	If oExtrusion.Name.Contains("SL1")  Then
		If Feature.IsActive(oExtrusion.Name) Then
		   ExtrusionList.Add(oExtrusion.Name)
		End If
	End If
Next

' Count the number of items in the FeatureList array
Dim FeatureCount As Integer
FeatureCount = ExtrusionList.Count

'Turn off these message boxes if not needed.
MessageBox.Show(FeatureCount, "iLogic")
d0 = InputListBox("Prompt", ExtrusionList, d0, Title := "Title", ListName := "List")

'Places the FeatureCount value into the User parameter
Parameter("Extrusion_Slots1") = FeatureCount   

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 15

Alex.Shechter
Contributor
Contributor

Thanks for the quick reply!

 

The code works but unfortunately not the way I imagined it.

It counts the number of feature names that contain “SL1” in them and not how many slots the feature creates.

So that means I would have to extrude each slot with a unique feature name that contains SL1 in it in order for this code to work. I could work with this but when I have to create individually more than 20 slots that way, and in many parts, this quickly becomes not a productive workflow.

 

Isn’t there anyway to make Inventor to count how many geometries a single feature creates like the hole feature does?

0 Likes
Message 4 of 15

A.Acheson
Mentor
Mentor

There may be but I have not use this method. Can you please provide a sample part with a number of slots as features. Provide also a few screen shots of the browser tree in case forum viewers have not got your INV release. This way other users can see the document your using (sheetmetal/part) the feature method used in slot creation etc.

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 15

Ralf_Krieg
Advisor
Advisor

Hello

 

Maybe this can be achived by counting the profiles in the extrude feature "SL-xxx". Of course, if two or more profiles overlap and Inventor recognizes them as one or if one slot consists of two or more profiles, this method will fail. Also if there are different slot types in one extrusion, but they should be separate counted, this is not possible.

 

Another idea is to use 1 Slot per extrusion and create a sketch driven pattern.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 6 of 15

Alex.Shechter
Contributor
Contributor

the attached files were created with Inventor 2021.

 

Slotted_Part01_P1.JPGSlotted_Part01_P2.JPG

 

 

 

0 Likes
Message 7 of 15

Alex.Shechter
Contributor
Contributor

I don't mind working with restrictions like specificpProfile or sizes as long as it works but the question is,

how do you make Inventor to count any geometry/extrussions of a feature at all?

0 Likes
Message 8 of 15

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

By counting the profiles used for create this extrusion.

 

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oUserParams As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters 
Dim iCount As Integer
Dim sCount As String

' If a feature is Active (not suppressed), it is added the FeatureList array
For Each oExtrusion As ExtrudeFeature In oDoc.ComponentDefinition.Features.ExtrudeFeatures
	If oExtrusion.Name.StartsWith("SL") Then
		If Feature.IsActive(oExtrusion.Name) Then
		   sCount = Mid(oExtrusion.Name, 3)
		   If sCount.Length = 1 Then
			   sCount = "0" & sCount
		   End If
		   MsgBox("Number_of_Slots_" & sCount & ": " & oExtrusion.Definition.Profile.Count)
			Try
		   		Parameter("Number_of_Slots_" & sCount)= oExtrusion.Definition.Profile.Count
			Catch
				oUserParams.AddByExpression ("Number_of_Slots_" & sCount, oExtrusion.Definition.Profile.Count, UnitsTypeEnum.kUnitlessUnits)
			End Try
		End If
	End If
Next

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 9 of 15

Alex.Shechter
Contributor
Contributor
It works!!! 🙂
Thank you and thank you everyone who tried to help with this. This saves me so much time and unnesasery frustrations. You guys are great!
0 Likes
Message 10 of 15

Ralf_Krieg
Advisor
Advisor

Hello

 

I think there's more work to do. What about patterns of this extrusion features? Not tested it, but I think this is not recognized by our code. Can the count of extrusion features raise over "SL99"? The code assumes til now there are myx 2 digits. Maybe there are more situations where result isn't correct.

For instance, I tried to create a simple keyhole slot (1x circle, 1x long slot) and this is recognized as 3 slots. I had to cut the not needed inner sketch lines or set it to construction line, to get correct value.

 


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 11 of 15

Alex.Shechter
Contributor
Contributor

I have experimented with this and as you can see the code works just fine , it counts over 99 and it counts diffrent shapes and ingular objects and pattern objects alike.

 

Slotted_Part01_P3_1.JPG

 

Slotted_Part01_P3.JPG

The only thing is, I tried to use this same code to count holes and it doesn't work for some reason. It seams to me I am missing something for the HoleFeature definition.

 

0 Likes
Message 12 of 15

Ralf_Krieg
Advisor
Advisor
Accepted solution

Hello

 

I  don't mean more than 99 slots per feature, but more than 99 features. If there is an feature "SL100", the code fails. Just want to say, don't except it's perfect.

For hole features you could try to count the holecenterpoints. If such a center point is positioned out of your volume and you drill "a hole in the air" this hole would even be counted.

 

Dim oDoc As PartDocument = ThisApplication.ActiveDocument
Dim oUserParams As UserParameters = oDoc.ComponentDefinition.Parameters.UserParameters 
Dim iCount As Integer
Dim sCount As String

' If a feature is Active (not suppressed), it is added the FeatureList array
For Each oExtrusion As ExtrudeFeature In oDoc.ComponentDefinition.Features.ExtrudeFeatures
	If oExtrusion.Name.StartsWith("SL") Then
		If Feature.IsActive(oExtrusion.Name) Then
		   sCount = Mid(oExtrusion.Name, 3)
		   If sCount.Length = 1 Then
			   sCount = "0" & sCount
		   End If
		   MsgBox("Number_of_Slots_" & sCount & ": " & oExtrusion.Definition.Profile.Count)
			Try
		   		Parameter("Number_of_Slots_" & sCount)= oExtrusion.Definition.Profile.Count
			Catch
				oUserParams.AddByExpression ("Number_of_Slots_" & sCount, oExtrusion.Definition.Profile.Count, UnitsTypeEnum.kUnitlessUnits)
			End Try
		End If
	End If
Next


For Each oHole As HoleFeature In oDoc.ComponentDefinition.Features.HoleFeatures 
	If oHole.Name.StartsWith("Hole_") Then
		If Feature.IsActive(oHole.Name) Then
		   sCount = Mid(oHole.Name, 6)
		   If sCount.Length = 1 Then
			   sCount = "0" & sCount
		   End If
		   MsgBox("Number_of_Holes_" & sCount & ": " & oHole.HoleCenterPoints.Count)
			Try
		   		Parameter("Number_of_Holes_" & sCount)= oHole.HoleCenterPoints .Count
			Catch
				oUserParams.AddByExpression ("Number_of_Holes_" & sCount, oHole.HoleCenterPoints.Count, UnitsTypeEnum.kUnitlessUnits)
			End Try
		End If
	End If
Next


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 13 of 15

Alex.Shechter
Contributor
Contributor

krieg, thank you very much!

Your code simply works for all the situations that I have.

I don't think that I will reach more than 99 features but if I will, then I can always adjust the "SL" to something else and then have another 99 variations avaliable.

0 Likes
Message 14 of 15

SharkDesign
Mentor
Mentor

Can iLogic tell if the extrude is a cut/join or will it only count extrude in general?

  Inventor Certified Professional
0 Likes
Message 15 of 15

Ralf_Krieg
Advisor
Advisor

Hello

 

iLogic can tell you the kind of operation. Use the ExtrudeDefinition.Operation Property

ExtrudeFeature.Definition.Operation = PartFeatureOperationEnum.kCutOperation
ExtrudeFeature.Definition.Operation = PartFeatureOperationEnum.kIntersectOperation 
ExtrudeFeature.Definition.Operation = PartFeatureOperationEnum.kJoinOperation 
ExtrudeFeature.Definition.Operation = PartFeatureOperationEnum.kNewBodyOperation 
ExtrudeFeature.Definition.Operation = PartFeatureOperationEnum.kSurfaceOperation 

 


R. Krieg
RKW Solutions
www.rkw-solutions.com