Create an array of spheres in Spaceclaim

Erik Kostson
Erik Kostson Member, Employee Posts: 233
50 Answers 100 Comments Second Anniversary 25 Likes
✭✭✭✭
edited March 13 in 3D Design

Do we have an example of creating an array/multiple spheres, based on their location (x,y,z) and radius (this information could be given in a text file say, with 4 columns, corresponding to x,y,z,radius)?

Comments

  • Erik Kostson
    Erik Kostson Member, Employee Posts: 233
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited March 8

    Below is an example that does that (reads in a text file with the format described above - has 4 columns with x,y,z,radius - see image below on this format).

    import csv
    with open('D:\spherelocradt.txt', 'rb') as f:
        reader = csv.reader(f)
        for row in reader:
            x=(float(row[0]))
            y=(float(row[1]))
            z=(float(row[2]))
            x1=(float(row[0])-float(row[3]))
            SphereBody.Create(Point.Create(MM(float(x)), MM(float(y)), MM(float(z))), 
            Point.Create(MM(float(x1)), MM(float(y)), MM(float(z))), ExtrudeType.None)
    
    
  • Erik Kostson
    Erik Kostson Member, Employee Posts: 233
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited March 13

    If the text file is tab delimited we can replace in the script above all the lines reading the data so upto SphereBody.Create. Also if it is space separated we can replace the "\t" with "\s".

    myt=[]
    f=open('D:\spherelocradtab.txt', 'r')
    for line in f:
        myt=(line.split("\t"))
        x=(float(myt[0]))
        y=(float(myt[1]))
        z=(float(myt[2]))
        x1=(float(myt[0])-float(myt[3]))
    
This discussion has been closed.