Message 1 of 45
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
# 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
Solved! Go to Solution.