algo
This commit is contained in:
@@ -21,6 +21,10 @@
|
||||
# ***********************************************************************
|
||||
|
||||
import FreeCAD
|
||||
import FreeCADGui
|
||||
from PySide import QtGui, QtCore
|
||||
import datetime
|
||||
import getpass
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
import FreeCADGui, os
|
||||
@@ -43,51 +47,99 @@ except AttributeError:
|
||||
import PVPlantResources
|
||||
from PVPlantResources import DirIcons as DirIcons
|
||||
|
||||
class SafeDict(dict):
|
||||
"""Diccionario seguro para manejar placeholders no definidos"""
|
||||
|
||||
def rename(objects, mask, mode=0):
|
||||
'''
|
||||
mode = 0/1/2/3
|
||||
0: izquierda a derecha - arriba a abajo
|
||||
1: arriba a abajo - izquierda a derecha
|
||||
'''
|
||||
|
||||
# sort:
|
||||
tmp = sorted(objects, key=lambda x: (x.Placement.Base.x,
|
||||
x.Placement.Base.y))
|
||||
|
||||
for idx, obj in tmp:
|
||||
obj.Name = name
|
||||
|
||||
class renamerTaskPanel:
|
||||
def __init__(self, obj=None):
|
||||
self.obj = obj
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------
|
||||
# Module widget form
|
||||
# -------------------------------------------------------------------------------------------------------------
|
||||
self.formRack = FreeCADGui.PySideUic.loadUi(PVPlantResources.__dir__ + "/PVPlantFrame.ui")
|
||||
self.formRack.widgetTracker.setVisible(False)
|
||||
self.formRack.comboFrameType.currentIndexChanged.connect(self.selectionchange)
|
||||
|
||||
self.formPiling = FreeCADGui.PySideUic.loadUi(PVPlantResources.__dir__ + "/PVPlantRackFixedPiling.ui")
|
||||
self.formPiling.editBreadthwaysNumOfPost.valueChanged.connect(self.editBreadthwaysNumOfPostChange)
|
||||
self.formPiling.editAlongNumOfPost.valueChanged.connect(self.editAlongNumOfPostChange)
|
||||
|
||||
self.form = [self.formRack, self.formPiling]
|
||||
|
||||
def accept(self):
|
||||
self.closeForm()
|
||||
return True
|
||||
|
||||
def reject(self):
|
||||
self.closeForm()
|
||||
return False
|
||||
|
||||
def closeForm(self):
|
||||
FreeCADGui.Control.closeDialog()
|
||||
def __missing__(self, key):
|
||||
return f'{{{key}}}'
|
||||
|
||||
|
||||
class _CommandRenamer:
|
||||
class RenameDialog(QtGui.QDialog):
|
||||
def __init__(self):
|
||||
super(RenameDialog, self).__init__()
|
||||
self.setupUI()
|
||||
|
||||
def setupUI(self):
|
||||
self.setWindowTitle("Renombrar objetos con plantilla")
|
||||
self.setMinimumWidth(400)
|
||||
layout = QtGui.QVBoxLayout(self)
|
||||
|
||||
# Campo para la plantilla
|
||||
layout.addWidget(QtGui.QLabel("Plantilla de nombre:"))
|
||||
self.template_input = QtGui.QLineEdit()
|
||||
self.template_input.setPlaceholderText("Ej: {label}_mod_{index:03d}_{date:%Y%m%d}")
|
||||
layout.addWidget(self.template_input)
|
||||
|
||||
# Info de placeholders
|
||||
info = QtGui.QLabel(
|
||||
"Placeholders disponibles:\n"
|
||||
"• {index} - Número en orden\n"
|
||||
"• {label} - Nombre actual del objeto\n"
|
||||
"• {name} - Nombre interno\n"
|
||||
"• {date} - Fecha actual\n"
|
||||
"• {time} - Hora actual\n"
|
||||
"• {user} - Usuario del sistema\n"
|
||||
"• {datetime} - Fecha y hora completa\n"
|
||||
"Formatos: {date:%Y/%m/%d}, {index:03d}, etc."
|
||||
)
|
||||
layout.addWidget(info)
|
||||
|
||||
# Botones
|
||||
btn_box = QtGui.QDialogButtonBox()
|
||||
btn_box.addButton(QtGui.QDialogButtonBox.Apply)
|
||||
btn_box.addButton(QtGui.QDialogButtonBox.Close)
|
||||
btn_box.clicked.connect(self.on_button_click)
|
||||
layout.addWidget(btn_box)
|
||||
|
||||
def on_button_click(self, button):
|
||||
if button == btn_box.button(QtGui.QDialogButtonBox.Apply):
|
||||
self.rename_objects()
|
||||
else:
|
||||
self.close()
|
||||
|
||||
def rename_objects(self):
|
||||
template = self.template_input.text()
|
||||
if not template:
|
||||
QtGui.QMessageBox.warning(self, "Error", "¡La plantilla no puede estar vacía!")
|
||||
return
|
||||
|
||||
selected_objects = FreeCADGui.Selection.getSelection()
|
||||
if not selected_objects:
|
||||
QtGui.QMessageBox.warning(self, "Error", "¡No hay objetos seleccionados!")
|
||||
return
|
||||
|
||||
now = datetime.datetime.now()
|
||||
user_name = getpass.getuser()
|
||||
errors = []
|
||||
|
||||
for idx, obj in enumerate(selected_objects, 1):
|
||||
try:
|
||||
placeholders = SafeDict({
|
||||
'index': idx,
|
||||
'label': obj.Label,
|
||||
'name': obj.Name,
|
||||
'date': now.date(),
|
||||
'time': now.time(),
|
||||
'datetime': now,
|
||||
'user': user_name
|
||||
})
|
||||
|
||||
new_name = template.format_map(placeholders)
|
||||
obj.Label = new_name
|
||||
except Exception as e:
|
||||
errors.append(f"{obj.Name}: {str(e)}")
|
||||
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
if errors:
|
||||
error_msg = "\n".join(errors)
|
||||
QtGui.QMessageBox.critical(self, "Errores", f"Error(es) encontrado(s):\n{error_msg}")
|
||||
else:
|
||||
QtGui.QMessageBox.information(self, "Éxito", "¡Objetos renombrados correctamente!")
|
||||
|
||||
|
||||
|
||||
class CommandRenamer:
|
||||
"the Arch Building command definition"
|
||||
|
||||
def GetResources(self):
|
||||
|
||||
Reference in New Issue
Block a user