Macro Half turn stairs/it

Descrizione
Questa macro crea una scala mezzo giro con i dati del file stairs.dat e con svolta a sinistra o a destra.



Uso

 * Avviare la macro e modificare l'altezza della scala. La svolta può essere a sinistra o a destra.

Script
Half_turn_stairs.FCMacro


 * 1) -*- coding: utf-8 -*-
 * 2) Half_turn_stairs Macro runs with Freecad 0.17
 * 3) Author: Berner and Forum
 * 4) This macro creates a half turn stair from tupels of x,y,z
 * 5) the tupels used to create a dwire for every stair.
 * 6) The dwire is extruded, so it give with 18 stairs the total rise
 * 7) A sample file with parameters is in stairs.dat
 * 8) created a wire with coordinate x y z separated (in the file)
 * 9) Sample: (delete # on lines without comments)
 * 10) Stair 0
 * 11) 0.0 -240.0 0.0 0.0 0.0 0.0 1000.0 0.0 0.0 1000.0 -240.0 0.0
 * 12) Stair 1
 * 13) 0.0 0.0 0.0 0.0 240.0 0.0 1000.0 240.0 0.0 1000.0 0.0 0.0
 * 1) Sample: (delete # on lines without comments)
 * 2) Stair 0
 * 3) 0.0 -240.0 0.0 0.0 0.0 0.0 1000.0 0.0 0.0 1000.0 -240.0 0.0
 * 4) Stair 1
 * 5) 0.0 0.0 0.0 0.0 240.0 0.0 1000.0 240.0 0.0 1000.0 0.0 0.0

from __future__ import unicode_literals from FreeCAD import Base import Draft, Part

App.Console.PrintMessage("Half_turn_stairs-Macro\n") p=FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro") path = p.GetString("MacroPath") dataset = path + "/stairs.dat"                         # path and name of file.txt docname = App.ActiveDocument.Name                      # Name of active document debug='n' # Debug Values on Console rise = 3100.0 # Geschosshoehe Total Rise
 * 1) Get location of user macros

left_right="l" # turn stairs left or left_right
 * 1) GUI

from PySide import QtGui (rise, ok) = QtGui.QInputDialog.getDouble(		QtGui.QWidget, 'Total Rise / Geschosshoehe', 'Total Rise / Geschosshoehe', 2000, 0, 3100, 4) if ok: left_right = QtGui.QInputDialog.getText(None, "left_right", "Turn Left or Right l/r")[0] if debug == 'y': FreeCAD.Console.PrintMessage("rise="+str(rise) + " " + str(ok) + "\n" ) if debug == 'y': FreeCAD.Console.PrintMessage("left_right="+str(left_right) + " " + str(ok) + "\n" ) step=float(rise/18) # Treppensteigung / Step_high
 * 1) End Gui

def objnames: # List object names doc = FreeCAD.ActiveDocument objs = FreeCAD.ActiveDocument.Objects names='' #list of objectnames labels='' # list of objectlabels for obj in objs: a = obj.Name                                            # list the Name  of the object  (not modifiable) b = obj.Label                                           # list the Label of the object  (modifiable) try: c = obj.LabelText                                   # list the LabeText of the text (modifiable) names=names+str(a)+" " labels=labels+str(b)+" " except: names=names+str(a)+" " labels=labels+str(b)+" " return names if debug == 'y': App.Console.PrintMessage("Names="+str(names) +"\n"+"Labels="+ str(labels) + "\n")
 * 1) functions
 * 1) end functions

