Macro Corner shapes wizard/update: Difference between revisions

From FreeCAD Documentation
(Original source code translated to english, changed GUI by introducing a list structure)
 
(icon)
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
# Corner Shape Wizard
<translate>
# https://sourceforge.net/apps/mediawiki/free-cad/index.php?title=Macro_Corner_shapes_wizard/update
<!--T:2-->
# Version 10.03.2013
{{Macro
# Modifications: Neondata, Rainer Nase
# original source: https://sourceforge.net/apps/mediawiki/free-cad/index.php?title=Macro_Corner_shapes_wizard
|Icon=Macro_Corner_shapes_wizard.png
|Name=Corner shapes wizard/update
# -*- coding:utf-8 -*-
|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 Drawing Workbench
#
|Author=Nicotuf
# output to page file commented out ?
|Version=2.0
#####################################
|Date=2013-03-10
# import external functions
|FCVersion= <= 0.17
|Download=[https://www.freecadweb.org/wiki/images/6/60/Macro_Corner_shapes_wizard.png ToolBar Icon]
#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
==Description== <!--T:3-->
App=FreeCAD
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. Original source: [[Macro Corner shapes wizard]]
Gui=FreeCADGui


##################################
==Script== <!--T:4-->
# Class definition

</translate>
class CornerSteel:

def __init__(self, obj):
ToolBar Icon [[Image:Macro_Corner_shapes_wizard.png]]
obj.addProperty("App::PropertyLength","L1","CornerSteel","Width_1").L1=20.0

obj.addProperty("App::PropertyLength","L2","CornerSteel","Width_2").L2=20.0
'''Macro_Corner_shapes_wizard_update.FCMacro'''
obj.addProperty("App::PropertyLength","e1","CornerSteel","Thickness").e1=2.0

#obj.addProperty("App::PropertyLength","e2","CornerSteel","Thickness2").e2=2.0
<!--NOT CHANGE THE <pre> </pre> BALISE CAUSE THE PIPE IN MACRO CODE CUT THE MACRO-->
obj.addProperty("App::PropertyLength","Length","CornerSteel","Length").Length=200.0

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

</pre>

Latest revision as of 14:03, 24 July 2019

Other languages:

Corner shapes wizard/update

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 Drawing Workbench

Macro version: 2.0
Last modified: 2013-03-10
FreeCAD version: <= 0.17
Download: ToolBar Icon
Author: Nicotuf
Author
Nicotuf
Download
ToolBar Icon
Links
Macro Version
2.0
Date last modified
2013-03-10
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. Original source: Macro Corner shapes wizard


Script

ToolBar Icon

Macro_Corner_shapes_wizard_update.FCMacro


 
# 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 PySide 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()