Assign thickness values defined in a csv file to surfaces in Spaceclaim?

Options
Erik Kostson
Erik Kostson Member, Employee Posts: 102
First Answer Name Dropper First Anniversary Ansys Employee
edited June 2023 in 3D Design

How can we automatically assign thickness values defined in a csv file to surfaces in Spaceclaim?

Best Answer

  • Erik Kostson
    Erik Kostson Member, Employee Posts: 102
    First Answer Name Dropper First Anniversary Ansys Employee
    edited June 2023 Answer ✓
    Options

    Below is a sample code that does that. It is assuming that the pre-existing csv file (file called mythick.csv in D drive) has one column with the surface names in Spaceclaim and one with their thicknesses.

    Note: for the below to work we need to have insert selection set to index.

    # Python Script, API Version = V22
    
    import csv
    
    th=[]
    
    names=[]
    
    with open('D:\mythick.csv', 'rb') as f:
    
        reader = csv.reader(f)
    
        for row in reader:
    
            th.append(row[1])
    
            names.append(row[0])
    
    allBodies = GetRootPart().GetAllBodies()
    
    i=0
    
    for name in names:
    
        for body in allBodies:
    
            if body.GetName()==name:
    
                print(body.GetName())
    
                result = Midsurface.Convert(BodySelection.Create(body), MM(float(th[i])))
    
        i=i+1