Macro ArrayCopy/sv

Rutnätskopiering
Detta makro kopierar det valda objektet flera gånger på ett rutnät. Du kan definiera antalet rader, kolumner och avståndet mellan dem. Du behöver ha pyqt installerat.

import FreeCAD, FreeCADGui, Part from PyQt4 import QtGui,QtCore def proceed: try: u = (int(l1.text),float(l2.text)) v = (int(l3.text),float(l4.text)) except: FreeCAD.Console.PrintError("Fel inmatning! Endast siffror är tillåtna...\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 newshape.translate(delta) newobject = FreeCAD.ActiveDocument.addObject("Part::Feature",name) newobject.Shape = newshape else: FreeCAD.Console.PrintError("Fel: Ett objekt måste väljas") hide def hide: dialog.hide dialog = QtGui.QDialog dialog.resize(200,300) dialog.setWindowTitle("Array") la = QtGui.QVBoxLayout(dialog) t1 = QtGui.QLabel("Antal kolumner") la.addWidget(t1) l1 = QtGui.QLineEdit la.addWidget(l1) t2 = QtGui.QLabel("Avstånd mellan kolumner") la.addWidget(t2) l2 = QtGui.QLineEdit la.addWidget(l2) t3 = QtGui.QLabel("Antal rader") la.addWidget(t3) l3 = QtGui.QLineEdit la.addWidget(l3) t4 = QtGui.QLabel("Avstånd mellan rader") la.addWidget(t4) l4 = QtGui.QLineEdit la.addWidget(l4) okbox = QtGui.QDialogButtonBox(dialog) okbox.setOrientation(QtCore.Qt.Horizontal) okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok) la.addWidget(okbox) QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted"), proceed) QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected"), hide) QtCore.QMetaObject.connectSlotsByName(dialog) dialog.show