i am trying to automate some operations using python, on ANSA I wonder if you have some scrips that I can use to fit my needs, and I'll be grateful if you have a script which can read coordinate from an xlsx file and generates SPRING (im working with Deck>PAMCRASH)
you can find below the current script, till now i have succeeded to: - read & create POINTS from (csv) file - create NODES and SPRINGS from those nodes but i can't find the link between the two parts ( i need to convert the POINTS from csv file to NODES or Create SPRINGS from POINTS directly ) ----> other way: 1- how to extract values from a table 2- fill in a new table from these values
import ansa
from ansa import *
def main():
# import csv file and create POINTS
file = 'C:/Users/ejjed/Desktop/Scripting/Test.csv'
list_points = ansa.base.ImportCSVFileCreatePoints( file )
# create set of NODES
vals = {'Name':'new set'}
set = base.CreateEntity(constants.PAMCRASH, "GROUP", vals)
# create NODES
nodes_list = []
for i in range(5):
vals = { "X": i, "Y": i, "Z": i }
n = base.CreateEntity(constants.PAMCRASH, "NODE",vals)
base.AddToSet(set, nodes_list)
# create SPRING from NODES
vals_property = {"IDPRT":111, "Name": "new property"}
property =base.CreateEntity(constants.PAMCRASH,"PART_SPRING ",vals_property)
vals_element = {"M":1,"IPART":111,"N1":1,"N2":5,}
SpringEle = base.CreateEntity(constants.PAMCRASH, "SPRING",vals_element)
cordially
1 Answer 1
you are creating nodes at (0,0,0) (1,1,1) (2,2,2) (3,3,3) and (4,4,4) instead you should use values from the csv file for creating nodes
considering that you have data from csv in form of a list eg:
csvdata=[123,456,486]
you can try following lines to create nodes at the coordinates from csv:
vals = { "X": csvdata[0], "Y": csvdata[1], "Z": csvdata[2] }
n = base.CreateEntity(constants.PAMCRASH, "NODE",vals)
if you want to make any changes in an existing node use setentitycardvalue api
hope it helps