Errors raised by Python Nodes during first run

I have written some Python nodes to incorporate into my Dynamo script to set up models in Robot and have been encountering problems. The nodes are designed to assign properties to bars that are created at an earlier point in the script using nodes from the Structural Analysis library.

The first time I run the script, errors are raised at the Python nodes. It appears that the Dynamo script is reaching this point, but cannot find any bars in my model. When I run the script a second time, it runs without any errors.

Has anyone else encountered this problem?

make sure the prior step in your script is actually a dependency of the later nodes in your script - if they are separate branches of the graph there is no way to assign which one will run first.

An alternative is to use [imperative] ds code.

1 Like

A wait for trigger method can also work if your python nodes all have some degree of input (note: this input doesn’t even need to do anything). A code block like this will suffice:

{WaitForThis,BeforeYouPullThisTrigger}[1];

I have the exact same problem. Did you find a solution?

I have tried using:

import time
time.sleep(seconds)

but, without success…

I wonder if the problem is that objects hasn’t been created yet in Robot even though the information for creating them has been sent…

My code:
#####################################################################
# Enable Python support and load DesignScript library
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)
# add the reference to the interop file shipped with the package
clr.AddReferenceToFileAndPath(user +r"\Dynamo\Dynamo Core\2.0\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

# The inputs to this node will be stored as a list in the IN variables.
name = IN[0]
kX = IN[1]
kY = IN[1]

# Place your code below this line

# Connect to the running instance of Robot Structural Analysis
application = RobotApplicationClass()
# Get a reference of the current project
project = application.Project
# Get a reference of the current model
structure = project.Structure
# Get a reference of the label server
labels = structure.Labels
# create a new label of type thickness with the name passed as parameter

out = labels.Create(IRobotLabelType.I_LT_SUPPORT, name)
out.Data.ElasticSurface=True;
out.Data.KX=kX
out.Data.KY=kY
out.Data.UX=0
out.Data.UY=0
out.Data.UZ=0

labels.Store(out)

# Assign your output to the OUT variable.
OUT = out.Name

#####################################################################

My error message:
#####################################################################
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 34, in
EnvironmentError: System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.
at Microsoft.Scripting.ComInterop.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message)
at CallSite.Target(Closure , CallSite , Object , Object , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at Microsoft.Scripting.Interpreter.DynamicInstruction4.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run5[T0,T1,T2,T3,T4,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3) at Microsoft.Scripting.Interpreter.DynamicInstruction5.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
at DSIronPython.IronPythonEvaluator.EvaluateIronPythonScript(String code, IList bindingNames, IList bindingValues)
#####################################################################

Please post using preformatted text :slight_smile: it might suffice to say that you’re trying to create a new support :slight_smile: please also show your dynamo graph :slight_smile: I am very certain that it is a timing issue :slight_smile:

Also my guess is that this should be a bool and not a string :slight_smile:

1 Like

And that the “t” should be a capital letter :slight_smile:

Also,

Is this intended ?

Yes, it is intended. Horizontal stiffness of soil is the same in both x and y-direction.

The code works when it is reconnected after the first run. So, as far as I understand it is nothing wrong with the code, because I get what I want after the reconnection.

I will in the future :wink: do you have a suggestion for how the timing can be changed?

Yes have around 20 ideas… Pinpointing the correct one would require me to see your dynamo graph :wink:

Also, I’ll add the code in a readable format… (Made some slight changes as you’re only using the label server).

#Enable Python support and load DesignScript library
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)

#add the reference to the interop file shipped with the package
clr.AddReferenceToFileAndPath(user +r"\Dynamo\Dynamo Core\2.0\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

#The inputs to this node will be stored as a list in the IN variables.
name = IN[0]
kX = IN[1]
kY = IN[1]

#Connect to the running instance of Robot Structural Analysis
application = RobotApplicationClass()

#Get a reference of the label server
labels = application.Project.Structure.Labels

#create a new label of type thickness with the name passed as parameter
out = labels.Create(IRobotLabelType.I_LT_SUPPORT, name)
out.Data.ElasticSurface=True
out.Data.KX=kX
out.Data.KY=kY
out.Data.UX=0
out.Data.UY=0
out.Data.UZ=0
labels.Store(out)

#Assign your output to the OUT variable.
OUT = out.Name

Try and have a read in the API, the “ElasticSurface” property is stored in a 0,1 or True/False property…

EDIT: Arrow moved down to “ElasticSurface”

The same thing can be found if you probe around the Interop.RobotOM.dll:
image

1 Like

Thanks :slight_smile:

The script works if I only open Robot before opening dynamo. I see what you mean with the documentation, so it is weird that it goes through…

Sorry about being slow on changing the text, was in a meeting.
And, I’m new to the forum… so sorry for being a newbie! :wink:

No problem :slight_smile:

The reason why it doesn’t fail is that the use of the wrong flag will not result in a critical error, it will simply be assumed “different from zero” :wink:

Just because something doesn’t return an error does not make it successful :stuck_out_tongue:

I cannot replicate your issue… Opening Dynamo -> Start Dynamo Graph in “Manual” mode -> Open RSA -> Start Blank project -> Run Dynamo -> Inspect your newly created support :slight_smile: