2

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

hiro protagonist
47.4k17 gold badges93 silver badges119 bronze badges
asked Feb 21, 2019 at 15:18

1 Answer 1

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

CKE
1,63819 gold badges21 silver badges33 bronze badges
answered Dec 9, 2019 at 5:46
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.