How can I access Create3DContext method?

Options
Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 813
First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
edited June 2023 in Structures

I've tried to use ExtAPI.Graphics.CreateAndOpenDraw3DContext() but I get a warning message stating that this method is obsolete and I should use Create3DContext method instead :

But where can I find this new method ?

Tagged:

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 813
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Answer ✓
    Options

    Create3DContext is actually not a single method but all the methods created in order to modify the graphics window.

    Below are some examples:

    elems = ExtAPI.DataModel.MeshDataByName('Global').Elements
    elem = ExtAPI.Graphics.Scene.Factory3D.CreateMesh(list(elems)[:5])
    
    body = ExtAPI.DataModel.GeoData.Assemblies[0].Parts[0].Bodies[0]
    geo = ExtAPI.Graphics.Scene.Factory3D.CreateGeometry(body)
    
    Point2D = ExtAPI.Graphics.CreatePixelPoint
    Point3D = ExtAPI.Graphics.CreateWorldPoint
    Vector3D = ExtAPI.Graphics.CreateVector3D
    
    graphics = ExtAPI.Graphics
    
    triad = graphics.Scene.Factory3D.CreateTriad(1.0)
    
    arrow = graphics.Scene.Factory3D.CreateArrow(0.5)
    arrow.Color = 0xFF0000
    arrow.Transformation3D.Translate(Vector3D(0.5,0.5,1))
    
    box = graphics.Scene.Factory3D.CreateBox(2.0, 3.0, 4.0)
    box.Color = 0xFF0000
    
    cone = graphics.Scene.Factory3D.CreateCone(3.0, 2.0, 1.0)
    cone.Color = 0xFF0000
    
    sphere = graphics.Scene.Factory3D.CreateSphere(2.0)
    sphere.Color = 0xFF0000
    
    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 = Point3D(0,0,0)
        p6 = Point2D(100,100)
        l2 = graphics.Scene.Factory2D.CreatePolyline([p5, p6])
    
        p7 = Point2D(20,40)
        text = graphics.Scene.Factory2D.CreateText(p7, "Coucou")
    
        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)
    
    
        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))