[Python] Extracting coordinates from ANSYS .inp file in Python

Discussão em 'Python' iniciado por Stack, Janeiro 22, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on a project that involves manipulating node coordinates from an ANSYS .inp file. I'm trying to extract the node coordinates, modify them (e.g., multiply the z-coordinate by 1.5), and then write the modified data back to a file. However, I'm encountering difficulties parsing the file correctly due to its specific format. Here's an example of the node coordinate data in the .inp file:

    The format is: Node ID (integer), a zero value, and X, Y, Z coordinates (scientific notation).


    1 0 0-3.3131786040000E-002 4.5036802300000E-002-1.2229753440000E-001
    2 0 0-2.7267243100000E-002 3.7109654860000E-002-1.2437740980000E-001
    3 0 0-2.0034116490000E-002 3.0278565420000E-002-1.2621129580000E-001


    The challenges I'm facing: There are no spaces between the Y and Z coordinates, I've tried using regular expressions and converting it to other file types such as csv, but I haven't been able to correctly extract the coordinates. What would be the most efficient way to extract the node coordinates correctly? I am coding in Python. Any help/advice is greatly appreciated!

    I've tried using regular expressions and converting it to other file types such as csv, but I haven't been able to correctly extract the coordinates. Here's an example output from when I tried converting the inp file into a csv file.

    Node_ID,X,Y,Z


    1,-3.3131786040000E-0,0,2


    2,-2.7267243100000E-0,0,2


    3,-2.0034116490000E-0,0,2

    Continue reading...

Compartilhe esta Página