Multi bodies - auto rename.

Multi bodies - auto rename.

Anonymous
Not applicable
8,053 Views
36 Replies
Message 1 of 37

Multi bodies - auto rename.

Anonymous
Not applicable

Hello everybody,

 

I have small problem. I have lot of bodies (50) with name solid1.... solid50.

How can I quickly rename all bodies according some template for example "Plate_01... Plate_50"?

It is possible to use ilogic? or maybe will be better to use vba.

 

Somebody have idea??

 

Thank you for helps,

TJ

Accepted solutions (1)
8,054 Views
36 Replies
Replies (36)
Message 21 of 37

GosponZ
Collaborator
Collaborator

22Deriver IS WRONG

 

 

Copy and paste this rule. Hit run rule.

'If forgot something click no and rule will not run

 

response = MessageBox.Show("Are you sure?", "Reminder",MessageBoxButtons.YesNo)

 

Ifresponse = vbNo ThenExit Sub

 

myparam = InputBox(     "/", "Replace In Solid Name", "OLD/NEW")

 

If (myparam <> "")Then

      myparams = myparam.Split("/")

      replaceString = myparams(0)

      withString = myparams(1)

 

      ForEachsolidInThisDoc.Document.ComponentDefinition.SurfaceBodies

            name = solid.Name

            name = name.Replace(replaceString, withString)

            solid.Name = name

     Next

End If

 

'Folow what is on screen

 

rename solid bodies.JPG

0 Likes
Message 22 of 37

xenocatalyst
Advocate
Advocate

I am using the iLogic that Barbara Han wrote some time back. found here.

 

Please note that I do not have vba functionality on my installation of inventor 2015, and i dont have the system rights to rectify this.

 

Is there a way to add the ability to specify the starting number of the sequence?

 

     ie: the code currently prompts for a prefix, i'll use "partno-" and it rename the solid bodies from

 

     Solid1, Solid2, Solid3,...to partno-1, partno-2, partno-3,...

 

Can we get it to start at number 5 for instance,

 

     ie: Solid1, Solid2, Solid3,...to partno-5, partno-6, partno-7,...

 

 

 

Another useful function would be to specifiy a 0 padding if possible. so we can specify how many leading 0's there are.

 

     ie: a 0 padding of 3 results in renaming Solid1, Solid2, Solid3,...to partno-005, partno-006, partno-007,...

 

 

 

0 Likes
Message 23 of 37

bruce.blundell
Participant
Participant

I agree this would be super handy, I have managed to get the got to work with visible items ( See below)

But it would be incredibly handy to get the re-number to work if you already have a set of numbers or if you wanted to start from a set number.

 

SyntaxEditor Code Snippet

'check for custom iProperty and add it if not found
Dim prefix As String = "Prefix"
customPropertySet = ThisDoc.Document.PropertySets.Item _
("Inventor User Defined Properties")

Try
         prop= customPropertySet.Item(prefix)
Catch
      ' Assume error means not found
            customPropertySet.Add("", prefix)
End Try

'write the part number to the Prefix iProperty if it is empty
If iProperties.Value("Custom", "Prefix") = "" Then
iProperties.Value("Custom", "Prefix") = iProperties.Value("Project", "Part Number") & "_"
Else
End If

'check that this active document is a part file   
Dim partDoc As PartDocument
If ThisApplication.ActiveDocument.DocumentType <> kPartDocumentObject Then
MessageBox.Show ("Please open a part document", "iLogic")
End If

'define the active document
partDoc = ThisApplication.ActiveDocument
Dim solid As SurfaceBody
Dim i As Integer

'get input from user
prefix = InputBox("Enter a prefix for the solid body names", "iLogic", iProperties.Value("Custom", "Prefix"))

'write input back to custom iProperty
iProperties.Value("Custom", "Prefix") = prefix
i = 1
'rename all solid bodies incrementing suffix
For Each solid In partDoc.ComponentDefinition.SurfaceBodies
    If solid.Visible = True
		solid.Name = prefix + IIf (i < 10, "0" + CStr(i), CStr(i))
		i = i + 1
    End If
    
Next
0 Likes
Message 24 of 37

aurel_e
Collaborator
Collaborator

Hi all,

in the case of an ipt derived from an assembly using shrinkwrap command:

Is there any chance to rename the bodies based on the original part name?

In my case the Solid2 will be renamed "Spacer-1", the Solid6->"Base block-1", Solid7->"Spacer-2"....

 

