Macro Corner shapes wizard: Difference between revisions

From FreeCAD Documentation
No edit summary
m (minor)
 
(19 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<languages/>
{{Macro|Icon=Text-x-python|Name=Corner shapes wizard|Description=This macro is a complete application, it pops up a dialog asking for the dimensions of your corner piece, then creates the object in the document and creates a page view with top, front and lateral views of the piece.|Author=Nicotuf}}
<translate>
[[https://sourceforge.net/apps/mediawiki/free-cad/index.php?title=Macro_Corner_shapes_wizard/update]|There is a modified version with changes GUI]
<!--T:1-->
{{Macro
|Name=Corner shapes wizard
|Icon=Macro_Corner_shapes_wizard.png
|Description=This macro is a complete application, it pops up a dialog asking for the dimensions of your corner piece, then creates the object in the document and creates a page view with top, front and lateral views of the piece.<br/>This macro use the DrawingWorkBench
|Author=Nicotuf
|Version=1.0
|Date=2011-08-01
|FCVersion= <= 0.17
|Download=[https://www.freecadweb.org/wiki/images/6/60/Macro_Corner_shapes_wizard.png ToolBar Icon]
}}


==Description== <!--T:4-->


<!--T:2-->
# -*- coding:utf-8 -*-
This macro is a complete application, it pops up a dialog asking for the dimensions of your corner piece, then creates the object in the document and creates a page view with top, front and lateral views of the piece.

<!--T:6-->
There is a [[Macro_Corner_shapes_wizard/update|modified version]] with changes GUI.

<!--T:5-->
[[File:CornerShape1.png]]

==Script== <!--T:3-->
</translate>

ToolBar Icon [[Image:Macro_Corner_shapes_wizard.png]]

'''Macro_Corner_shapes_wizard.FCMacro'''

<!--NOT CHANGE THE <pre> </pre> BALISE CAUSE THE PIPE IN MACRO CODE CUT THE MACRO-->
<pre>
# -*- coding:utf-8 -*-
#####################################
# Importation de fonctions externes :
#from os import *
import FreeCAD, FreeCADGui, Part, Draft, math, MeshPart, Mesh, Drawing
#from PyQt4 import QtGui,QtCore
from PySide import QtGui,QtCore
from FreeCAD import Base
App=FreeCAD
Gui=FreeCADGui
##################################
# Défnition Class :
class Corniere:
def __init__(self, obj):
obj.addProperty("App::PropertyLength","L1","Corniere","Largeur 1").L1=20.0
obj.addProperty("App::PropertyLength","L2","Corniere","Largeur 2").L2=20.0
obj.addProperty("App::PropertyLength","e1","Corniere","Epaisseur 1").e1=2.0
#obj.addProperty("App::PropertyLength","e2","Corniere","Epaisseur 2").e2=2.0
obj.addProperty("App::PropertyLength","Longueur","Corniere","Longueur").Longueur=200.0
obj.Proxy = self
def execute(self, fp):
#####################################
P1=Base.Vector(fp.e1,fp.e1,0)
# Importation de fonctions externes :
S1=Part.makeBox(fp.L1,fp.L2,fp.Longueur)
S2=Part.makeBox(fp.L1-fp.e1,fp.L2-fp.e1,fp.Longueur,P1)
fp.Shape=S1.cut(S2)
##################################
#from os import *
# Défnition locale de fonctions :
import FreeCAD, FreeCADGui, Part, Draft, math, MeshPart, Mesh, Drawing
from PyQt4 import QtGui,QtCore
from FreeCAD import Base
App=FreeCAD
Gui=FreeCADGui
##################################
# Défnition Class :
def proceed():
class Corniere:
QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)
def __init__(self, obj):
obj.addProperty("App::PropertyLength","L1","Corniere","Largeur 1").L1=20.0
obj.addProperty("App::PropertyLength","L2","Corniere","Largeur 2").L2=20.0
obj.addProperty("App::PropertyLength","e1","Corniere","Epaisseur 1").e1=2.0
#obj.addProperty("App::PropertyLength","e2","Corniere","Epaisseur 2").e2=2.0
obj.addProperty("App::PropertyLength","Longueur","Corniere","Longueur").Longueur=200.0
obj.Proxy = self
if FreeCAD.ActiveDocument==None:
def execute(self, fp):
P1=Base.Vector(fp.e1,fp.e1,0)
FreeCAD.newDocument("Corniere")
S1=Part.makeBox(fp.L1,fp.L2,fp.Longueur)
S2=Part.makeBox(fp.L1-fp.e1,fp.L2-fp.e1,fp.Longueur,P1)
fp.Shape=S1.cut(S2)
oldDocumentObjects=App.ActiveDocument.Objects
##################################
# Défnition locale de fonctions :
try:
QL1 = float(l1.text())
QL2 = float(l2.text())
Qe = float(l3.text())
QLongueur = float(l4.text())
except:
FreeCAD.Console.PrintError("Wrong input! Only numbers allowed...\n")
Cor=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Corniere")
def proceed():
Corniere(Cor)
QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)
Cor.ViewObject.Proxy=0
Cor.L1=QL1
Cor.L2=QL2
Cor.e1=Qe
Cor.Longueur=QLongueur
if FreeCAD.ActiveDocument==None:
App.ActiveDocument.recompute()
Gui.SendMsgToActiveView("ViewFit")
FreeCAD.newDocument("Corniere")
QtGui.qApp.restoreOverrideCursor()
oldDocumentObjects=App.ActiveDocument.Objects
try:
Plan(Cor)
QL1 = float(l1.text())
QL2 = float(l2.text())
Qe = float(l3.text())
QLongueur = float(l4.text())
except:
FreeCAD.Console.PrintError("Wrong input! Only numbers allowed...\n")
dialog.hide()
Cor=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Corniere")
Corniere(Cor)
Cor.ViewObject.Proxy=0
Cor.L1=QL1
Cor.L2=QL2
Cor.e1=Qe
Cor.Longueur=QLongueur
def hide():
App.ActiveDocument.recompute()
Gui.SendMsgToActiveView("ViewFit")
dialog.hide()
QtGui.qApp.restoreOverrideCursor()
Plan(Cor)
dialog.hide()
def hide():
def Plan(obj):
ObjetProjete=obj.Shape
dialog.hide()
TailleX=ObjetProjete.BoundBox.XLength
def Plan(obj):
TailleY=ObjetProjete.BoundBox.YLength
TailleZ=ObjetProjete.BoundBox.ZLength
page = App.activeDocument().addObject('Drawing::FeaturePage','Page')
ObjetProjete=obj.Shape
page.Template = App.getResourceDir()+'Mod/Drawing/Templates/A3_Landscape.svg'
vueprofil = App.activeDocument().addObject('Drawing::FeatureViewPart','VueProfil')
vueprofil.Source = obj
vueprofil.Direction = (0.0,0.0,1.0)
vueprofil.Scale = 1.0
vueprofil.X = 50.0
vueprofil.Y = 50.0
page.addObject(vueprofil)
vuegauche = App.activeDocument().addObject('Drawing::FeatureViewPart','Vuegauche')
TailleX=ObjetProjete.BoundBox.XLength
vuegauche.Source = obj
TailleY=ObjetProjete.BoundBox.YLength
vuegauche.Direction = (-1.0,0.0,0.0)
TailleZ=ObjetProjete.BoundBox.ZLength
vuegauche.ShowHiddenLines = True
vuegauche.Scale = 1.0
vuegauche.Rotation = 180.0
vuegauche.X = 50.0+TailleX/2+TailleX
vuegauche.Y = 50.0
page.addObject(vuegauche)
page = App.activeDocument().addObject('Drawing::FeaturePage','Page')
vuedessus = App.activeDocument().addObject('Drawing::FeatureViewPart','Vuedessus')
vuedessus.Source = obj
page.Template = App.getResourceDir()+'Mod/Drawing/Templates/A3_Landscape.svg'
vuedessus.Direction = (0.0,-1.0,0.0)
vueprofil = App.activeDocument().addObject('Drawing::FeatureViewPart','VueProfil')
vuedessus.ShowHiddenLines = True
vueprofil.Source = obj
vueprofil.Direction = (0.0,0.0,1.0)
vuedessus.Scale = 1.0
vueprofil.Scale = 1.0
vuedessus.Rotation = 180.0
vueprofil.X = 50.0
vuedessus.X = 50.0+TailleX/2+TailleX
vueprofil.Y = 50.0
vuedessus.Y = 50.0+TailleX/2+TailleY+TailleX
page.addObject(vueprofil)
page.addObject(vuedessus)
vuegauche = App.activeDocument().addObject('Drawing::FeatureViewPart','Vuegauche')
vueiso = App.activeDocument().addObject('Drawing::FeatureViewPart','VueIso')
vuegauche.Source = obj
vueiso.Source = obj
vuegauche.Direction = (-1.0,0.0,0.0)
vueiso.Direction = (-1.0,-1.0,0.5)
vueiso.Scale = 1.0
vuegauche.ShowHiddenLines = True
vueiso.ShowSmoothLines = True
vuegauche.Scale = 1.0
vueiso.X = TailleZ+TailleX/2
vuegauche.Rotation = 180.0
vueiso.Y = 7*TailleZ+3*TailleY
vuegauche.X = 50.0+TailleX/2+TailleX
page.addObject(vueiso)
vuegauche.Y = 50.0
page.addObject(vuegauche)
vuedessus = App.activeDocument().addObject('Drawing::FeatureViewPart','Vuedessus')
vuedessus.Source = obj
vuedessus.Direction = (0.0,-1.0,0.0)
vuedessus.ShowHiddenLines = True
vuedessus.Scale = 1.0
vuedessus.Rotation = 180.0
vuedessus.X = 50.0+TailleX/2+TailleX
vuedessus.Y = 50.0+TailleX/2+TailleY+TailleX
page.addObject(vuedessus)
vueiso = App.activeDocument().addObject('Drawing::FeatureViewPart','VueIso')
App.activeDocument().recompute()
vueiso.Source = obj
vueiso.Direction = (-1.0,-1.0,0.5)
vueiso.Scale = 1.0
vueiso.ShowSmoothLines = True
vueiso.X = TailleZ+TailleX/2
vueiso.Y = 7*TailleZ+3*TailleY
page.addObject(vueiso)
PageFile = open(page.PageResult,'r')
App.activeDocument().recompute()
OutFile = open('temp.svg','w')
OutFile.write(PageFile.read())
del OutFile,PageFile
PageFile = open(page.PageResult,'r')
OutFile = open('temp.svg','w')
OutFile.write(PageFile.read())
del OutFile,PageFile
dialog = QtGui.QDialog()
dialog = QtGui.QDialog()
dialog.resize(200,200)
dialog.resize(200,200)
dialog.setWindowTitle("Corniere")
dialog.setWindowTitle("Corniere")
la = QtGui.QVBoxLayout(dialog)
la = QtGui.QVBoxLayout(dialog)
e1 = QtGui.QLabel("Dimensions de la corniere")
e1 = QtGui.QLabel("Dimensions de la corniere")
commentFont=QtGui.QFont("Arial",10,True)
commentFont=QtGui.QFont("Arial",10,True)
e1.setFont(commentFont)
e1.setFont(commentFont)
la.addWidget(e1)
la.addWidget(e1)
t1 = QtGui.QLabel("L1")
t1 = QtGui.QLabel("L1")
la.addWidget(t1)
la.addWidget(t1)
l1 = QtGui.QLineEdit()
l1 = QtGui.QLineEdit()
l1.setText("20")
l1.setText("20")
la.addWidget(l1)
la.addWidget(l1)
t2 = QtGui.QLabel("L2")
t2 = QtGui.QLabel("L2")
la.addWidget(t2)
la.addWidget(t2)
l2 = QtGui.QLineEdit()
l2 = QtGui.QLineEdit()
l2.setText("20")
l2.setText("20")
la.addWidget(l2)
la.addWidget(l2)
t3 = QtGui.QLabel("e")
t3 = QtGui.QLabel("e")
la.addWidget(t3)
la.addWidget(t3)
l3 = QtGui.QLineEdit()
l3 = QtGui.QLineEdit()
l3.setText("2")
l3.setText("2")
la.addWidget(l3)
la.addWidget(l3)
t4 = QtGui.QLabel("Longueur")
t4 = QtGui.QLabel("Longueur")
la.addWidget(t4)
la.addWidget(t4)
l4 = QtGui.QLineEdit()
l4 = QtGui.QLineEdit()
l4.setText("300")
l4.setText("300")
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()


</pre>
{{languages | {{es|Macro_Corner_shapes_wizard/es}} {{fr|Macro_Corner_shapes_wizard/fr}} {{it|Macro_Corner_shapes_wizard/it}} }}
{{clear}}

Latest revision as of 14:09, 24 July 2019

Corner shapes wizard

Description
This macro is a complete application, it pops up a dialog asking for the dimensions of your corner piece, then creates the object in the document and creates a page view with top, front and lateral views of the piece.
This macro use the DrawingWorkBench

Macro version: 1.0
Last modified: 2011-08-01
FreeCAD version: <= 0.17
Download: ToolBar Icon
Author: Nicotuf
Author
Nicotuf
Download
ToolBar Icon
Links
Macro Version
1.0
Date last modified
2011-08-01
FreeCAD Version(s)
<= 0.17
Default shortcut
None
See also
None

Description

This macro is a complete application, it pops up a dialog asking for the dimensions of your corner piece, then creates the object in the document and creates a page view with top, front and lateral views of the piece.

There is a modified version with changes GUI.

Script

ToolBar Icon

Macro_Corner_shapes_wizard.FCMacro

# -*- coding:utf-8 -*-
 
#####################################
# Importation de fonctions externes :
 
#from os import *
import FreeCAD, FreeCADGui, Part, Draft, math, MeshPart, Mesh, Drawing
#from PyQt4 import QtGui,QtCore
from PySide import QtGui,QtCore
from FreeCAD import Base
App=FreeCAD
Gui=FreeCADGui
 
##################################
# Défnition Class :
 
class Corniere:
   def __init__(self, obj):
      obj.addProperty("App::PropertyLength","L1","Corniere","Largeur 1").L1=20.0
      obj.addProperty("App::PropertyLength","L2","Corniere","Largeur 2").L2=20.0
      obj.addProperty("App::PropertyLength","e1","Corniere","Epaisseur 1").e1=2.0
      #obj.addProperty("App::PropertyLength","e2","Corniere","Epaisseur 2").e2=2.0
      obj.addProperty("App::PropertyLength","Longueur","Corniere","Longueur").Longueur=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.Longueur)
      S2=Part.makeBox(fp.L1-fp.e1,fp.L2-fp.e1,fp.Longueur,P1)
      fp.Shape=S1.cut(S2)   
 
##################################
# Défnition locale de fonctions :
 
 
def proceed():
   QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)
 
   if FreeCAD.ActiveDocument==None:
      FreeCAD.newDocument("Corniere")
 
   oldDocumentObjects=App.ActiveDocument.Objects
 
   try:
      QL1 = float(l1.text())   
      QL2 = float(l2.text())
      Qe = float(l3.text())
      QLongueur = float(l4.text())
   except:
      FreeCAD.Console.PrintError("Wrong input! Only numbers allowed...\n")
 
   Cor=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Corniere")
   Corniere(Cor)
   Cor.ViewObject.Proxy=0
   Cor.L1=QL1
   Cor.L2=QL2
   Cor.e1=Qe
   Cor.Longueur=QLongueur
 
   App.ActiveDocument.recompute()
   Gui.SendMsgToActiveView("ViewFit")
 
   QtGui.qApp.restoreOverrideCursor()
 
   Plan(Cor)
 
   dialog.hide()
 
def hide():
 
   dialog.hide()
 
def Plan(obj):
 
   ObjetProjete=obj.Shape
 
   TailleX=ObjetProjete.BoundBox.XLength
   TailleY=ObjetProjete.BoundBox.YLength
   TailleZ=ObjetProjete.BoundBox.ZLength
 
   page = App.activeDocument().addObject('Drawing::FeaturePage','Page')
   page.Template = App.getResourceDir()+'Mod/Drawing/Templates/A3_Landscape.svg'   
   vueprofil = App.activeDocument().addObject('Drawing::FeatureViewPart','VueProfil')
   vueprofil.Source = obj
   vueprofil.Direction = (0.0,0.0,1.0)
   vueprofil.Scale = 1.0
   vueprofil.X = 50.0
   vueprofil.Y = 50.0
   page.addObject(vueprofil)
 
   vuegauche = App.activeDocument().addObject('Drawing::FeatureViewPart','Vuegauche')
   vuegauche.Source = obj
   vuegauche.Direction = (-1.0,0.0,0.0)
   vuegauche.ShowHiddenLines = True
   vuegauche.Scale = 1.0
   vuegauche.Rotation = 180.0
   vuegauche.X = 50.0+TailleX/2+TailleX
   vuegauche.Y = 50.0
   page.addObject(vuegauche)
 
   vuedessus = App.activeDocument().addObject('Drawing::FeatureViewPart','Vuedessus')
   vuedessus.Source = obj
   vuedessus.Direction = (0.0,-1.0,0.0)
   vuedessus.ShowHiddenLines = True
   vuedessus.Scale = 1.0
   vuedessus.Rotation = 180.0
   vuedessus.X = 50.0+TailleX/2+TailleX
   vuedessus.Y = 50.0+TailleX/2+TailleY+TailleX
   page.addObject(vuedessus)
 
   vueiso = App.activeDocument().addObject('Drawing::FeatureViewPart','VueIso')
   vueiso.Source = obj
   vueiso.Direction = (-1.0,-1.0,0.5)
   vueiso.Scale = 1.0
   vueiso.ShowSmoothLines = True
   vueiso.X = TailleZ+TailleX/2
   vueiso.Y = 7*TailleZ+3*TailleY
   page.addObject(vueiso)
 
 
   App.activeDocument().recompute()
 
   PageFile = open(page.PageResult,'r')
   OutFile = open('temp.svg','w')
   OutFile.write(PageFile.read())
   del OutFile,PageFile
 
 
dialog = QtGui.QDialog()
dialog.resize(200,200)
dialog.setWindowTitle("Corniere")
la = QtGui.QVBoxLayout(dialog)
 
e1 = QtGui.QLabel("Dimensions de la corniere")
commentFont=QtGui.QFont("Arial",10,True)
e1.setFont(commentFont)
la.addWidget(e1)
 
t1 = QtGui.QLabel("L1")
la.addWidget(t1)
l1 = QtGui.QLineEdit()
l1.setText("20")
la.addWidget(l1)
 
t2 = QtGui.QLabel("L2")
la.addWidget(t2)
l2 = QtGui.QLineEdit()
l2.setText("20")
la.addWidget(l2)
 
t3 = QtGui.QLabel("e")
la.addWidget(t3)
l3 = QtGui.QLineEdit()
l3.setText("2")
la.addWidget(l3)
 
t4 = QtGui.QLabel("Longueur")
la.addWidget(t4)
l4 = QtGui.QLineEdit()
l4.setText("300")
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()