DirectShape: Create Sphere Geometry

.

import clr, math
clr.AddReference('System')
from System.Collections.Generic import List



def CreateCenterbasedSphere(center, radius):

    frame = Frame(center,
            XYZ.BasisX,
            XYZ.BasisY,
            XYZ.BasisZ)
    
    profileloops = List[CurveLoop]() 
    profileloop  = CurveLoop()
    
    cemiEllipse = Ellipse.CreateCurve(center, radius, radius,
                                        XYZ.BasisX,
                                        XYZ.BasisZ,
                                        -math.pi / 2.0, math.pi / 2.0)
    
    profileloop.Append(cemiEllipse);
    profileloop.Append(Line.CreateBound(
    XYZ(center.X, center.Y, center.Z + radius),
    XYZ(center.X, center.Y, center.Z - radius)))
    profileloops.Add(profileloop);
    
    return GeometryCreationUtilities.CreateRevolvedGeometry(frame, profileloops, -math.pi, math.pi)
    

# Create Sphere
pt = XYZ(1,1,1)
r  = 1
sphere = CreateCenterbasedSphere(pt, r)

print(sphere)

# Transaction
t = Transaction(doc, 'test')
t.Start()

# Create DS Shape


ds = DirectShape.CreateElement(doc, ElementId(BuiltInCategory.OST_GenericModel))
ds.SetShape([sphere])

t.Commit()

⌨️ Happy Coding!
Erik Frits