file = open(dataset, "r") # open the file read i = 0 #line counter line = file.readline while(line != ''):   # read number of lines if line[0:1] != "#" and len(line) >0: i = i + 1 if debug == "y": App.Console.PrintMessage("Parameter-Line" + str(i) + " " + line + "\n") line = file.readline file.close numlines=i # number of parameter-lines if debug == "y": App.Console.PrintMessage("Number of Parameter-Lines =" + str(numlines) + "\n") file = open(dataset, "r")                                 # open the file read wire = [] X=Y=Z = 0.0 if left_right == "r": i = 0 #line counter else: i = numlines line = file.readline while(line != ''): num_words = len(line.split) num_tupel = num_words / 3 if debug == "y": App.Console.PrintMessage(str(num_words) + "\n") if debug == "y": App.Console.PrintMessage(str(num_tupel) + "\n") if line[0:1] == "#" or num_words != (num_tupel * 3): if num_words != (num_tupel * 3): App.Console.PrintMessage("Error on Inputfile line " + str(i) + "\n") App.Console.PrintMessage("Only " + str(num_words) + " of multiple of 3 Words\n") else: if line[0:1] == "#": num_words = 0  #  ignore comment if debug == "y": App.Console.PrintMessage(line + "\n") coordinates = line.split if debug == "y": App.Console.PrintMessage(str(coordinates) + " " + str(num_words) + " " + str(num_tupel)+ str(type(num_words)) + "\n") if num_words > 0: data="" # generate statement printline="App.Console.PrintMessage(" # generate variable for PrintMessage (debug)     for x in range(1, num_tupel + 1):       data=data + "X" + str(x) + ",Y" + str(x) + ",Z" + str(x)       printline=printline + "str(X" + str(x) + ") + ' ' + " + "str(Y" + str(x) + ") + ' ' + " + "str(Z" + str(x) + ") + ' '"       if x < num_tupel:         data=data + ","        printline=printline + " + "      data=data + " = coordinates"       printline=printline + ")\n" if debug == "y": App.Console.PrintMessage(data + "\n") if debug == "y": App.Console.PrintMessage(printline + "\n") # X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3,X4,Y4,Z4 = coordinates exec(data) # coordinates to variables if debug == "y": exec(printline) # output input file #App.Console.PrintMessage(str(X1) + " " + str(Y1) + " " +str(Z1) + "\n") px="" pn="" # names of generated variables for x in range(1, num_tupel +1): if x < num_tupel: pn=pn + "p" + str(x) + "," else: pn=pn + "p" + str(x) data = "Z" + str(x) + " = " + str(i * step) # Korrektur z= 0.0 auf aktuelle step if debug == "y": App.Console.PrintMessage(data + "\n") exec(data) px="p" + str(x) + "= FreeCAD.Vector(float(X" + str(x) + "),float(Y" + str(x) + "),float(Z" + str(x) + "))" if debug == "y": App.Console.PrintMessage(px + "\n") exec(px) if debug == "y": App.Console.PrintMessage(pn + "\n") #p1 = FreeCAD.Vector(float(X1),float(Y1),float(Z1)) #p2 = FreeCAD.Vector(float(X2),float(Y2),float(Z2)) #p3 = FreeCAD.Vector(float(X3),float(Y3),float(Z3)) #p4 = FreeCAD.Vector(float(X4),float(Y4),float(Z4)) data="Draft.makeWire([" + pn + "],closed=True)" if debug == "y": App.Console.PrintMessage(data + "\n") exec(data) #Draft.makeWire([p1,p2,p3,p4,p5],closed=True) if left_right == "r": i = i + 1 else: i = i -1 line = file.readline file.close names = objnames   # list objectnames App.Console.PrintMessage("names="+str(names) +"\n") extr="" # suffix for continues Extrude in commands extrnames="Box Cut" #names of source object, because not consitend nameings in freecad j=len(names.split) n=0 #counter if left_right == "r": l1 = 0 l2 = j step = 1 else: l1 = j l2 = -1 step = -1 for x in range(l1, l2, step): w=str(names.split(" ")[x]) if w[0:5] == "DWire": if debug == 'y': App.Console.PrintMessage("w="+str(w) +"\n") data = 'f = FreeCAD.getDocument(docname).addObject("Part::Extrusion","Extrude' + str(extr)+ '")' if debug == "y": App.Console.PrintMessage(data + "\n") exec(data) data = 'f = App.getDocument(docname).getObject("Extrude' + str(extr) + '")' if debug == "y": App.Console.PrintMessage(data + "\n") exec(data) data = 'f.Base = App.getDocument(docname).getObject("' + str(w) + '")' if debug == "y": App.Console.PrintMessage(data + "\n") exec(data) data = 'f.DirMode = str("Custom")' if debug == "y": App.Console.PrintMessage(data + "\n") exec(data) data = 'f.Dir = App.Vector(0.000000000000000, 0.000000000000000, 1.000000000000000)' if debug == "y": App.Console.PrintMessage(data + "\n") exec(data) data = 'f.DirLink = None' if debug == "y": App.Console.PrintMessage(data + "\n") exec(data) data = 'f.LengthFwd = 180.000000000000000' if debug == "y": App.Console.PrintMessage(data + "\n") exec(data) data = 'f.LengthRev = 0.000000000000000' if debug == "y": App.Console.PrintMessage(data + "\n") exec(data) data = 'f.Solid = True' if debug == "y": App.Console.PrintMessage(data + "\n") exec(data) data = 'f.Reversed = False' if debug == "y": App.Console.PrintMessage(data + "\n") exec(data) data = 'f.Symmetric = False' if debug == "y": App.Console.PrintMessage(data + "\n") exec(data) data = 'f.TaperAngle = 0.000000000000000' if debug == "y": App.Console.PrintMessage(data + "\n") exec(data) data = 'f.TaperAngleRev = 0.000000000000000' if debug == "y": App.Console.PrintMessage(data + "\n") exec(data) #if debug == "y": App.Console.PrintMessage(data + "\n") #exec(data) n = n + 1 extr = str("%03d" % n) # count extrude suffix extrnames=extrnames + " Extrude" + str("%03d" % x) FreeCAD.ActiveDocument.recompute
 * 1) List all objects of the document
 * 1) List all objects of the document
 * 1) extrude
 * 1) data = 'App.getDocument(docname).Extrude' + str(extr) + '.Placement=App.Placement(App.Vector(0,0,360), #App.Rotation(App.Vector(0,0,1),0), App.Vector(0,0,0))'

Data (stairs.dat)
Salva questi dati come file stairs.dat nella propria directory delle macro

0.0 -240.0 0.0 0.0 0.0 0.0 1000.0 0.0 0.0 1000.0 -240.0 0.0 0.0 0.0 0.0 0.0 240.0 0.0 1000.0 240.0 0.0 1000.0 0.0 0.0 0.0 240.0 0.0 0.0 520.0 0.0 1000.0 520.0 0.0 1000.0 240.0 0.0 0.0 520.0 0.0 0.0 840.0 0.0 1000.0 720.0 0.0 1000.0 520.0 0.0 0.0 840.0 0.0 0.0 1220.0 0.0 1000.0 860.0 0.0 1000.0 720.0 0.0 0.0 1220.0 0.0 0.0 1620.0 0.0 1000.0 1000.0 0.0 1000.0 860.0 0.0 0.0 1620.0 0.0 0.0 2170.0 0.0 140.0 2170.0 0.0 1000.0 1120.0 0.0 1000.0 1000.0 0.0 140.0 2170.0 0.0 680.0 2170.0 0.0 1020.0 1170.0 0.0 1000.0 1170.0 0.0 1000.0 1120.0 0.0 140.0 2170.0 0.0 680.0 2170.0 0.0 1115.0 2170.0 0.0 1115.0 1170.0 0.0 1020.0 1170.0 0.0 1115.0 2170.0 0.0 1550.0 2170.0 0.0 1210.0 1170.0 0.0 1115.0  1170.0 0.0 1115.0 2170.0 0.0 1550.0 2170.0 0.0 2090.0 2170.0 0.0 1230.0 1120.0 0.0 1230.0 1170.0 0.0 1210.0 1170.0 0.0 1550.0 2170.0 0.0 2090.0 2170.0 0.0 2230.0 2170.0 0.0 2230.0 1620.0 0.0 1230.0 1000.0 0.0 1230.0 1120.0 0.0 2090.0 2170.0 0.0 1230.0 1000.0 0.0 2230.0 1620.0 0.0 2230.0 1230.0 0.0 1230.0 860.0 0.0 1230.0 1000.0 0.0 1230.0 720.0 0.0 1230.0 860.0 0.0 2230.0 1220.0 0.0 2230.0 840.0 0.0 1230.0 720.0 0.0 1230.0 520.0 0.0 1230.0 720.0 0.0 2230.0 840.0 0.0 2230.0 520.0 0.0 1230.0 520.0 0.0 1230.0 240.0 0.0 1230.0 520.0 0.0 2230 520.0 0.0 2230.0 240.0 0.0 1230.0 240.0 0.0 1230.0 0.0 0.0 1230.0 240.0 0.0 2230.0 240.0 0.0 2230.0 0.0 0.0 1230.0 0.0 0.0 1230.0 -240.0 0.0 1230.0 0.0 0.0 2230.0 0.0 0.0 2230.0 -240.0 0.0 1230.0 -240.0 0.0
 * 1) Save this Data as file stairs.dat in your macro directory
 * 2) Stufe 0
 * 1) Stufe 0
 * 1) Stufe 0
 * 1) Stufe 1
 * 1) Stufe 2
 * 1) Stufe 3
 * 1) Stufe 4
 * 1) Stufe 5
 * 1) Stufe 6
 * 1) Stufe 7
 * 1) Stufe 8
 * 1) Stufe 9
 * 1) Stufe 10
 * 1) Stufe 11
 * 1) Stufe 12
 * 1) Stufe 13
 * 1) Stufe 14
 * 1) Stufe 15
 * 1) Stufe 16
 * 1) Stufe 17

Link

 * Macro_PartsLibrary FreeCAD Library