Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
WCrihfield
in reply to: ldellaversano

Hi @ldellaversano.  Here is a modified version of your code that I just created for you, but have not tested yet.  It looked to me like the problem you were likely encountering is that the code was trying to name another feature exactly the same as an already existing feature, which I don't think Inventor allows in the same document.  It is very easy to do, so it is difficult to avoid with a rule like this.  And I still can not guarantee that you will not encounter the same issue while using this version, but this version is a bit shorter and easier to look at.

Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument
Dim oFeatures As Object = oDoc.ComponentDefinition.Features
'must be different counter for each different type of feature
Dim iExt As Integer = 1
Dim iRev As Integer = 1
Dim iFill As Integer = 1
Dim iCham As Integer = 1
Dim iFeat As Integer = 1

For Each oFeature As PartFeature In oFeatures
	Select Case oFeature.Type
	Case ObjectTypeEnum.kExtrudeFeatureObject
		Try
			oFeature.Name = oFeature.SurfaceBodies(1).Name & "_Es" & If (iExt < 10, "0" + CStr(iExt), CStr(iExt))
		Catch
		End Try
		iExt = iExt + 1
	Case ObjectTypeEnum.kRevolveFeatureObject
		Try
			oFeature.Name = oFeature.SurfaceBodies(1).Name & "_Riv" & If (iRev < 10, "0" + CStr(iRev), CStr(iRev))
		Catch
		End Try
		iRev = iRev + 1
	Case ObjectTypeEnum.kFilletFeatureObject
		Try
			oFeature.Name = oFeature.SurfaceBodies(1).Name & "_Racc" & If (iFill < 10, "0" + CStr(iFill), CStr(iFill))
		Catch
		End Try
		iFill = iFill + 1
	Case ObjectTypeEnum.kChamferFeatureObject
		Try
			oFeature.Name = oFeature.SurfaceBodies(1).Name & "_Sm" & If (iCham < 10, "0" + CStr(iCham), CStr(iCham))
		Catch
		End Try
		iCham = iCham + 1
	Case ObjectTypeEnum.kiFeatureObject
		'an iFeature can contain multiple other types of features
		'Dim oIFeature As Inventor.iFeature = oFeature
		'Dim oIFeatDef As iFeatureDefinition = oIFeature.iFeatureDefinition
		Try
			oFeature.Name = oFeature.SurfaceBodies(1).Name & "_Other" & If (iFeat < 10, "0" + CStr(iFeat), CStr(iFeat))
		Catch
		End Try
		iFeat = iFeat + 1
	End Select
Next

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)