Python script returns “HResult E_FAIL for calling a COM-object” error

Python script returns “HResult E_FAIL for calling a COM-object” error

m_hoebe
Explorer Explorer
509 Views
5 Replies
Message 1 of 6

Python script returns “HResult E_FAIL for calling a COM-object” error

m_hoebe
Explorer
Explorer

 

Hello Everyone,

 

When running my python script in dynamo for rsa, the following error occurs:

“IronPythonEvaluator.EvaluateIronPyth onScript operation failed.
Traceback (most recent call last):
File “”, line 34, in
EnvironmentError: System.Runtime.InteropServices.COMException
(0x80004005): Fout HRESULT
E_FAIL is geretourneerd voor een aanroep van een COM-onderdeel. bij
Microsoft.Scripting.ComInterop.ComRuntimeHelpers.CheckThrowException
(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message)
bij CallSite.Target(Closure, CallSite, Object, Object) bij
System.Dynamic.UpdateDelegates.UpdateAndExecute2[TO,T1,TRet] (CallSitesite, TO arg0, T1 arg1)
bij CallSite.Target(Closure, CallSite, Object, Object) bij
Microsoft.Scripting.Interpreter.DynamicInstruction 3.Run(Interpreted Frameframe) bij
Microsoft.Scripting.Interpreter.Interpre ter.Run(Interpreted Frame frame) bij
Microsoft.Scripting.Interpreter.LightLa mbda.Run4[TO,T1,T2,T3,TRet](TO arg0,T1 arg1, T2 arg2, T3 arg3) bij
System.Dynamic.UpdateDelegates.UpdateAndExecute3[TO,T1,T2,TRet](CallSitesite, TO arg0, T1 arg1, T2 arg2) bij
Microsoft.Scripting.Interpreter.DynamicInstruction 4.Run(Interpreted Frameframe) bij
Microsoft.Scripting.Interpreter.Interpre ter.Run(Interpreted Frame frame) bij
Microsoft.Scripting.Interpreter.LightLambda.Run2[TO,T1,TRet](TO arg0, T1arg1) bij
Iron Python.Compiler.PythonScriptCode. RunWorker(CodeContext ctx) bij
Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope) bij
DSIron Python.Iron Python Evaluator.Eva luate(String code, IList bindingNames, IList bindingValues)”
(pardon me for the length, just trying to be as complete as possible)

 

The weird thing is that when I disconnect an input string → run the model → then reconnect the same input string → run the model again, the script does work without the error. It also works when I change something insignificant in the script. The problem is that I don’t want to keep doing one of the above everytime I use the scriptm_hoebe_0-1679481997913.png. Does someone know what i’m doing wrong?

 

This is my code:

 

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.13\packages\SAD\bin\RSA\interop.RobotOM.dll")

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

GrondprofielName = IN[0]
GrondprofielData = IN[1]
barNumber = IN[2]

application = RobotApplicationClass()
project = application.Project
structure = project.Structure
labels = structure.Labels
bars = structure.Bars

out = labels.Create(IRobotLabelType.I_LT_BAR_ELASTIC_GROUND, GrondprofielName)

out.Data.Ky = GrondprofielData[0]
out.Data.Kz = GrondprofielData[1]

labels.Store(out)

for i in range(len(barNumber)):
	bar = structure.Bars.Get(barNumber[i])
	bar.SetLabel(IRobotLabelType.I_LT_BAR_ELASTIC_GROUND, GrondprofielName)

 

 

This is my dynamo input:

2ee19f6f73b0b92632f7d2b1e91a43846f0e964b.jpeg

 

Thanks in advance!

0 Likes
510 Views
5 Replies
Replies (5)
Message 2 of 6

Stephane.kapetanovic
Mentor
Mentor

hi @m_hoebe 

If the error occurs on line 34 and it matches the collect of the bar object then you need to check if an incorrect variable type or wrong type definition is not present. difficult to see. I see barNumber[i]. what does this table contain [1,2,3,4], are these numbers (int), does the bar number exist in the model? Another example you defined "bars" but don't seem to use it in your snippet. You can define also "bar" type as RobotBar

Best regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
0 Likes
Message 3 of 6

m_hoebe
Explorer
Explorer

Hi Stephane,

 

Thanks for replying. I think the bars do not exist yet when the script runs. That would mean it is a timing issue. But I do not know how to fix it. I have tried using the wait command to let the script wait for the input but it doesn't seem to work. Maybe there is another solution i'm not seeing.

 

0 Likes
Message 4 of 6

Stephane.kapetanovic
Mentor
Mentor

hi @m_hoebe 

you mean there are no bars? Could you clarify ?
Creating a bar is a different code than accessing to apply labels.

Best Regards

 

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
0 Likes
Message 5 of 6

m_hoebe
Explorer
Explorer

Hi Stephane,

 

I do create the bars with different nodes in the same project but I presume the python script is carried out before those bars are created, which is why I think the error occurs. But that is a wild guess.

0 Likes
Message 6 of 6

Stephane.kapetanovic
Mentor
Mentor

hi @m_hoebe 

so if the bars may not exist and bar type allready defined I can only advise you to combine the two scripts to be sure of their operating order.

bar = RobApp.Project.Structure.Bars.Create(num, start_node, end_node)

Best Regards

Stéphane Kapetanovic

Did you find this post helpful? If it gave you one or more solutions,
don't forget to accept the solution and leave a < like !
EESignature
0 Likes