Get Node Displacement Results using CPython3

Get Node Displacement Results using CPython3

stefanyC6JZ7
Enthusiast Enthusiast
285 Views
2 Replies
Message 1 of 3

Get Node Displacement Results using CPython3

stefanyC6JZ7
Enthusiast
Enthusiast

Hi all, 

We are currently upgrading our scripts from IronPhyton 2 to CPhyton 3.

I want to get the results of node displacement using CPython3. The code in IronPython2 cretes 6 lists of results in UX,UY,UZ,RX,RY,and RZ, please see picture below. 

stefanyC6JZ7_0-1661160415826.png

In CPython3 I get the following error: Warning: AttributeError : '__ComObject' object has no attribute 'UX' [' File "<string>", line 41, in <module>\n']. 

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# add Robot Structural Analysis API reference
from System import Environment
# get the current user folder i.e C:\Users\<you>\AppData\Roaming
user = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
sys.path.append(user+r"\Dynamo\Dynamo Core\2.11\packages\Structural Analysis for Dynamo\bin\RSA\Interop.RobotOM.dll")
clr.AddReference('interop.RobotOM')
#clr.AddReference(user+r"\Dynamo\Dynamo Core\2.11\packages\Structural Analysis for Dynamo\bin\RSA\Interop.RobotOM.dll")

# add needed import to be able to use Robot Structural Analysis objects
from RobotOM import *
from System import Object

# get input data 
# input 0 is just a result that indicates if the calculation ran ok.
# also makes sure we get loads AFTER running analysis.
calculateOutcome = IN[0]
# list of robot bar IDs that you want loads from:
inputNodeIDs = IN[1]
All_Case_Comb_nr = IN[2]
# Connect to the running instance of Robot Structural Analysis
application = RobotApplicationClass()
# Get a reference of the current project
project = application.Project
structure = project.Structure

NodeDisplacement = []
NodeDisplacement.append([])
NodeDisplacement.append([])
NodeDisplacement.append([])
NodeDisplacement.append([])
NodeDisplacement.append([])
NodeDisplacement.append([])

node =  IRobotNodeDisplacementServer
node_dis = IRobotDisplacementData
for l in range(len(All_Case_Comb_nr)): 
    NodeDisplacement[0].append(structure.Results.Nodes.Displacements.Value(inputNodeIDs[0],All_Case_Comb_nr[l]).UX*1000)
    NodeDisplacement[1].append(structure.Results.Nodes.Displacements.Value(inputNodeIDs[0],All_Case_Comb_nr[l]).UY*1000)
    NodeDisplacement[2].append(structure.Results.Nodes.Displacements.Value(inputNodeIDs[0],All_Case_Comb_nr[l]).UZ*1000)
    NodeDisplacement[3].append(structure.Results.Nodes.Displacements.Value(inputNodeIDs[0],All_Case_Comb_nr[l]).RX*1000)
    NodeDisplacement[4].append(structure.Results.Nodes.Displacements.Value(inputNodeIDs[0],All_Case_Comb_nr[l]).RY*1000)
    NodeDisplacement[5].append(structure.Results.Nodes.Displacements.Value(inputNodeIDs[0],All_Case_Comb_nr[l]).RZ*1000)
    OUT = NodeDisplacement

	

I have been trying to change the code with the following classes, but It is not working. 

node =  IRobotNodeDisplacementServer
node_dis = IRobotDisplacementData

 

Could you help me to solve the issue? 

Thank you in advance. 

 

Best regards, 

Stefany 

 

 

 

0 Likes
Accepted solutions (1)
286 Views
2 Replies
Replies (2)
Message 2 of 3

stefanyC6JZ7
Enthusiast
Enthusiast

Hi all, 

I have seen your names in similar topics, maybe one of you can help me out?

@JacquesGaudin @cool.stuff @chjpcoi 

 

Thank you in advance. 

 

Best regards, 

Stefany 

0 Likes
Message 3 of 3

JacquesGaudin
Advocate
Advocate
Accepted solution

I think this one is quite easy, just cast the result of the `Value` method to IRobotDisplacementData and it should be ok.

 

Note that rather than calling six time the `Value` method, you're better off calling it once and storing the result in a variable.

 

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# add Robot Structural Analysis API reference
from System import Environment
# get the current user folder i.e C:\Users\<you>\AppData\Roaming
user = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
sys.path.append(user+r"\Dynamo\Dynamo Core\2.11\packages\Structural Analysis for Dynamo\bin\RSA\Interop.RobotOM.dll")
clr.AddReference('interop.RobotOM')
#clr.AddReference(user+r"\Dynamo\Dynamo Core\2.11\packages\Structural Analysis for Dynamo\bin\RSA\Interop.RobotOM.dll")

# add needed import to be able to use Robot Structural Analysis objects
from RobotOM import *
from System import Object

# get input data
# input 0 is just a result that indicates if the calculation ran ok.
# also makes sure we get loads AFTER running analysis.
calculateOutcome = IN[0]
# list of robot bar IDs that you want loads from:
inputNodeIDs = IN[1]
All_Case_Comb_nr = IN[2]
# Connect to the running instance of Robot Structural Analysis
application = RobotApplicationClass()
# Get a reference of the current project
project = application.Project
structure = project.Structure

NodeDisplacement = []
NodeDisplacement.append([])
NodeDisplacement.append([])
NodeDisplacement.append([])
NodeDisplacement.append([])
NodeDisplacement.append([])
NodeDisplacement.append([])

for l in range(len(All_Case_Comb_nr)):
    disp_value = IRobotDisplacementData(structure.Results.Nodes.Displacements.Value(
        inputNodeIDs[0],
        All_Case_Comb_nr[l]
    ))
    NodeDisplacement[0].append(disp_value.UX*1000)
    NodeDisplacement[1].append(disp_value.UY*1000)
    NodeDisplacement[2].append(disp_value.UZ*1000)
    NodeDisplacement[3].append(disp_value.RX*1000)
    NodeDisplacement[4].append(disp_value.RY*1000)
    NodeDisplacement[5].append(disp_value.RZ*1000)
    OUT = NodeDisplacement
0 Likes