Macro ArrayCopy/it: Difference between revisions

From FreeCAD Documentation
(Created page with "{{Macro/it|Icon=Text-x-python|Name=ArrayCopy|Name/it=ArrayCopy|Description=Esta macro copia el objeto seleccionado varias veces, a lo largo de una matriz rectangular|Author=Yo...")
(Updating to match new version of source page)
 
(22 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
{{Macro/it|Icon=Text-x-python|Name=ArrayCopy|Name/it=ArrayCopy|Description=Esta macro copia el objeto seleccionado varias veces, a lo largo de una matriz rectangular|Author=Yorik}}
{{Macro/it
|Name=ArrayCopy
|Icon=Macro_ArrayCopy.png
|Translate=Serie di copie
|Description=Questa macro copia più volte gli oggetti selezionati in una griglia (matrice) rettangolare
|Author=Yorik
|Version=1.0
|Date=2014-05-04
|FCVersion=All
|Download=[https://www.freecadweb.org/wiki/images/9/9d/Macro_ArrayCopy.png ToolBar Icon]
}}


==Descrizione==
This macro copies the selected object several times, on an array grid. You can define the number of rows and columns and the distance between them. You need [http://en.wikipedia.org/wiki/PyQt pyqt] installed.
Questa macro copia più volte gli oggetti selezionati in una griglia (matrice). È possibile definire il numero di righe e di colonne e la loro distanza.


==Script==
ToolBar Icon [[Image:Macro_ArrayCopy.png]]


'''Macro_ArrayCopy.FCMacro'''
<syntaxhighlight>

import FreeCAD, FreeCADGui, Part
{{MacroCode|code=
from PyQt4 import QtGui,QtCore

import FreeCAD, FreeCADGui, Part
from PySide import QtGui,QtCore
def proceed():
def proceed():
try:
try:
u = (int(l1.text()),float(l2.text()))
u = (int(l1.text()),float(l2.text()))
v = (int(l3.text()),float(l4.text()))
v = (int(l3.text()),float(l4.text()))
except:
except:
FreeCAD.Console.PrintError("Wrong input! Only numbers allowed...\n")
FreeCAD.Console.PrintError("Wrong input! Only numbers allowed...\n")
sel = FreeCADGui.Selection.getSelection()
sel = FreeCADGui.Selection.getSelection()
if sel:
if sel:
sel = sel[0]
sel = sel[0]
name = sel.Name
name = sel.Name
shape = sel.Shape
shape = sel.Shape
for column in range(u[0]):
for column in range(u[0]):
for row in range(v[0]):
for row in range(v[0]):
if (column != 0) or (row != 0):
if (column != 0) or (row != 0):
delta = FreeCAD.Vector(column*u[1],row*v[1],0)
delta = FreeCAD.Vector(column*u[1],row*v[1],0)
newshape = sel.Shape.copy()
newshape = sel.Shape.copy()
newshape.translate(delta)
newshape.translate(delta)
newobject = FreeCAD.ActiveDocument.addObject("Part::Feature",name)
newobject = FreeCAD.ActiveDocument.addObject("Part::Feature",name)
newobject.Shape = newshape
newobject.Shape = newshape
else:
else:
FreeCAD.Console.PrintError("Error: One object must be selected")
FreeCAD.Console.PrintError("Error: One object must be selected")
hide()
hide()
def hide():
def hide():
dialog.hide()
dialog.hide()
dialog = QtGui.QDialog()
dialog = QtGui.QDialog()
dialog.resize(200,300)
dialog.resize(200,300)
dialog.setWindowTitle("Array")
dialog.setWindowTitle("Array")
la = QtGui.QVBoxLayout(dialog)
la = QtGui.QVBoxLayout(dialog)
t1 = QtGui.QLabel("number of columns")
t1 = QtGui.QLabel("number of columns")
la.addWidget(t1)
la.addWidget(t1)
l1 = QtGui.QLineEdit()
l1 = QtGui.QLineEdit()
la.addWidget(l1)
la.addWidget(l1)
t2 = QtGui.QLabel("distance between columns")
t2 = QtGui.QLabel("distance between columns")
la.addWidget(t2)
la.addWidget(t2)
l2 = QtGui.QLineEdit()
l2 = QtGui.QLineEdit()
la.addWidget(l2)
la.addWidget(l2)
t3 = QtGui.QLabel("number of rows")
t3 = QtGui.QLabel("number of rows")
la.addWidget(t3)
la.addWidget(t3)
l3 = QtGui.QLineEdit()
l3 = QtGui.QLineEdit()
la.addWidget(l3)
la.addWidget(l3)
t4 = QtGui.QLabel("distance between rows")
t4 = QtGui.QLabel("distance between rows")
la.addWidget(t4)
la.addWidget(t4)
l4 = QtGui.QLineEdit()
l4 = QtGui.QLineEdit()
la.addWidget(l4)
la.addWidget(l4)
okbox = QtGui.QDialogButtonBox(dialog)
okbox = QtGui.QDialogButtonBox(dialog)
okbox.setOrientation(QtCore.Qt.Horizontal)
okbox.setOrientation(QtCore.Qt.Horizontal)
okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
la.addWidget(okbox)
la.addWidget(okbox)
QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), proceed)
QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), proceed)
QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), hide)
QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), hide)
QtCore.QMetaObject.connectSlotsByName(dialog)
QtCore.QMetaObject.connectSlotsByName(dialog)
dialog.show()
dialog.show()


}}
</syntaxhighlight>
<languages/>

