hexagon logo

How to add rows to existing spline with Python?

I am a beginner in the "Python in Adams" world. I would like to create a function which makes it possible to add (and later remove) a given number of rows to an existing spline.
 
As I sometime have to copy/paste splines into Adams, it happens that I have to add (or delete) a large amount of rows before I can do so in order to match the length of the spline with the new input. Doing that manually is not fun if that number is big so I thought this could be a nice first tool to code in Python.
 
I started to write a function called "add_lines".
The inputs are:
  1. spline_id: id of the spline to be updated
  2. n_lines: number of lines to be added
 
It works fine until I try to add the new empty rows. By empty I mean [0,0]. My approach doesn't seem correct and I am wondering how I should proceed.
 
I am able to access the spline of interest and get the current values. But I don't know how to add or remove lines. Here is what I tried to do:
iSpline[spline_id].x=iSpline[spline_id].x+[0]*n_lines
 
The error I get is "ERROR: The number of X values for spline .MODEL_1.SPLINE_1 must be the same as the number of Y values."
 
I understand what the problem is (when I do that X is longer than Y) but I am wondering what the correct way of doing it would look like.
 
Thanks for the help.
Parents
  • Thanks Martin. I ended up doing something similar to what you suggest: using cmd language in my Python code:
     
    command ='data_element modify spline spline=.MODEL_1.{0} x={1} y={2} linear_extrapolate=no '.format(spline_name,newXvalues, newYvalues)
    Adams.execute_cmd(command )
     
    I still did not find a way to do that directly with Python code.
Reply
  • Thanks Martin. I ended up doing something similar to what you suggest: using cmd language in my Python code:
     
    command ='data_element modify spline spline=.MODEL_1.{0} x={1} y={2} linear_extrapolate=no '.format(spline_name,newXvalues, newYvalues)
    Adams.execute_cmd(command )
     
    I still did not find a way to do that directly with Python code.
Children
No Data