Bar gets removed in second run (API/Dynamo)

Hi all,

Hopefully someone can help me a little bit. I wrote i big script to make design calculations on a cantilever bar including load cases and combinations, all based on input from an excel file.

When i run it for the first time it works good(picture 1). but when changing the “bar section” or the “material” and running again(gives an message that robot is changing, picture 2) and the bar is getting removed(picture 3)

Picture 1 2%20messagePicture 2 Picture 3

This is the dynamo script i use(simplified for this forum)

The red marks around the sliders are there to change the bar section and the material.(normally done in Excel, but works the same).

Hopefully someone can explain me why is the bar removed in the second run?

PS Dynamo file is attached.Test draw bar multiple times_rem.dyn (36.7 KB)

Here a the Python scripts i used.

Create nodes and bar(1)
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

from System import Environment
user = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
clr.AddReferenceToFileAndPath(user +r"\Dynamo\Dynamo Core\1.3\packages\Structural Analysis for Dynamo\bin\RSA\Interop.RobotOM.dll")
from RobotOM import *
from System import Object
#The inputs to this node will be stored as a list in the IN variables.

pnt = IN[0]
Barsection = IN[1]
Barnumber = IN[2]
Barmaterial = IN[3]

application = RobotApplicationClass()
project = application.Project
structure = project.Structure
labels = structure.Labels
loads = structure.Cases
ProjectPrefs = project.Preferences


#output
for i in range(len(pnt)):
	structure.Nodes.Create(pnt[i][0],pnt[i][1],pnt[i][2],pnt[i][3])


structure.Bars.Create(Barnumber,1,2)
selectionBars = structure.Selections.Get(IRobotObjectType.I_OT_BAR)
selectionBars.FromText(Barnumber)
steelsections = ProjectPrefs.SectionsActive
steelsections.Add("RCAT")
label = labels.Create(IRobotLabelType.I_LT_BAR_SECTION,Barsection)
labels.Store(label)
structure.Bars.SetLabel(selectionBars,IRobotLabelType.I_LT_BAR_SECTION,Barsection)
structure.Bars.SetLabel(selectionBars,IRobotLabelType.I_LT_BAR_MATERIAL,Barmaterial)


OUT = pnt

Creating and adding support(2)
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

from System import Environment
user = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
clr.AddReferenceToFileAndPath(user +r"\Dynamo\Dynamo Core\1.3\packages\Structural Analysis for Dynamo\bin\RSA\Interop.RobotOM.dll")
from RobotOM import *
from System import Object
#The inputs to this node will be stored as a list in the IN variables.

nodeSupportName = IN[0]
nodeSupportData = IN[1]
supportnodes = IN[2]

application = RobotApplicationClass()
project = application.Project
structure = project.Structure
labels = structure.Labels
#Assign your output to the OUT variable.

out = labels.Create(IRobotLabelType.I_LT_NODE_SUPPORT, nodeSupportName)
out.Data.UX = nodeSupportData[0]
out.Data.UY = nodeSupportData[1]
out.Data.UZ = nodeSupportData[2]
out.Data.RX = nodeSupportData[3]
out.Data.RY = nodeSupportData[4]
out.Data.RZ = nodeSupportData[5]
labels.Store(out)		
		
SelectionNodes = structure.Selections.Get(IRobotObjectType.I_OT_NODE)
SelectionNodes.FromText(supportnodes)
structure.Nodes.SetLabel(SelectionNodes,IRobotLabelType.I_LT_SUPPORT,nodeSupportName)
OUT = out.Name

Own weight(3)
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

from System import Environment
user = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
clr.AddReferenceToFileAndPath(user +r"\Dynamo\Dynamo Core\1.3\packages\Structural Analysis for Dynamo\bin\RSA\Interop.RobotOM.dll")
from RobotOM import *
from System import Object
#The inputs to this node will be stored as a list in the IN variables.
LoadCaseNumber = IN[0]
LoadCaseName = IN[1]
IRCN = IN[2]
IRCAT = IN[3]
LCLabel = IN[4]

