Macro Corner shapes wizard/update: Difference between revisions
m (Robot: Automated text replacement (-https://sourceforge.net/apps/mediawiki/free-cad/ +http://www.freecadweb.org/wiki/)) |
Renatorivo (talk | contribs) (indentation and syntaxhighlight) |
||
Line 1: | Line 1: | ||
<translate> |
|||
# Corner Shape Wizard |
|||
Macro Corner shapes wizard/update |
|||
# http://www.freecadweb.org/wiki/index.php?title=Macro_Corner_shapes_wizard/update |
|||
</translate> |
|||
# Version 10.03.2013 |
|||
<syntaxhighlight> |
|||
# Modifications: Neondata, Rainer Nase |
|||
# original source: http://www.freecadweb.org/wiki/index.php?title=Macro_Corner_shapes_wizard |
|||
# -*- coding:utf-8 -*- |
|||
# Corner Shape Wizard |
|||
# |
|||
# http://www.freecadweb.org/wiki/index.php?title=Macro_Corner_shapes_wizard/update |
|||
# output to page file commented out ? |
|||
# Version 10.03.2013 |
|||
##################################### |
|||
# Modifications: Neondata, Rainer Nase |
|||
# import external functions |
|||
# original source: http://www.freecadweb.org/wiki/index.php?title=Macro_Corner_shapes_wizard |
|||
# -*- coding:utf-8 -*- |
|||
#from os import * |
|||
# |
|||
import FreeCAD as App, FreeCADGui as Gui, Part, Draft, math, MeshPart, Mesh, Drawing |
|||
# output to page file commented out ? |
|||
from PyQt4 import QtGui,QtCore |
|||
##################################### |
|||
from FreeCAD import Base |
|||
# import external functions |
|||
App=FreeCAD |
|||
Gui=FreeCADGui |
|||
#from os import * |
|||
import FreeCAD as App, FreeCADGui as Gui, Part, Draft, math, MeshPart, Mesh, Drawing |
|||
################################## |
|||
from PyQt4 import QtGui,QtCore |
|||
# Class definition |
|||
from FreeCAD import Base |
|||
App=FreeCAD |
|||
class CornerSteel: |
|||
Gui=FreeCADGui |
|||
def __init__(self, obj): |
|||
obj.addProperty("App::PropertyLength","L1","CornerSteel","Width_1").L1=20.0 |
|||
################################## |
|||
obj.addProperty("App::PropertyLength","L2","CornerSteel","Width_2").L2=20.0 |
|||
# Class definition |
|||
obj.addProperty("App::PropertyLength","e1","CornerSteel","Thickness").e1=2.0 |
|||
#obj.addProperty("App::PropertyLength","e2","CornerSteel","Thickness2").e2=2.0 |
|||
class CornerSteel: |
|||
obj.addProperty("App::PropertyLength","Length","CornerSteel","Length").Length=200.0 |
|||
def __init__(self, obj): |
|||
obj.addProperty("App::PropertyLength","L1","CornerSteel","Width_1").L1=20.0 |
|||
obj.addProperty("App::PropertyLength","L2","CornerSteel","Width_2").L2=20.0 |
|||
def execute(self, fp): |
|||
obj.addProperty("App::PropertyLength","e1","CornerSteel","Thickness").e1=2.0 |
|||
P1=Base.Vector(fp.e1,fp.e1,0) |
|||
#obj.addProperty("App::PropertyLength","e2","CornerSteel","Thickness2").e2=2.0 |
|||
S1=Part.makeBox(fp.L1,fp.L2,fp.Length) |
|||
obj.addProperty("App::PropertyLength","Length","CornerSteel","Length").Length=200.0 |
|||
S2=Part.makeBox(fp.L1-fp.e1,fp.L2-fp.e1,fp.Length,P1) |
|||
obj.Proxy = self |
|||
def execute(self, fp): |
|||
################################## |
|||
P1=Base.Vector(fp.e1,fp.e1,0) |
|||
# definition of local functions : |
|||
S1=Part.makeBox(fp.L1,fp.L2,fp.Length) |
|||
S2=Part.makeBox(fp.L1-fp.e1,fp.L2-fp.e1,fp.Length,P1) |
|||
fp.Shape=S1.cut(S2) |
|||
def proceed(): |
|||
QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor) |
|||
################################## |
|||
# definition of local functions : |
|||
if App.ActiveDocument==None: |
|||
App.newDocument("CornerSteel") |
|||
def proceed(): |
|||
oldDocumentObjects=App.ActiveDocument.Objects |
|||
QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor) |
|||
try: |
|||
if App.ActiveDocument==None: |
|||
QL1 = float(l[0].text()) |
|||
App.newDocument("CornerSteel") |
|||
QL2 = float(l[1].text()) |
|||
Qe = float(l[2].text()) |
|||
oldDocumentObjects=App.ActiveDocument.Objects |
|||
QLength = float(l[3].text()) |
|||
except: |
|||
try: |
|||
App.Console.PrintError("Wrong input! Only numbers allowed...\n") |
|||
QL1 = float(l[0].text()) |
|||
QL2 = float(l[1].text()) |
|||
Cor=App.ActiveDocument.addObject("Part::FeaturePython","CornerSteel") |
|||
Qe = float(l[2].text()) |
|||
QLength = float(l[3].text()) |
|||
Cor.ViewObject.Proxy=0 |
|||
except: |
|||
Cor.L1 = QL1 |
|||
App.Console.PrintError("Wrong input! Only numbers allowed...\n") |
|||
Cor.L2 = QL2 |
|||
Cor.e1 = Qe |
|||
Cor=App.ActiveDocument.addObject("Part::FeaturePython","CornerSteel") |
|||
Cor.Length=QLength |
|||
CornerSteel(Cor) |
|||
Cor.ViewObject.Proxy=0 |
|||
App.ActiveDocument.recompute() |
|||
Cor.L1 = QL1 |
|||
Gui.SendMsgToActiveView("ViewFit") |
|||
Cor.L2 = QL2 |
|||
Cor.e1 = Qe |
|||
QtGui.qApp.restoreOverrideCursor() |
|||
Cor.Length=QLength |
|||
Drawing(Cor) |
|||
App.ActiveDocument.recompute() |
|||
Gui.SendMsgToActiveView("ViewFit") |
|||
dialog.hide() |
|||
QtGui.qApp.restoreOverrideCursor() |
|||
def hide(): |
|||
Drawing(Cor) |
|||
dialog.hide() |
|||
def hide(): |
|||
ObjetProjete=obj.Shape |
|||
dialog.hide() |
|||
DimX=ObjetProjete.BoundBox.XLength |
|||
DimY=ObjetProjete.BoundBox.YLength |
|||
def Drawing(obj): |
|||
DimZ=ObjetProjete.BoundBox.ZLength |
|||
ObjetProjete=obj.Shape |
|||
page = App.activeDocument().addObject('Drawing::FeaturePage','Page') |
|||
page.Template = App.getResourceDir()+'Mod/Drawing/Templates/A3_Landscape.svg' |
|||
DimX=ObjetProjete.BoundBox.XLength |
|||
ProfileView = App.activeDocument().addObject('Drawing::FeatureViewPart','ProfileView') |
|||
DimY=ObjetProjete.BoundBox.YLength |
|||
ProfileView.Source = obj |
|||
DimZ=ObjetProjete.BoundBox.ZLength |
|||
ProfileView.Direction = (0.0,0.0,1.0) |
|||
ProfileView.Scale = 1.0 |
|||
page = App.activeDocument().addObject('Drawing::FeaturePage','Page') |
|||
ProfileView.X = 50.0 |
|||
page.Template = App.getResourceDir()+'Mod/Drawing/Templates/A3_Landscape.svg' |
|||
ProfileView.Y = 50.0 |
|||
ProfileView = App.activeDocument().addObject('Drawing::FeatureViewPart','ProfileView') |
|||
ProfileView.Source = obj |
|||
ProfileView.Direction = (0.0,0.0,1.0) |
|||
LeftView = App.activeDocument().addObject('Drawing::FeatureViewPart','LeftView') |
|||
ProfileView.Scale = 1.0 |
|||
ProfileView.X = 50.0 |
|||
ProfileView.Y = 50.0 |
|||
LeftView.ShowHiddenLines = True |
|||
page.addObject(ProfileView) |
|||
LeftView.Scale = 1.0 |
|||
LeftView.Rotation = 180.0 |
|||
LeftView = App.activeDocument().addObject('Drawing::FeatureViewPart','LeftView') |
|||
LeftView.X = 50.0+DimX/2+DimX |
|||
LeftView.Source = obj |
|||
LeftView.Direction = (-1.0,0.0,0.0) |
|||
page.addObject(LeftView) |
|||
LeftView.ShowHiddenLines = True |
|||
LeftView.Scale = 1.0 |
|||
TopView = App.activeDocument().addObject('Drawing::FeatureViewPart','TopView') |
|||
LeftView.Rotation = 180.0 |
|||
LeftView.X = 50.0+DimX/2+DimX |
|||
TopView.Direction = (0.0,-1.0,0.0) |
|||
LeftView.Y = 50.0 |
|||
TopView.ShowHiddenLines = True |
|||
page.addObject(LeftView) |
|||
TopView.Scale = 1.0 |
|||
TopView.Rotation = 180.0 |
|||
TopView = App.activeDocument().addObject('Drawing::FeatureViewPart','TopView') |
|||
TopView.X = 50.0+DimX/2+DimX |
|||
TopView.Source = obj |
|||
TopView.Direction = (0.0,-1.0,0.0) |
|||
page.addObject(TopView) |
|||
TopView.ShowHiddenLines = True |
|||
TopView.Scale = 1.0 |
|||
IsoView = App.activeDocument().addObject('Drawing::FeatureViewPart','IsoView') |
|||
TopView.Rotation = 180.0 |
|||
TopView.X = 50.0+DimX/2+DimX |
|||
TopView.Y = 50.0+DimX/2+DimY+DimX |
|||
page.addObject(TopView) |
|||
IsoView.ShowSmoothLines = True |
|||
IsoView.X = DimZ+DimX/2 |
|||
IsoView = App.activeDocument().addObject('Drawing::FeatureViewPart','IsoView') |
|||
IsoView.Y = 7*DimZ+3*DimY |
|||
IsoView.Source = obj |
|||
page.addObject(IsoView) |
|||
IsoView.Direction = (-1.0,-1.0,0.5) |
|||
IsoView.Scale = 1.0 |
|||
IsoView.ShowSmoothLines = True |
|||
App.activeDocument().recompute() |
|||
IsoView.X = DimZ+DimX/2 |
|||
IsoView.Y = 7*DimZ+3*DimY |
|||
# PageFile = open(page.PageResult,'r') |
|||
page.addObject(IsoView) |
|||
# OutFile = open('temp.svg','w') |
|||
# OutFile.write(PageFile.read()) |
|||
# del OutFile,PageFile |
|||
App.activeDocument().recompute() |
|||
# PageFile = open(page.PageResult,'r') |
|||
# OutFile = open('temp.svg','w') |
|||
# OutFile.write(PageFile.read()) |
|||
# del OutFile,PageFile |
|||
l = [] # Array to transfer parameters to the process |
|||
F = [ ["Width first side" , "20."] ] |
|||
F.append(["Width second side" , "10."]) |
|||
F.append(["Thickness" , "3."]) |
|||
F.append(["Length" , "100."]) |
|||
l = [] # Array to transfer parameters to the process |
|||
dialog = QtGui.QDialog() |
|||
F = [ ["Width first side" , "20."] ] |
|||
dialog.resize(200,200) |
|||
F.append(["Width second side" , "10."]) |
|||
dialog.setWindowTitle("Angle profile (angle steel)") |
|||
F.append(["Thickness" , "3."]) |
|||
la = QtGui.QVBoxLayout(dialog) |
|||
F.append(["Length" , "100."]) |
|||
# adding the input fields to the GUI |
|||
dialog = QtGui.QDialog() |
|||
for field in range(len(F)): |
|||
dialog.resize(200,200) |
|||
dialog.setWindowTitle("Angle profile (angle steel)") |
|||
la.addWidget(QtGui.QLabel(F[field][0])) |
|||
la = QtGui.QVBoxLayout(dialog) |
|||
la.addWidget(l[field]) |
|||
# adding the input fields to the GUI |
|||
for field in range(len(F)): |
|||
e1 = QtGui.QLabel("Dimensions of the corner profile") |
|||
commentFont=QtGui.QFont("Arial",10,True) |
|||
la.addWidget(QtGui.QLabel(F[field][0])) |
|||
e1.setFont(commentFont) |
|||
l.append( QtGui.QLineEdit(F[field][1]) ) |
|||
la.addWidget(e1) |
|||
la.addWidget(l[field]) |
|||
e1 = QtGui.QLabel("Dimensions of the corner profile") |
|||
okbox = QtGui.QDialogButtonBox(dialog) |
|||
commentFont=QtGui.QFont("Arial",10,True) |
|||
okbox.setOrientation(QtCore.Qt.Horizontal) |
|||
e1.setFont(commentFont) |
|||
okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok) |
|||
la.addWidget(e1) |
|||
QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), proceed) |
|||
okbox = QtGui.QDialogButtonBox(dialog) |
|||
QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), hide) |
|||
okbox.setOrientation(QtCore.Qt.Horizontal) |
|||
QtCore.QMetaObject.connectSlotsByName(dialog) |
|||
okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok) |
|||
dialog.show() |
|||
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() |
|||
</syntaxhighlight> |
Revision as of 12:35, 6 May 2014
Macro Corner shapes wizard/update
# Corner Shape Wizard
# http://www.freecadweb.org/wiki/index.php?title=Macro_Corner_shapes_wizard/update
# Version 10.03.2013
# Modifications: Neondata, Rainer Nase
# original source: http://www.freecadweb.org/wiki/index.php?title=Macro_Corner_shapes_wizard
# -*- coding:utf-8 -*-
#
# output to page file commented out ?
#####################################
# import external functions
#from os import *
import FreeCAD as App, FreeCADGui as Gui, Part, Draft, math, MeshPart, Mesh, Drawing
from PyQt4 import QtGui,QtCore
from FreeCAD import Base
App=FreeCAD
Gui=FreeCADGui
##################################
# Class definition
class CornerSteel:
def __init__(self, obj):
obj.addProperty("App::PropertyLength","L1","CornerSteel","Width_1").L1=20.0
obj.addProperty("App::PropertyLength","L2","CornerSteel","Width_2").L2=20.0
obj.addProperty("App::PropertyLength","e1","CornerSteel","Thickness").e1=2.0
#obj.addProperty("App::PropertyLength","e2","CornerSteel","Thickness2").e2=2.0
obj.addProperty("App::PropertyLength","Length","CornerSteel","Length").Length=200.0
obj.Proxy = self
def execute(self, fp):
P1=Base.Vector(fp.e1,fp.e1,0)
S1=Part.makeBox(fp.L1,fp.L2,fp.Length)
S2=Part.makeBox(fp.L1-fp.e1,fp.L2-fp.e1,fp.Length,P1)
fp.Shape=S1.cut(S2)
##################################
# definition of local functions :
def proceed():
QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)
if App.ActiveDocument==None:
App.newDocument("CornerSteel")
oldDocumentObjects=App.ActiveDocument.Objects
try:
QL1 = float(l[0].text())
QL2 = float(l[1].text())
Qe = float(l[2].text())
QLength = float(l[3].text())
except:
App.Console.PrintError("Wrong input! Only numbers allowed...\n")
Cor=App.ActiveDocument.addObject("Part::FeaturePython","CornerSteel")
CornerSteel(Cor)
Cor.ViewObject.Proxy=0
Cor.L1 = QL1
Cor.L2 = QL2
Cor.e1 = Qe
Cor.Length=QLength
App.ActiveDocument.recompute()
Gui.SendMsgToActiveView("ViewFit")
QtGui.qApp.restoreOverrideCursor()
Drawing(Cor)
dialog.hide()
def hide():
dialog.hide()
def Drawing(obj):
ObjetProjete=obj.Shape
DimX=ObjetProjete.BoundBox.XLength
DimY=ObjetProjete.BoundBox.YLength
DimZ=ObjetProjete.BoundBox.ZLength
page = App.activeDocument().addObject('Drawing::FeaturePage','Page')
page.Template = App.getResourceDir()+'Mod/Drawing/Templates/A3_Landscape.svg'
ProfileView = App.activeDocument().addObject('Drawing::FeatureViewPart','ProfileView')
ProfileView.Source = obj
ProfileView.Direction = (0.0,0.0,1.0)
ProfileView.Scale = 1.0
ProfileView.X = 50.0
ProfileView.Y = 50.0
page.addObject(ProfileView)
LeftView = App.activeDocument().addObject('Drawing::FeatureViewPart','LeftView')
LeftView.Source = obj
LeftView.Direction = (-1.0,0.0,0.0)
LeftView.ShowHiddenLines = True
LeftView.Scale = 1.0
LeftView.Rotation = 180.0
LeftView.X = 50.0+DimX/2+DimX
LeftView.Y = 50.0
page.addObject(LeftView)
TopView = App.activeDocument().addObject('Drawing::FeatureViewPart','TopView')
TopView.Source = obj
TopView.Direction = (0.0,-1.0,0.0)
TopView.ShowHiddenLines = True
TopView.Scale = 1.0
TopView.Rotation = 180.0
TopView.X = 50.0+DimX/2+DimX
TopView.Y = 50.0+DimX/2+DimY+DimX
page.addObject(TopView)
IsoView = App.activeDocument().addObject('Drawing::FeatureViewPart','IsoView')
IsoView.Source = obj
IsoView.Direction = (-1.0,-1.0,0.5)
IsoView.Scale = 1.0
IsoView.ShowSmoothLines = True
IsoView.X = DimZ+DimX/2
IsoView.Y = 7*DimZ+3*DimY
page.addObject(IsoView)
App.activeDocument().recompute()
# PageFile = open(page.PageResult,'r')
# OutFile = open('temp.svg','w')
# OutFile.write(PageFile.read())
# del OutFile,PageFile
l = [] # Array to transfer parameters to the process
F = [ ["Width first side" , "20."] ]
F.append(["Width second side" , "10."])
F.append(["Thickness" , "3."])
F.append(["Length" , "100."])
dialog = QtGui.QDialog()
dialog.resize(200,200)
dialog.setWindowTitle("Angle profile (angle steel)")
la = QtGui.QVBoxLayout(dialog)
# adding the input fields to the GUI
for field in range(len(F)):
la.addWidget(QtGui.QLabel(F[field][0]))
l.append( QtGui.QLineEdit(F[field][1]) )
la.addWidget(l[field])
e1 = QtGui.QLabel("Dimensions of the corner profile")
commentFont=QtGui.QFont("Arial",10,True)
e1.setFont(commentFont)
la.addWidget(e1)
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()