2020-04-28 11_02_19-Window.png

0 Likes
Message 25 of 37

aurel_e
Collaborator
Collaborator

Any idea? Is it impossible?

 

0 Likes
Message 26 of 37

adam.nagy
Autodesk Support
Autodesk Support

One of the best ways to investigate the API is to select the relevant object in the UI and check its properties in VBA:
https://adndevblog.typepad.com/manufacturing/2013/10/discover-object-model.html

 

In this case you'll see you have access to the SurfaceBody objects and can change their Name parameter:

Sub RenameSurfaceBodies()
  Dim pd As PartDocument
  Set pd = ThisApplication.ActiveDocument
  
  Dim pcd As PartComponentDefinition
  Set pcd = pd.ComponentDefinition
  
  Dim sb As SurfaceBody
  For Each sb In pcd.SurfaceBodies
    sb.name = sb.name + "_changed"
  Next
End Sub

 



Adam Nagy
Autodesk Platform Services
0 Likes
Message 27 of 37

Biju.Veedu
Contributor
Contributor

Hi all, anyone could help me with the ilogic codes for below?

I want to rename my solids in a multibody part file to be same as parent sketch block name used to create each body. 

0 Likes
Message 28 of 37

GosponZ
Collaborator
Collaborator

I'm using this one for years and works perfect. If you have lot solid bodies with this one change in second all of them.

 
'check for custom iProperty and add it if not found
Dim prefix As String = "Prefix"
customPropertySet = ThisDoc.Document.PropertySets.Item _
("Inventor User Defined Properties")


Try
         prop= customPropertySet.Item(prefix)
Catch
       'Assume Error means Not found
            customPropertySet.Add("", prefix)
End Try


'write the part number to the Prefix iProperty if it is empty
If iProperties.Value("Custom", "Prefix") = "" Then
iProperties.Value("Custom", "Prefix") = iProperties.Value("Project", "Part Number") & "_"
Else 
End If


'check that this active document is a part file    
Dim partDoc As PartDocument
If ThisApplication.ActiveDocument.DocumentType <> kPartDocumentObject Then
MessageBox.Show ("Please open a part document", "iLogic")
End If


'define the active document
partDoc = ThisApplication.ActiveDocument
Dim solid As SurfaceBody
Dim i As Integer


'get input from user
prefix = InputBox("Enter a prefix for the solid body names", "iLogic", iProperties.Value("Custom", "Prefix"))


'write input back to custom iProperty 
iProperties.Value("Custom", "Prefix") = prefix
i = 1
'Rename all solid bodies incrementing suffix
For Each solid In partDoc.ComponentDefinition.SurfaceBodies
solid.Name = prefix + Iif(i < 10, "0" + CStr(i), CStr(i))
i = i + 1
Next
Message 29 of 37

Biju.Veedu
Contributor
Contributor

appreciated your reply.

is there a way to rename the solid same as the sketch block that used to create that solid?

 

0 Likes
Message 30 of 37

adam.nagy
Autodesk Support
Autodesk Support

You would need to investigate the API object model to see how to drill down from the solid to the sketch block that was used to create it (e.g. via an Extrude feature)

https://adndevblog.typepad.com/manufacturing/2013/10/discover-object-model.html 



Adam Nagy
Autodesk Platform Services
0 Likes
Message 31 of 37

ganesh_omkaar
Contributor
Contributor
Can you your code here
Thanks in advance
0 Likes
Message 32 of 37

Biju.Veedu
Contributor
Contributor

Hi

Is here any ilogic to rename all solidbodies with a prefix on it? need want retain existing "body name" and want to add prefix to it.

for Example

" xxxxx_Solidbody 01"

" xxxxx_Solidbody 02"

" xxxxx_Solidbody 03"

 

 

0 Likes
Message 33 of 37

aronmatheus
Advocate
Advocate

Hi @Curtis_Waguespack Is there any way to link rename the bodies with link the name used the parameter ruler?  

 

2021-06-28 10_00_21-Edit Rule_ Rule0.png

0 Likes
Message 34 of 37

Curtis_Waguespack
Consultant
Consultant

Hi @aronmatheus 

 

It's unclear what you are asking. You might create a new thread and further explain what you are attempting to do in more detail.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 35 of 37

aronmatheus
Advocate
Advocate

@Curtis_Waguespack  I want to rename the multibody without to lost the link with the name I put the ruler. I'm using this ruler to rename the bodies with part number although I lost the link to the parameter I logic. I make a video to show this missed.

