hexagon logo

Delete matrix values with python

I have a 3 column by N row matrix that is created by tracing a marker with respect to ground. I need to delete a row from this matrix with a python script. It would be nice to be able to do this to any row, but my immediate need is to remove the first row (or the first three values). I can get a reference to the matrix with no issue, but there is something I am missing in order to delete values. Any thoughts please?
 
  • Hi Todd,
     
    This is easy in standard Python, but the relationship between the gcurve, curve & matrix objects is a little odd when you first look at it. Here is a function that removes a row - it hasn't been tested much and it's ugly, but it works for a simple example:
    def gcurve_remove_row(curve_name, rownum):
    import Adams
    gc = Adams.stoo(curve_name)
    curve_ref = gc.ref_curve
    m = curve_ref.matrix
    if (rownum > 0) and (rownum <= m.row_count):
    data = m.values
    remove_start = (rownum - 1) * 3
    remove_end = remove_start + 2 + 1
    start_array = data[:remove_start]
    end_array = data[remove_end:]
    print('start array: ', start_array)
    print('end array: ', end_array)
    newdata = start_array + end_array
    m.modify(values=newdata, row_count=m.row_count-1, column_count=3)
    curve_ref.matrix = m # triggers update of gcurve?
     
    else:
    print('curve matrix has {} rows. Cannot remove index {}.'.format(m.row_count, rownum))
     
    gcurve_remove_row('gcurve_1', 2)