Goal: Add several example draw functions that can be used to draw entities in the Mechanical graphics window.
Code:
def DrawElements():
elems = DataModel.MeshDataByName('Global').Elements
elem = Graphics.Scene.Factory3D.CreateMesh(list(elems)[:5])
elem.Color = 0xA00ABC
def DrawBody():
body = DataModel.GeoData.Assemblies[0].Parts[0].Bodies[0]
geo = Graphics.Scene.Factory3D.CreateGeometry(body)
geo.Color = 0xAAA000
def DrawFace():
face = DataModel.GeoData.Assemblies[0].Parts[0].Bodies[0].Faces[0]
geo = Graphics.Scene.Factory3D.CreateGeometry(face)
geo.Color = 0xABCABC
def DrawEdge():
edge = DataModel.GeoData.Assemblies[0].Parts[0].Bodies[0].Faces[0].Edges[1]
geo = Graphics.Scene.Factory3D.CreateGeometry(edge)
geo.LineWeight = 14
geo.VertexColor = 0x0000AA
geo.VertexSize = 15
geo.Color = 0x000ABC
def DrawVertex():
vertex = DataModel.GeoData.Assemblies[0].Parts[0].Bodies[0].Faces[0].Edges[0].Vertices[0]
geo = Graphics.Scene.Factory3D.CreateGeometry(vertex)
geo.Color = 0xBACBAC
def DrawTriad():
triad = Graphics.Scene.Factory3D.CreateTriad(1.0)
def DrawArrow():
Vector3D = Graphics.CreateVector3D
arrow = Graphics.Scene.Factory3D.CreateArrow(0.5)
arrow.Color = 0xFFABC0
arrow.Transformation3D.Translate(Vector3D(0.5, 0.5, 1))
def DrawBox():
box = Graphics.Scene.Factory3D.CreateBox(2.0, 3.0, 4.0)
box.Color = 0xFF0ABC
def DrawCircle():
cone = Graphics.Scene.Factory3D.CreateCircle(0.5)
cone.Color = 0xAAACCC
def DrawCone():
cone = Graphics.Scene.Factory3D.CreateCone(3.0, 2.0, 1.0)
cone.Color = 0xABC000
def DrawCylinder():
cone = Graphics.Scene.Factory3D.CreateCylinder(0.5, 2)
cone.Color = 0xAAA000
def DrawDisc():
cone = Graphics.Scene.Factory3D.CreateDisc(0.5)
cone.Color = 0xAAABBB
def DrawQuad():
sphere = Graphics.Scene.Factory3D.CreateQuad(0.33, 0.33)
sphere.Color = 0xFFA000
def DrawShell():
shell = Graphics.Scene.Factory3D.CreateShell([1., 1., 1. ,2., 1., 1., 1., 1. ,2.], [0., 1., 0., 0., 1., 0., 0., 1., 0.], [0, 1, 2])
shell.Color = 0xFFFFFF
def DrawSphere():
sphere = Graphics.Scene.Factory3D.CreateSphere(0.33)
sphere.Color = 0xFF0A00
def DrawPolyline3D():
Point2D = Graphics.CreatePixelPoint
Point3D = Graphics.CreateWorldPoint
Vector3D = Graphics.CreateVector3D
with Graphics.Suspend():
p1 = Point2D(10, 10)
p2 = Point2D(10, 100)
p3 = Point2D(100, 100)
p4 = Point2D(100, 10)
coll = Graphics.Scene.CreateChildCollection()
l1 = coll.Factory2D.CreatePolyline([p1, p2, p3, p4])
l1.Closed = True
p5 = Point2D(0, 0)
p6 = Point2D(100, 100)
l2 = Graphics.Scene.Factory2D.CreatePolyline([p5, p6])
p7 = Point2D(20, 40)
text = Graphics.Scene.Factory2D.CreateText(p7, "Hello World 3D")
wp1 = Point3D(0, 5, 0)
wp2 = Point3D(0, 0, 0)
wp3 = Point3D(5, 0, 0)
coll = Graphics.Scene.CreateChildCollection()
l1 = coll.Factory3D.CreatePolyline([wp1, wp2])
l2 = coll.Factory3D.CreatePolyline([wp2, wp3])
#shell = Graphics.Scene.Factory3D.CreateShell([1.,1.,1.,2.,1.,1.,1.,1.,2.], [0.,1.,0.,0.,1.,0.,0.,1.,0.], [0,1,2])
points = []
for i in range(10):
for j in range(10):
for k in range(10):
points.Add(Point3D(float(i)/float(10), float(j)/float(10),float(k)/float(10)))
coll.Factory3D.CreatePoint(points, 4)
return True
for i in range(5):
for j in range(5):
for k in range(5):
point = Point3D(float(i)/float(2), float(j)/float(2),float(k)/float(2))
coll.Factory2D.CreateText(point, str(i + j + k))
def DrawPolyline2D():
Point2D = Graphics.CreatePixelPoint
Point3D = Graphics.CreateWorldPoint
with Graphics.Suspend():
p1 = Point2D(10, 10)
p2 = Point2D(10, 100)
p3 = Point2D(100, 100)
p4 = Point2D(100, 10)
coll = Graphics.Scene.CreateChildCollection()
l1 = coll.Factory2D.CreatePolyline([p1, p2, p3, p4])
l1.Closed = True
p5 = Point2D(0,0)
p6 = Point2D(100,100)
l2 = Graphics.Scene.Factory2D.CreatePolyline([p5, p6])
p7 = Point2D(20,40)
text = Graphics.Scene.Factory2D.CreateText(p7, "Hello World 2D")
wp1 = Point3D(0,5,0)
wp2 = Point3D(0,0,0)
wp3 = Point3D(5,0,0)
coll = Graphics.Scene.CreateChildCollection()
l1 = coll.Factory3D.CreatePolyline([wp1, wp2])
l2 = coll.Factory3D.CreatePolyline([wp2, wp3])
points = []
for i in range(10):
for j in range(10):
points.Add(Point2D(float(i)/float(10), float(j)/float(10)))
coll.Factory2D.CreatePoint(points, 4)
def DrawText2D(pixX,pixY,color):
Point2D = Graphics.CreatePixelPoint
with Graphics.Suspend():
p7 = Point2D(pixX,pixY)
text = Graphics.Scene.Factory2D.CreateText(p7, "Hello World 2D")
text.Color = color
def DrawText3D(x,y,z,color):
Point3D = Graphics.CreateWorldPoint
with Graphics.Suspend():
p7 = Point3D(x,y,z)
text = Graphics.Scene.Factory3D.CreateText3D(p7, "Hello World 3D")
text.Color = color