application = RobotApplicationClass()
project = application.Project
structure = project.Structure
labels = structure.Labels
loads = structure.Cases

#output
if(loads.Exist(LoadCaseNumber)):
	OUT = LoadCaseName
if not(loads.Exist(LoadCaseNumber)):
	Caseeigengewicht = structure.Cases.CreateSimple(LoadCaseNumber,LoadCaseName,IRCN,IRCAT)
	Caseeigengewicht.Label = LCLabel

	Caseeigengewicht.Records.New(IRobotLoadRecordType.I_LRT_DEAD)
	LoadRecord = Caseeigengewicht.Records.Get(1)
	LoadRecord.SetValue(IRobotDeadRecordValues.I_DRV_Z,-1)
	LoadRecord.SetValue(IRobotDeadRecordValues.I_DRV_ENTIRE_STRUCTURE,True)
	OUT = LoadCaseNumber

Calculate(4)
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

from System import Environment
user = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
clr.AddReferenceToFileAndPath(user +r"\Dynamo\Dynamo Core\1.3\packages\Structural Analysis for Dynamo\bin\RSA\Interop.RobotOM.dll")
from RobotOM import *
from System import Object
#The inputs to this node will be stored as a list in the IN variables.
objects = IN[0]
application = RobotApplicationClass()
project = application.Project
structure = project.Structure
labels = structure.Labels
project.CalcEngine.AnalysisParams.IgnoreWarnings = True
calcEngine = project.CalcEngine
calcEngine.AutoGenerateModel = True
calcEngine.UseStatusWindow = True
OUT = calcEngine.Calculate()

as a fast solution, try to run it from dynamo player

1 Like

@khuzaimah.ElecEng

thanks for your reply, I don’t use dynamo player, is use dynamo studio instead.
But i gave it a try and end up with the same result that the bar is getting removed in the second run.

@Jonathan.Olesen @Maciek_Kubica @Emmanuel_Weyermann maybe someone of you know why this is happening?

The versions of the programs i use are:
Robot structural analysis 2020
Dynamo studio 1.3.0.946/Dynamo core 1.3.4.6666

Hi All,
@khuzaimah.ElecEng @Jonathan.Olesen @Maciek_Kubica @Emmanuel_Weyermann

I got this problem solved. after rethinking how the bar is created, that it’s not neccesary to draw the bar again. so ended up with adding this in the code “Create nodes and bar(1)”.(red boxes)

But i have one other question that when adding load to a bar it keeps adding the load as new everytime i run the script again with a bar change. See pictures below.
Run 1 works fine


Run 2 see red boxes(load has duplicated

This is the script which is added to the script in the start of this topic.

Add load to bar(5)

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

from System import Environment
user = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
clr.AddReferenceToFileAndPath(user +r"\Dynamo\Dynamo Core\1.3\packages\Structural Analysis for Dynamo\bin\RSA\Interop.RobotOM.dll")
from RobotOM import *
from System import Object

objects = IN[0]
LoadCaseID = IN[1]
ILRT = IN[2]
LoadPX = IN[3]
LoadPY = IN[4]
LoadPZ = IN[5]


application = RobotApplicationClass()
project = application.Project
structure = project.Structure
labels = structure.Labels
loads = structure.Cases


simplecase = loads.Get(LoadCaseID)

Uniform = []
Uniform.append(simplecase.Records.New(ILRT))
LoadRecord = simplecase.Records.Get(Uniform[0])
LoadRecord.SetValue(0,LoadPX)
LoadRecord.SetValue(1,LoadPY)
LoadRecord.SetValue(2,LoadPZ)
LoadRecord.Objects.FromText(objects)

#Assign your output to the OUT variable.
OUT = 0

I think this part of the api could help me, but can’t figure out how to use it inside the script.

I hope someone of you can provide me some insight why the loads keep adding up.

Many thanks in advance

Edward
Dynamo file Loads keeps adding.dyn (47.9 KB)