Force body renaming (multi-body part)

Force body renaming (multi-body part)

Maxim-CADman77
Advisor Advisor
488 Views
1 Reply
Message 1 of 2

Force body renaming (multi-body part)

Maxim-CADman77
Advisor
Advisor

I'd like to know how to force-rename bodies of multi-body part.

For example: there is a simplest multi-body part with three bodies named in index-style : "1" (Red), "2" (Green) and "3" (Blue).

For some reason I ask user to choose the body which he wants to be The Base body (#1).

Let say user points to Blue or Green body.

My code then try to set name "1" for it but the command mutually fails and name value doesn't change (I believe this happens because body names should be unique and there is already Red body named "1").

I'm looking for the way to smart-"swap" names in the described scenario.

I.e.: If name of the user-chosen body differs from "1" it's name backups to some string variable, then its name temporarily changes to something random (with no chances to match name of any existing bodies which is highly important in context of possible consequent runs of the script), then name of the Red body changes to the name of user-chosen body and finally user-chosen body gets it's brave-New name "1".

This sounds easy-peasy but till now I don't even invent the bullet-prove solution for that temporary random name.

Any ideas?

 

I'm using iLogic and my code for now is:

Dim oIPT As PartDocument = ThisDoc.Document
Dim oPCD As ComponentDefinition = oIPT.ComponentDefinition

Dim oB1 As SurfaceBody=ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Pick which body is the First one")

Dim InitName As String = oB1.Name

Dim NewName As String = InputBox ("Type new name for the selected body :", "New Name of the body", "1")

oB1.Name=NewName

MsgBox ("Initial body's name was - " & InitName & vbCrLF & vbCrLF & "New body's name is - " & oB1.Name,,"Rename result")

 

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Accepted solutions (1)
489 Views
1 Reply
Reply (1)
Message 2 of 2

Maxim-CADman77
Advisor
Advisor
Accepted solution

Nevermind. Did the trick with:

 

 

Dim oIPT As PartDocument = ThisDoc.Document
Dim oPCD As ComponentDefinition = oIPT.ComponentDefinition

Dim oB1 As SurfaceBody=ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Pick which body is the First one")

Dim InitName As String = oB1.Name : Logger.Debug ("InitName - " & InitName)
Dim TempName As String = Now.ToString
TempName=TempName.Replace(":","-") : Logger.Debug ("TempName - " & TempName)
Dim NewName As String = InputBox ("Type new name for the selected body :", "New Name of the body", "1")

If InitName<>NewName
	oB1.Name=TempName
End If

''' Find and rename (to <InitName>) spoiler-body (that one blocking usage of <NewName>)

oPCD.SurfaceBodies(NewName).Name=InitName

oB1.Name=NewName

MsgBox ("Initial body's name was - " & InitName & vbCrLF & vbCrLF & "New body's name is - " & oB1.Name,,"Rename result")

 

 

Please vote for Inventor-Idea Text Search within Option Names

0 Likes