# Bar gets removed in second run (API/Dynamo)

**URL:** <https://forum.dynamobim.com/t/bar-gets-removed-in-second-run-api-dynamo/43219>\
**Category:** Robot Structural Analysis\
**Tags:** python\
**Created:** [November 15, 2019, 4:23pm UTC](https://forum.dynamobim.com/t/bar-gets-removed-in-second-run-api-dynamo/43219 "2019-11-15T16:23:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![1234eddie](https://avatars.discourse-cdn.com/v4/letter/1/4da419/32.png) [@1234eddie](https://forum.dynamobim.com/u/1234eddie)\
**Post date:** [November 15, 2019, 4:23pm UTC](https://forum.dynamobim.com/t/bar-gets-removed-in-second-run-api-dynamo/43219/1 "2019-11-15T16:23:27Z")

</div>

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)

 ![1%20Result%20first%20run](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/4/a4a3c1b366cb504a9983f2b368ea22c1c0efdda4.jpeg)Picture 1 ![2%20message](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/5/2580fcbf90f4749ff8c333356d758a4d361bf486.jpeg)Picture 2 ![3%20result%20second%20run](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/2/f2f9f0e17404756711c7ba3e308f8dc0c5c4512f.jpeg) Picture 3

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

 ![Full%20script](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/7/8769194d952fdf2ce0d184adc4d9ccd493f82289.jpeg)

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](https://forum.dynamobim.com/uploads/short-url/p27CEiDKCarQCOZLD14xGr6UlqM.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()
```

---

<div class="post-metadata">

**Author:** ![khuzaimah.ElecEng](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/khuzaimah.eleceng/32/92768_2.png) [@khuzaimah.ElecEng](https://forum.dynamobim.com/u/khuzaimah.ElecEng)\
**Post date:** [November 15, 2019, 6:44pm UTC](https://forum.dynamobim.com/t/bar-gets-removed-in-second-run-api-dynamo/43219/2 "2019-11-15T18:44:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![1234eddie](https://avatars.discourse-cdn.com/v4/letter/1/4da419/32.png) [@1234eddie](https://forum.dynamobim.com/u/1234eddie)\
**Post date:** [November 18, 2019, 8:08am UTC](https://forum.dynamobim.com/t/bar-gets-removed-in-second-run-api-dynamo/43219/3 "2019-11-18T08:08:09Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![1234eddie](https://avatars.discourse-cdn.com/v4/letter/1/4da419/32.png) [@1234eddie](https://forum.dynamobim.com/u/1234eddie)\
**Post date:** [November 19, 2019, 10:22am UTC](https://forum.dynamobim.com/t/bar-gets-removed-in-second-run-api-dynamo/43219/4 "2019-11-19T10:22:54Z")

</div>

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)

 ![Solved%20script](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/1/912d69766ec213e39f0ae6d2b3ad930d710ae77a.jpeg)

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

 ![Result%20run%201](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/5/c5d6d29fcd838622adfceac0a80e20c93f5ea895.jpeg)  
Run 2 see red boxes(load has duplicated ![Result%20run%202](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/c/0cf857fa6bf4a816a73329946f2be72d86ea47db.jpeg)

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

 ![Script%20Load%20to%20bar](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/5/9557443cd79911c4980d188247057ea1d4bd003b.jpeg)

**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.

 ![IRobotLoadRecordMngr](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/0/e06bb360e363f3d304c4a6aac5c83816b0063192.jpeg)

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](https://forum.dynamobim.com/uploads/short-url/h7l2EByAWXiLehTMFdGsJPtzpMs.dyn) (47.9 KB)