Latest revision as of 09:44, 23 May 2020

Serie di copie

Descrizione
Questa macro copia più volte gli oggetti selezionati in una griglia (matrice) rettangolare

Versione macro: 1.0
Ultima modifica: 2014-05-04
Versione FreeCAD: All
Download: ToolBar Icon
Autore: Yorik
Autore
Yorik
Download
ToolBar Icon
Link
Versione macro
1.0
Data ultima modifica
2014-05-04
Versioni di FreeCAD
All
Scorciatoia
Nessuna
Vedere anche
Nessuno

Descrizione

Questa macro copia più volte gli oggetti selezionati in una griglia (matrice). È possibile definire il numero di righe e di colonne e la loro distanza.

Script

ToolBar Icon

Macro_ArrayCopy.FCMacro

import FreeCAD, FreeCADGui, Part
from PySide import QtGui,QtCore
 
def proceed():
    try:
        u = (int(l1.text()),float(l2.text()))   
        v = (int(l3.text()),float(l4.text()))
    except:
        FreeCAD.Console.PrintError("Wrong input! Only numbers allowed...\n")
    sel = FreeCADGui.Selection.getSelection()
    if sel:
        sel = sel[0]
        name = sel.Name   
        shape = sel.Shape
        for column in range(u[0]):
            for row in range(v[0]):
                if (column != 0) or (row != 0):
                    delta = FreeCAD.Vector(column*u[1],row*v[1],0)   
                    newshape = sel.Shape.copy()
                    newshape.translate(delta)
                    newobject = FreeCAD.ActiveDocument.addObject("Part::Feature",name)
                    newobject.Shape = newshape
    else:
        FreeCAD.Console.PrintError("Error: One object must be selected")
    hide()
 
def hide():
    dialog.hide()
 
dialog = QtGui.QDialog()
dialog.resize(200,300)
dialog.setWindowTitle("Array")
la = QtGui.QVBoxLayout(dialog)
t1 = QtGui.QLabel("number of columns")
la.addWidget(t1)
l1 = QtGui.QLineEdit()
la.addWidget(l1)
t2 = QtGui.QLabel("distance between columns")
la.addWidget(t2)
l2 = QtGui.QLineEdit()
la.addWidget(l2)
t3 = QtGui.QLabel("number of rows")
la.addWidget(t3)
l3 = QtGui.QLineEdit()
la.addWidget(l3)
t4 = QtGui.QLabel("distance between rows")   
la.addWidget(t4)
l4 = QtGui.QLineEdit()
la.addWidget(l4)
okbox = QtGui.QDialogButtonBox(dialog)
okbox.setOrientation(QtCore.Qt.Horizontal)
okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel