Node
Represents a 3D point in space with ID. It facilitates node creation, synchronization, and deletion.
Note.
All the codes below assumes the initial import and MAPI Key definition.
from midas_civil import *
MAPI_KEY('eyJ1ciI6InN1bWl0QG1pZGFzaXQuY29tIiwicGciO252a81571d')
Node
Node(x , y , z , id=None , group = '' , merge = 1)
Parameters
x, y, z: Coordinates of the node.id (default=None): Manually assign an ID. If None, ID will be auto-assigned.group (default=''): Structure group of the node (can be str or list eg. 'SG' or ['SG1','SG2'])merge (default=1): If enabled, checks for existing nodes and return their IDs. No additional/duplicate node will be created.
Node.SE
Node.SE(s_loc: list, e_loc: list, n: int = 1, id=None , group = '' , merge = 1)
Parameters
s_loc: Start location. [x,y,z]e_loc: End location. [x,y,z]n (default=1): Number of division. n+1 nodes are created.id (default=None): Manually assign an ID. If None, ID will be auto-assigned.group (default=''): Structure group of the node (can be str or list eg. 'SG' or ['SG1','SG2'])merge (default=1): If enabled, checks for existing nodes and return their IDs. No additional/duplicate node will be created.
Node.SDL
Node.SDL(s_loc: list, dir: list, l: float, n: int = 1, id=None , group = '' , merge = 1)
Parameters
s_loc: Start location. [x,y,z]dir: Direction vector [dx, dy, dz]l: Total length of created nodes (seeElement.Beam.SDL).n (default=1): Number of division. n+1 nodes are created.id (default=None): Manually assign an ID. If None, ID will be auto-assigned.group (default=''): Structure group of the node (can be str or list eg. 'SG' or ['SG1','SG2'])merge (default=1): If enabled, checks for existing nodes and return their IDs. No additional/duplicate node will be created.
Node.fromList
Node.SDL(nodesList: list, id=None , group = '' , merge = 1)
Parameters
nodesList: List of[x, y, z]coordinates. e.g.[[0,0,0], [1,0,0], [2,0,0]].id (default=None): Manually assign an ID. If None, ID will be auto-assigned.group (default=''): Structure group of the node (can be str or list eg. 'SG' or ['SG1','SG2'])merge (default=1): If enabled, checks for existing nodes and return their IDs. No additional/duplicate node will be created.
Object Attributes
X, Y, Z: Coordinates of the node.
ID: Unique identifier.
LOC: (x,y,z) Coordinates of the node in tuple.
AXIS: Local direction of the node eg. [(1,0,0),(0,1,0),(0,0,1)] represent local X,Y,Z respectively. Created by bLocalAxis option of Beam element.
Retrieve Node by ID
nodeByID(id:int) : Returns NODE object with given ID.
Class Attributes
Node.nodes -> List of all nodes.
n1 = Node(0,1,2,10) # Create Node at 0,1,2 with ID = 10
n2 = Node(0,3,4,20) # Create Node at 0,3,4 with ID = 20
for n in Node.nodes:
print(f' NODE ID = {n.ID} | X = {n.X} , Y = {n.Y} , Z = {n.Z}')
# Output :
# NODE ID = 10 | X = 0 , Y = 1 , Z = 2
# NODE ID = 20 | X = 0 , Y = 3 , Z = 4
Methods
Node.json
Returns a JSON representation of all Nodes defined in python.
n1 = Node(0,1,2,10) # Create Node at 0,1,2 with ID = 10
n2 = Node(0,3,4,20) # Create Node at 0,3,4 with ID = 20
print(Node.json())
# Output :
# {'Assign': {10: {'X': 0, 'Y': 1, 'Z': 2}, 20: {'X': 0, 'Y': 3, 'Z': 4}}}
Node.create
Sends the current node list to the Civil NX using a PUT request.
New nodes are created and existing nodes(same ID) in Civil NX will be updated.
n1 = Node(0,1,2,10) # Create Node at 0,1,2 with ID = 10
n2 = Node(0,3,4,20) # Create Node at 0,3,4 with ID = 20
Node.create()
Node.get
Fetches nodes from the Civil NX and return the JSON representation.
-Here, Civil model had 2 nodes
print(Node.get())
# Output
# {'NODE': {'1': {'X': 1, 'Y': 2, 'Z': 3}, '2': {'X': 1, 'Y': 3, 'Z': 2}}}
Node.sync
Retrieves Node data from the Civil NX and rebuilds the internal node list.
-Here, Civil model had 2 nodes
Node.sync()
for n in Node.nodes:
print(f' NODE ID = {n.ID} | X = {n.X} , Y = {n.Y} , Z = {n.Z}')
# Output
# NODE ID = 1 | X = 1 , Y = 2 , Z = 3
# NODE ID = 2 | X = 1 , Y = 3 , Z = 2
Node.clear
Deletes all node data from Python.
Node.clear()
Node.delete
Deletes all node data from both Python and Civil NX.
Node.delete()
Examples
1. Sine Grid
import math
n=50
for j in range(n):
for i in range(n):
Node(i,j,2*(math.sin(i/5)+math.sin(j/5)),100*i+j+1)
Node.create()
2. Sphere Nodes
import math
n=50
R=5
phi=0
for j in range(40):
for i in range(n):
theta = i*2*math.pi/n
Node(R*math.sin(theta)*math.cos(phi),R*math.cos(theta),R*math.sin(theta)*math.sin(phi))
phi+=math.pi/16
Node.create()
3. Rotating Nodes
import math
n=50
R=5
phi=0
for j in range(40):
for i in range(n):
theta = i*2*math.pi/n
Node(R*math.sin(theta)*math.cos(phi),R*math.cos(theta),R*math.sin(theta)*math.sin(phi),i+1)
phi+=math.pi/16
Node.create()