fast rename dont work properly

fast rename dont work properly

nubrandao
Collaborator Collaborator
3,670 Views
44 Replies
Message 1 of 45

fast rename dont work properly

nubrandao
Collaborator
Collaborator
# Script zum schnellen umbennen von CAM Operationen
# Bei Rückfragen bitte an M.Toepke wenden
# Marcus.Toepke@gabler-naval.com

import adsk.core, adsk.fusion, adsk.cam, traceback
import re
import sys

# Get the application and userInterface
app = adsk.core.Application.get()
ui = app.userInterface
ui_var = app.userInterface

# Get the value of the property.
propertyValue = ui.commandDefinitions

# Get the active product.
cam = adsk.cam.CAM.cast(app.activeProduct)

# Check if anything was returned.
if (cam is None😞
    ui.messageBox('Você deve estar na área de trabalho Concluído (CAM)!')
   
# Get the Setups collection object from the CAM object.
setups = cam.setups

# Get the first Setup object in the CAM product.
setup = setups.item(0)

# Get the Operations collection object that contains all the operations in the setup.
operations = setup.operations

# Get the first operation in the collection.
operation = operations.item(0)

# Get selected Operations
selections = ui.activeSelections
try:
    # print(f'Es sind {selections.count} Operationen ausgewählt!')
    a_selections = selections.asArray()
    if selections.count == 0:
        ui.messageBox('Nenhuma seleção de operação foi feita')
        adsk.terminate()
    if selections.count >= 1:
        # Abfrage Operations Bezeichnungen
        vorgabe = a_selections[0].entity.name
        user_input = ui_var.inputBox("Nome básico da operação", "Qual deve ser o nome básico das operações?", vorgabe)
        if user_input[1]:
            ui.messageBox('Eingabe wurde abgebrochen')
            adsk.terminate()

        if '~' not in user_input[0]:
            number = 1
            for sel_op in a_selections:
                sel_op.entity.name = f'{user_input[0]}_{number}'
                number += 1
               
        if '~(' in user_input[0]:
            # Input Auseinandernehmen und in Liste umformen
            input_list = re.search(r'~(.*)$', user_input[0])
            input_list = input_list[0]
            input_list = input_list.replace('~', '').replace('(', '').replace(')', '')
            input_list = input_list.split(',')
           
            # Zusatzargumente aus user_input entfernen
            extract = re.search(f"(.*?){re.escape('~')}", user_input[0])
            user_input = extract[0]
            user_input = user_input.replace('~', '')
           
            if len(a_selections) == len(input_list):
                count = 0
                for sel_op in a_selections:
                    sel_op.entity.name = f'{user_input}_{input_list[count]}'
                    count += 0
            else:
                ui.messageBox('A lista que você forneceu não corresponde ao número de operações selecionadas! O script terminará agora')
        if '~' in user_input[0]:
            # Input Auseinandernehmen und in Liste umformen
            input_list = re.search(r'~.*$', user_input[0])
            input_list = input_list[0]
            input_list = input_list.replace('~', '')
            input_list = input_list.split(',')
           
            # Zusatzargumente aus user_input entfernen
            extract = re.search(f"(.*?){re.escape('~')}", user_input[0])
            user_input = extract[0]
            user_input = user_input.replace('~', '')
           
            count = 0
            new_number = float(input_list[0])
            add_number = float(input_list[1])
            for sel_op in a_selections:
                if count == 0:
                    sel_op.entity.name = f'{user_input}_{new_number}'
                if count > 0:
                    new_number += add_number
                    sel_op.entity.name = f'{user_input}_{new_number}'
               
                count += 1
               
           
           
except Exception as err:
    if selections.count < 1:
        # error_message = f'Es wurde keine Auswahl getroffen!\nEs wurden {selections.count} operationen ausgewählt'
        ui.messageBox(err)
    if ui:
      ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
   
     

     
   i have copied this script, but there is a problem, 
 
rename everthing but when renumbering, it jumps numbers
 
por example, i input  "MOULD"
 
it appears
 
mould_01
mould_06
mould_02
mould_04
mould_07
mould_03
mould_05
0 Likes
Accepted solutions (4)
3,671 Views
44 Replies
Replies (44)
Message 41 of 45

kandennti
Mentor
Mentor

Hi @nubrandao -San.

 

I tried it and was able to rename the operations in the folder as well.

1.png

 

If you attach the f3d file that cannot be renamed, I will try it here.

0 Likes
Message 42 of 45

nubrandao
Collaborator
Collaborator

Can you post the last script you using? Maybe mine is outdated 

0 Likes
Message 44 of 45

nubrandao
Collaborator
Collaborator

The script I was talking about is the rename operation and not drilling rename 

 

When I have multiple folders, it won't work 

 

I usually have 1 setup, 2 folder (2 component), inside each component, I have 3 folder, "rough" "finish" "2d drilling"

 

Usually I move all operations to the first folder or setup and and renamed ok, then put again inside de the folder

0 Likes
Message 45 of 45

kandennti
Mentor
Mentor

@nubrandao -San.

 

Can you provide some simple data that you can't process well?

0 Likes