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
Solved! Go to Solution.
Solved by Sergio.D.Suárez. Go to Solution.
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!
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
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
(Not an Autodesk Employee)
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
(Not an Autodesk Employee)
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")
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
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.