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: 

Count number of iFeature instances within .ipt file using iLogic

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
jamieking89
618 Views, 6 Replies

Count number of iFeature instances within .ipt file using iLogic

I am wondering what the code would be to count all instances certain ifeatures which have different names within an .ipt file using iLogic.

 

For example run a rule that will display how many ifeatures called "PLUG1" are used in the model and also display how many iFeatures called "PLUG2" are used.

 

PLUG1 = 0

Scan browser if PLUG1 is found + 1

Total the count once a sweep of the feature tree has complete.

 

Thank in advance

6 REPLIES 6
Message 2 of 7

Hi, I think you could achieve what you need by executing a rule like the following in your part file.

Dim doc As PartDocument= ThisDoc.Document
Dim oCD As PartComponentDefinition = doc.ComponentDefinition

Dim myparam As String = InputBox("Search and count the existing ifeatures in the model", "Count Ifeatures", "PLUG1")
If myparam Is "" Then Exit Sub

Dim i As Integer = 0
For Each iFeat As Inventor.iFeature In oCD.Features.iFeatures
	If InStr(iFeat.Name, myparam) <> 0 Then i = i + 1
Next

MessageBox.Show("There are " & i & " ifeatures of type " & plug1 & " in the model")

 I hope this helps with your work. Grettings!


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 3 of 7
WCrihfield
in reply to: jamieking89

Try this.

Dim oDoc As PartDocument = ThisDoc.Document
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oiFeats As iFeatures = oDef.Features.iFeatures
'MessageBox.Show("There are currently " & oiFeats.Count & " iFeatures in this part.")
i = 1
Dim oPLUG1 As Integer = 0
Dim oPLUG2 As Integer = 0
For I = 1 To oiFeats.Count
	If oiFeats.Item(i).Name = "PLUG1" Then
		oPLUG1 = oPLUG1 + 1
	ElseIf oiFeats.Item(i).Name = "PLUG2" Then
		oPLUG1 = oPLUG2 + 1
	End If
Next

MessageBox.Show("There are currently " & oPLUG1 & " iFeatures named 'PLUG1' in this part." & vbNewLine &
"There are currently " & oPLUG1 & " iFeatures named 'PLUG1' in

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 7
WCrihfield
in reply to: WCrihfield

Correction.

Dim oDoc As PartDocument = ThisDoc.Document
Dim oDef As PartComponentDefinition = oDoc.ComponentDefinition
Dim oiFeats As iFeatures = oDef.Features.iFeatures
i = 1
Dim oPLUG1 As Integer = 0
Dim oPLUG2 As Integer = 0
For i = 1 To oiFeats.Count
	If oiFeats.Item(i).Name = "PLUG1" Then
		oPLUG1 = oPLUG1 + 1
	ElseIf oiFeats.Item(i).Name = "PLUG2" Then
		oPLUG1 = oPLUG2 + 1
	End If
	i = i + 1
Next
MessageBox.Show("There are currently " & oPLUG1 & " iFeatures named 'PLUG1' in this part." & vbNewLine &
"There are currently " & oPLUG1 & " iFeatures named 'PLUG1' in this part.")

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 7

There was an error at the end of the code that happened at the beginning, here is the correction for any specified string. Grettings!

 

Dim doc As PartDocument= ThisDoc.Document
Dim oCD As PartComponentDefinition = doc.ComponentDefinition

Dim myparam As String = InputBox("Search and count the existing ifeatures in the model", "Count Ifeatures", "PLUG1")
If myparam Is "" Then Exit Sub

Dim i As Integer = 0
For Each iFeat As Inventor.iFeature In oCD.Features.iFeatures
	If InStr(iFeat.Name, myparam) <> 0 Then i = i + 1
Next

MessageBox.Show("There are " & i & " ifeatures of type " & myparam & " in the model")

 


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

Message 6 of 7

That works perfectly!

 

Thank you very much! 😁

Message 7 of 7

Sergio

 

As an addition to this rule. Is there anyway that a drop down listing the iFeatures used within the model can be added? Or a way to generate an output that would list each iFeature by name and its quantity in an output box?

 

If not the solution you have provided me will be good enough.

 

Thanks again

 

Jamie

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

Post to forums  

Autodesk Design & Make Report