Sub Main()

'Counts for the number of components in an assembly
Dim counter As Integer = 0
Dim InstNum As String

'Grab the Assembly Document
Dim oDoc As AssemblyDocument
oDoc = ThisDoc.Document

Dim ThisPath As String = oDoc.FullFileName

'Grab the Active Assembly Component Definition
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

' Get the model browser
Dim oPane As BrowserPane
oPane = oDoc.BrowserPanes.Item("Model")

Dim AssySubtype As String
AssySubtype = "Assembly"


' Grab the occurrence of the object
Dim oOcc As ComponentOccurrence
For Each oOcc In oDoc.ComponentDefinition.Occurrences


InstNum=":" & counter

'Grab Document from Occurrence
Dim oOccDoc As Document
oOccDoc = oOcc.Definition.Document


'get design properties set'
Dim invDesignInfo As PropertySet
invDesignInfo = oOccDoc.PropertySets.Item("Design Tracking Properties")

' Get the part number property.
Dim invPartNumberProperty As Inventor.Property
invPartNumberProperty = invDesignInfo.Item("Description")

'Get reference information for the path for the purpose of checking for whether the component is a standard Content Center part
Dim PathProperty As String = "ReferencePath"
Dim oPath As String = oOccDoc.FullFileName

'Create a property that can be referenced later for the purpose of maintaining links in other iLogic commands
Dim customPropSet As PropertySet
customPropSet = oOccDoc.PropertySets.Item("Inventor User Defined Properties")
Dim PropertyName As String = "ReferenceBrowserName"

Dim NodeName() As String
NodeName=oOcc.Name.Split( {":"c},StringSplitOptions.None)
'InstNum=":" & NodeName(1)

'Checks to see if the component is a standard content center part
If InStr(oPath,"Content Center Files") = 0 Then

'Checks to see if the component is actually the parent level assembly. This is necessary when the active assembly is a weldment
If InStr(oPath, ThisPath) = 0 Then

'Test to see if the property, "ReferencePath" has already been created
Try
custompath = customPropSet.Item(PathProperty)
'If it hasn't been created, do so
Catch
customPropSet.Add(oPath, PathProperty)
End Try

' Get the browser node that corresponds to the new item
Dim oSubAssyNode As BrowserNode
oSubAssyNode = oPane.GetBrowserNodeFromObject(oOcc)

'Take the current name of the component and separate it from the ":XX" instance number
Dim CurrentNode() As String
CurrentNode=oOcc.Name.Split( {":"c},StringSplitOptions.None)

'Determine whether the browser node should be renamed
If String.Compare(CurrentNode(0),(invPartNumberProperty.Value), True) = 0 Then

'If everything is consistent, then do nothing

Else

Try
prop = customPropSet.Item(PropertyName)
Catch
customPropSet.Add(NodeName(0), PropertyName)
End Try

'Set The name
oSubAssyNode.NativeObject.Name = (invPartNumberProperty.Value) & InstNum

End If
Else
End If

Else
End If

'advance the instance number by 1
counter = counter + 1

Next

End Sub

0 Likes
Message 36 of 37

GosponZ
Collaborator
Collaborator
'REPLACE OLD NUMBER / NEW NUMBER OR WHATEVER YOU WANT TO REPLACE

response
= MessageBox.Show("Are you sure?", "Reminder",MessageBoxButtons.YesNo) If response = vbNo Then Exit Sub myparam = InputBox( "/", "Replace In Solid Name", "OLD/NEW") If (myparam <> "") Then myparams = myparam.Split("/") replaceString = myparams(0) withString = myparams(1) For Each solid In ThisDoc.Document.ComponentDefinition.SurfaceBodies name = solid.Name name = name.Replace(replaceString, withString) solid.Name = name Next End If
0 Likes
Message 37 of 37

Curtis_Waguespack
Consultant
Consultant

Hi @aronmatheus 

 

it seems that your issue might not be related to the solid body name, but instead this is about the name of the occurrence in the browser... 

 

I suggested that you create your own, new thread/topic on this forum, rather than adding messages to existing one, because it if you've added to an existing topic that is not the exact same issue, it can make it difficult to get replies that are accurate to the question you are trying to answer.

 

From the video, it appears your issue is related to the browser node names and not solid body names... if that is the case, please see the information at this link to understand the issue better:

Inventor 2014 - iLogic – Stabilise Browser Nodes in Assembly – Cadline Community

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes