Rename automatically

Rename automatically

이슬이
Enthusiast Enthusiast
1,560 Views
9 Replies
Message 1 of 10

Rename automatically

이슬이
Enthusiast
Enthusiast

If you make a hole when working on a part, the hole 1 will be displayed on the left searcher.
I want to make the name displayed in the searcher automatically change to M3 instead of hole 1 when a size 3 hole is made.
Is it possible?

0 Likes
Accepted solutions (1)
1,561 Views
9 Replies
Replies (9)
Message 2 of 10

_dscholtes_
Advocate
Advocate

Did you know you can show extended information about features in the model tree? It works on all features, not on individual ones (aka holes only). The setting can be found here: Tools > Application Options > Part > Display extended information after feature node name in browser (this is a check box)

0 Likes
Message 3 of 10

이슬이
Enthusiast
Enthusiast

I know how. I want the name to change automatically.
Is there no way?

0 Likes
Message 4 of 10

Anonymous
Not applicable

You can use this to rename holes based on their diameters, but you'll have to run the rule manually. I'm trying to make it automatic though, if I do I will post it here. 

 

You will need some sort of numbered naming system because multiple holes can't have the same name

 

Dim oDoc As PartDocument = ThisDoc.Document

For Each oHole As HoleFeature In oDoc.ComponentDefinition.Features.HoleFeatures
	
	'Divide by 2.54 to convert cm to in
	If oHole.HoleDiameter.Value/2.54 = 3 Then
		
		oHole.Name = "Hole Name Here"
		
	End If
	
Next

 

 

0 Likes
Message 5 of 10

Anonymous
Not applicable

Here's some updated code including a simple numbered naming system

Dim oDoc As PartDocument = ThisDoc.Document
Dim oDef As ComponentDefinition = oDoc.ComponentDefinition
Dim oCount As Integer
Dim oName As String = "Hole Name Here"
Dim oNewHole As HoleFeature = oDef.Features.HoleFeatures.Item(oDef.Features.HoleFeatures.Count)

For Each oHole As HoleFeature In oDoc.ComponentDefinition.Features.HoleFeatures

'Divide by 2.54 to convert cm to in If oHole.Name.Contains(oName) And oHole.HoleDiameter.Value / 2.54 = .25 oCount += 1 End If Next oNewHole.Name = oName & "_" & oCount

It seems the easiest way to make it automatic is to use Inventors built in events.

 

Go to Manage and Event Triggers

Annotation 2020-06-26 103504.png

 

Drag the rule with the hole code under the Part Geometry Change. This will make the rule run anytime part geometry changes which includes creating holes. It's pretty lightweight, so it shouldn't cause any slowdowns if you leave it on, but you can always turn it on/off as needed

 

Annotation 2020-06-26 103717.png

 

0 Likes
Message 6 of 10

이슬이
Enthusiast
Enthusiast

Thank you for answer.

However, in the second coding, the following error occurs.

The parameters are wrong. (Exception occurred HRESULT: 0x80070057 (E_INVALIDARG))

0 Likes
Message 7 of 10

Anonymous
Not applicable

Try this. I added some additional checks to prevent errors.

 

Dim oDoc As PartDocument = ThisDoc.Document
Dim oDef As ComponentDefinition = oDoc.ComponentDefinition
Dim oCount As Integer
Dim oName As String = "Hole Name Here"
Dim oNewHole As HoleFeature
Dim oDiam As Decimal = .25 'Desired diameter in inches

If Not oDef.Features.HoleFeatures.Count = 0 Then
	 oNewHole = oDef.Features.HoleFeatures.Item(oDef.Features.HoleFeatures.Count)
End If

For Each oHole As HoleFeature In oDoc.ComponentDefinition.Features.HoleFeatures

        'Divide by 2.54 to convert cm to in
	If oHole.Name.Contains(oName) And oHole.HoleDiameter.Value / 2.54 = oDiam
			
			oCount += 1
		
	End If
	
Next

If oNewHole IsNot Nothing Then

	If oNewHole.HoleDiameter.Value / 2.54 = oDiam
		
		oNewHole.Name = oName & "_" & oCount
		
	End If

End If
0 Likes
Message 8 of 10

WCrihfield
Mentor
Mentor
Accepted solution

Perhaps something like this would work better for you?

It uses the ExtendedName portion of the feature's name (without the () marks at both ends, then just adds its item index number as an Integer at the end of the name, to ensure the name is unique each time.

Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oHoles As HoleFeatures = oPDef.Features.HoleFeatures
For i As Integer = 1 To oHoles.Count
	oHoles(i).Name = Mid(oHoles(i).ExtendedName,2,Len(oHoles(i).ExtendedName)-2) & " " & i
Next

In case that ExtentedName info isn't what you want, there are also a couple other routes that you may like.  For instance if you check the holes's "IsClearanceHole" Boolean and its "Tapped" Boolean,  and if either is true, you can use one or more of its "ClearanceInfo" properties in the name, or some of the properties under"TapInfo" object (which would need to be defined as a "HoleTapInfo" object, before use) to use in the name.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 10

WCrihfield
Mentor
Mentor

@이슬이 

Here's an example of one possible variation of my other suggestion:

If the hole is a clearance hole, it uses the fastener size in the name of the hole feature.

If the hole is threaded, it uses the nominal size in the name of the hole feature.

If neither of the above checks were true, it does something similar to my first suggestion, but goes one step further to eliminate the trailing info after the hole diameter in the extended name info.

 

Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oHoles As HoleFeatures = oPDef.Features.HoleFeatures
Dim oSimple As Boolean = True
Dim oHCI As HoleClearanceInfo
Dim oHTI As HoleTapInfo
Dim oExtName As String 'Extended Name

For i As Integer = 1 To oHoles.Count
	If oHoles(i).IsClearanceHole Then
		oHCI = oHoles(i).ClearanceInfo
		MsgBox("Fastener Size = " & oHCI.FastenerSize)
		oHoles(i).Name = oHCI.FastenerSize & " :" & i
		oSimple = False
	ElseIf oHoles(i).Tapped Then
		oHTI = oHoles(i).TapInfo
		MsgBox("Nominal Size = " & oHTI.NominalSize)
		oHoles(i).Name = oHTI.NominalSize & " :" & i
		oSimple = False
	End If
	If oSimple = True Then
		oExtName = Mid(oHoles(i).ExtendedName, 2, Len(oHoles(i).ExtendedName) -2)
		oHoles(i).Name = Split(oExtName," ")(0) & " :" & i
	End If
Next

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE" 👍.

Also, when you have time, please review & vote for these 'Ideas' I'd like to get implemented.

  • Add more capabilities to the 'Customize' dialog box (exe. Add Tab & Add Panel) Click Here
  • Constrain & Dimension Images In Assembly Sketches & Drawing Sketches (TitleBlocks & SketchedSymbols) Click Here
  • Save Section View Status In DesignViewRepresentation (So It Can Be Used In The Drawing) Click Here
  • Add SolidBodies Folder In iLogic Rule Editor Model Tab Click Here
  • Convert All Views To Raster Before Autosave Stores To 'OldVersions' Folder Click Here
  • SetDesignViewRepresentation - Fix limitations for DrawingView of a Part Click Here
  • Create DocumentSubTypeEnum Click Here
  • Add kRevisionTag or kDrawingRevisionTag to ObjectTypeEnum Click Here

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 10

이슬이
Enthusiast
Enthusiast

Thank you! Thanks a lot.

I have given you various methods, but this method does not cause an error and shows the desired result.

Thank you very much.

0 Likes