参考になるヘルプがあれば、教えてください。
Code: Select all
import FreeCAD
import Part
import DraftTools
import Draft
import Mesh
def myTetrahedron(P1x,P1y,P1z,P2x,P2y,P2z,P3x,P3y,P3z,P4x,P4y,P4z):
xDummy=0
yDummy=0
zDummy=0
a =[[xDummy,yDummy,zDummy], #dummy
[P1x,P1y,P1z],
[P2x,P2y,P2z],
[P3x,P3y,P3z],
[P4x,P4y,P4z]]
m1 = Mesh.Mesh([a[1],a[2],a[3]])
m2 = Mesh.Mesh([a[1],a[2],a[4]])
m3 = Mesh.Mesh([a[2],a[3],a[4]])
m4 = Mesh.Mesh([a[3],a[1],a[4]])
mesh=Mesh.Mesh()
mesh.addMesh(m1)
mesh.addMesh(m2)
mesh.addMesh(m3)
mesh.addMesh(m4)
shape = Part.Shape()
shape.makeShapeFromMesh(mesh.Topology,0.05)
solid = Part.makeSolid(shape).removeSplitter()
myWedgei='myTetrahedron_'+'x' + str(P1x) + 'y' + str(P1y)+ 'z' + str(P1z)
f = App.activeDocument().addObject("Part::Feature",myWedgei)
f.Shape = solid
FreeCADGui.getDocument('Unnamed').getObject('myTetrahedron_x0_0y0_0z5_0').ShapeColor = (1.00,1.00,0.50)
target_object=App.ActiveDocument.getObjectsByLabel("myTetrahedron_x0_0y0_0z5_0")[0]
myVolume=target_object.Shape.Volume
myTxt_XYZ(0,0,0,"{:.3f}".format(myVolume)+'cm3')
def myCube(mySize):
App.ActiveDocument.addObject("Part::Box","Box")
App.getDocument('Unnamed').Box.Length=mySize
App.getDocument('Unnamed').Box.Width=mySize
App.getDocument('Unnamed').Box.Height=mySize
App.getDocument('Unnamed').Box.Placement=App.Placement(App.Vector(0.00,0.00,0.00),App.Rotation(App.Vector(0.00,0.00,1.00),0.00))
FreeCADGui.getDocument('Unnamed').getObject('Box').Transparency = 100
def myTxt_XYZ(P5x,P5y,P5z,myWedgei):
p5 = FreeCAD.Vector(P5x,P5y,P5z)
myText = Draft.makeText(myWedgei,p5)
myText.Label = myWedgei
FreeCADGui.ActiveDocument.ActiveObject.FontSize = '0.7 mm'
# [(0,0,5),(6,0,2),(6,6,4),(0,6,0)]
P1x,P1y,P1z=0.0,0.0,5.0
P2x,P2y,P2z=6.0,0.0,2.0
P3x,P3y,P3z=6.0,6.0,4.0
P4x,P4y,P4z=0.0,6.0,0.0
myTetrahedron(P1x,P1y,P1z,P2x,P2y,P2z,P3x,P3y,P3z,P4x,P4y,P4z)
myTxt_XYZ(P1x,P1y,P1z,'x' + str(P1x) + 'y' + str(P1y)+ 'z' + str(P1z))
myTxt_XYZ(P2x,P2y,P2z,'x' + str(P2x) + 'y' + str(P2y)+ 'z' + str(P2z))
myTxt_XYZ(P3x,P3y,P3z,'x' + str(P3x) + 'y' + str(P3y)+ 'z' + str(P3z))
myTxt_XYZ(P4x,P4y,P4z,'x' + str(P4x) + 'y' + str(P4y)+ 'z' + str(P4z))
myCube(6.0)
App.ActiveDocument.recompute()
Gui.activeDocument().activeView().viewAxonometric()
Gui.SendMsgToActiveView("ViewFit")