I am trying to create a link using API between Grasshopper and Robot Structural Analysis to input loading into a model. However, this error message appears when I try to run the script.
Error HRESULT E_FAIL has been returned from a call to a COM component. (line: 0)
Do you try to get the COM object from a script or from a compiled component? If you can do it, it will be easier for debugging that you write a full GH component into VS --> you can do a step by step debug (and figure out where the program throws an exception).
Thanks for your quick response! This is my first time trying to use VB so I had written the script within the Grasshopper window, I’ll try writing in VS in the future if that is better for debugging.
I have shared the code below.
If Activate = True Then
Update = False
Dim robot As New RobotApplication
Dim robot_cache As RobotStructureCache
robot_cache = robot.Project.Structure.CreateCache
Dim comb_num As Long
comb_num = robot.Project.Structure.Cases.FreeNumber
Dim LoadRecIMP As RobotLoadRecord
Dim caseIMP As RobotSimpleCase
caseIMP = robot.Project.Structure.Cases.CreateSimple(comb_num, "Imposed - Snow & Maintenance", IRobotCaseNature.I_CN_EXPLOATATION, IRobotCaseAnalizeType.I_CAT_STATIC_NONLINEAR_BUCKLING)
caseIMP.Records.New(IRobotLoadRecordType.I_LRT_NODE_FORCE)
LoadRecIMP = caseIMP.Records.Get(1)
LoadRecIMP.SetValue(IRobotUniformRecordValues.I_URV_PX, 0)
LoadRecIMP.SetValue(IRobotUniformRecordValues.I_URV_PY, 0)
LoadRecIMP.SetValue(IRobotUniformRecordValues.I_URV_PZ, Imposed)
Dim node_num As int32: node_num = robot.Project.Structure.Nodes.FreeNumber
Dim node_sel_text As String: node_sel_text = ""
For i As int32 = 0 To GH_Panels.Count - 1
robot_cache.AddNode(node_num, GH_Panels(i).X, GH_Panels(i).Y, GH_Panels(i).Z)
node_sel_text = node_sel_text & " " & CStr(node_num)
node_num = node_num + 1
Next i
robot.Project.Structure.ApplyCache(robot_cache)
LoadRecIMP.Objects.FromText(node_sel_text)
Update = True
End If
Unfortunately I don’t know this API, but first thing you can try to do is to identify which line is throwing the exception --> comment all lines after line X and see if it returns, if not, move X upwards and iterate until you find which line is not working.
(disclaimer : this is only my feeling and I am not a professional programmer),
I personaly got a lot of troubles with COM components and I don’t find them easy to understand/use. I feel that trying to use one you don’t fully understand inside a VB script will be a pain . You really should think about writing your own logic to consume this COM Object and call your logic from a VS written GH component, It won’t take you long to figure out how to go from script to components and it will save you zillion hours of debugging/refactoring + it will make the code much more re-usable, which is hardly achievable with scripts.