2.How to? macro
Thank you in advance and sorry for the bad english!
full script :
Code: Select all
import FreeCAD
import Part
import DraftTools
import Draft
import Mesh
def myPyramidCal(xIn,yIn,bIn,hIn):
x = float(xIn)
y = float(yIn)
b = float(bIn)
h = float(hIn)
x2 = x+b*0.5
y2 = y+b*0.5
x3 = x+b
y3 = y+b
z = 0
z2 = h
P1x=x
P1y=y
P1z=z
P2x=x
P2y=y3
P2z=z
P3x=x3
P3y=y3
P3z=z
P4x=x3
P4y=y
P4z=z
P5x=x2
P5y=y2
P5z=z2
return P1x,P1y,P1z,P2x,P2y,P2z,P3x,P3y,P3z,P4x,P4y,P4z,P5x,P5y,P5z
def myPyramidSldTxt(P1x,P1y,P1z,P2x,P2y,P2z,P3x,P3y,P3z,P4x,P4y,P4z,P5x,P5y,P5z):
xDummy=0
yDummy=0
zDummy=0
a =[[xDummy,yDummy,zDummy],
[P1x,P1y,P1z],
[P2x,P2y,P2z],
[P3x,P3y,P3z],
[P4x,P4y,P4z],
[P5x,P5y,P5z]]
m1 = Mesh.Mesh([a[1],a[2],a[5]])
MyArea = round(m1.Area,1)
myTxtOut((P1x+P2x+P3x)/3,(P1y+P2y+P3y)/3,(P1z+P2z+P3z)/3,'A=' + str(MyArea))
m2 = Mesh.Mesh([a[2],a[3],a[5]])
m3 = Mesh.Mesh([a[3],a[4],a[5]])
m4 = Mesh.Mesh([a[4],a[1],a[5]])
m5 = Mesh.Mesh([a[1],a[2],a[3],a[1],a[3],a[4]])
mesh=Mesh.Mesh()
mesh.addMesh(m1)
mesh.addMesh(m2)
mesh.addMesh(m3)
mesh.addMesh(m4)
mesh.addMesh(m5)
shape = Part.Shape()
shape.makeShapeFromMesh(mesh.Topology,0.05)
solid = Part.makeSolid(shape).removeSplitter()
myWedgei='x' + str(P1x) + 'y' + str(P1y)+ 'z' + str(P1z)
f = App.activeDocument().addObject("Part::Feature",myWedgei)
f.Shape = solid
def myPyramidSldStr(P1x,P1y,P1z,P2x,P2y,P2z,P3x,P3y,P3z,P4x,P4y,P4z,P5x,P5y,P5z):
xDummy=0
yDummy=0
zDummy=0
a =[[xDummy,yDummy,zDummy],
[P1x,P1y,P1z],
[P2x,P2y,P2z],
[P3x,P3y,P3z],
[P4x,P4y,P4z],
[P5x,P5y,P5z]]
m1 = Mesh.Mesh([a[1],a[2],a[5]])
MyArea = round(m1.Area,1)
myShapeString((P1x+P2x+P3x)/3,(P1y+P2y+P3y)/3,(P1z+P2z+P3z)/3,'A=' + str(MyArea))
m2 = Mesh.Mesh([a[2],a[3],a[5]])
m3 = Mesh.Mesh([a[3],a[4],a[5]])
m4 = Mesh.Mesh([a[4],a[1],a[5]])
m5 = Mesh.Mesh([a[1],a[2],a[3],a[1],a[3],a[4]])
mesh=Mesh.Mesh()
mesh.addMesh(m1)
mesh.addMesh(m2)
mesh.addMesh(m3)
mesh.addMesh(m4)
mesh.addMesh(m5)
shape = Part.Shape()
shape.makeShapeFromMesh(mesh.Topology,0.05)
solid = Part.makeSolid(shape).removeSplitter()
myWedgei='x' + str(P1x) + 'y' + str(P1y)+ 'z' + str(P1z)
f = App.activeDocument().addObject("Part::Feature",myWedgei)
f.Shape = solid
def myShapeString(P5x,P5y,P5z,myStr):
ss=Draft.makeShapeString(String=myStr,FontFile="C:/Program Files/FreeCAD 0.16/Font/times.ttf",Size=10.0,Tracking=0)
plm=FreeCAD.Placement()
plm.Base=FreeCAD.Vector(P5x,P5y,P5z)
plm.Rotation.Q=(0.0,0.0,1.53080849893e-17,1.0)
ss.Placement=plm
ss.Support=None
def myTxtOut(P5x,P5y,P5z,myStr):
p5 = FreeCAD.Vector(P5x,P5y,P5z)
myText = Draft.makeText(myStr,p5)
myText.Label = myStr
b=10
h=10
P1x,P1y,P1z,P2x,P2y,P2z,P3x,P3y,P3z,P4x,P4y,P4z,P5x,P5y,P5z=myPyramidCal(0,0,b,h)
myPyramidSldTxt(P1x,P1y,P1z,P2x,P2y,P2z,P3x,P3y,P3z,P4x,P4y,P4z,P5x,P5y,P5z)
P1x,P1y,P1z,P2x,P2y,P2z,P3x,P3y,P3z,P4x,P4y,P4z,P5x,P5y,P5z=myPyramidCal(0,20,b,h)
myPyramidSldStr(P1x,P1y,P1z,P2x,P2y,P2z,P3x,P3y,P3z,P4x,P4y,P4z,P5x,P5y,P5z)
App.ActiveDocument.recompute()
Gui.activeDocument().activeView().viewAxonometric()
Gui.SendMsgToActiveView("ViewFit")
2018-05-12
Judgment(Front or Back on Face) possible?
Front(outside on Face) good!
Do not judge. It may be possible to respond by deciding input
--------------------------------------------------------------
2018-05-15
sorry
FreeCAD Wiki - Draft Shapestring Tutorial - YouTube
https://m.youtube.com/watch?v=_D5WJqd1SSE
text freecad-->text A=xx.x