API Robot Dynamo Create New Section and Variable Name Python

API Robot Dynamo Create New Section and Variable Name Python

Anonymous
Not applicable
2,539 Views
5 Replies
Message 1 of 6

API Robot Dynamo Create New Section and Variable Name Python

Anonymous
Not applicable

Good night,

 

Hi, I am a totally noob with the API Robot and all  that is related with programing, I started recently. 

 

These days, I have had thousands of doubts but thanks to the forum and looking in the API guide I have been able to figure out it. Is any Python Guide, not for C or C+?

 

Now I am trying to create a new section shape but I am not able to do it, even looking in the guide, I dont have a clue how the programming.I am learning taking a look to other examples.

 

Could you transform this lines for a Python script? 

 

An example ( API GUIDE):

 

Set Label = Robot.Project.Structure.labels.Create(I_LT_BAR_SECTION, "Beam 50*50")
Dim section As RobotBarSectionData
Set section = Label.Data
section.ShapeType = I_BSST_CONCR_BEAM_RECT
Dim concrete As RobotBarSectionConcreteData
Set concrete = section.concrete
concrete.SetValue I_BSCDV_BEAM_B, 0.5
concrete.SetValue I_BSCDV_BEAM_H, 0.5
section.CalcNonstdGeometry
Robot.Project.Structure.labels.Store Label
Robot.Project.Structure.Bars.Get(1).SetLabel I_LT_BAR_SECTION, "Beam 50*50"

 

The last doubt, Anyone knows how to do a variable name of the section?, I want to assign different kind of section to different bars and to use a loop.
for example:

 

"Beam 50*50_1", the next bar "Beam 50*50_2".... "Beam 50*50_i"

 

Thank you very much!! 

 

PD: It is my first post, I hope is posted in the right place.

0 Likes
Accepted solutions (2)
2,540 Views
5 Replies
Replies (5)
Message 2 of 6

napooil
Advocate
Advocate
Accepted solution

You can translate code from VB to Python by online web.As picture

ans.jpg

0 Likes
Message 3 of 6

1234eddie
Advocate
Advocate
Accepted solution

@Anonymous 

 

you need just to add the loop.

make a list of all sections, width and the height.

 

The base of this code comes from the SDK->Tutorial map with the example codes.(quite helpfull with the tool @napooil shared)

 

see this code including the loop.(python script inside dynamo)

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.
#Define input

USec_name = IN[0]
USec_mat = IN[1]
USec_B = IN[2]
USec_H = IN[3]

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

#User rectangular section
for i in range(len(USec_name)):
	lab_serv = IRobotLabelServer 
	lab_serv = labels
	sec = IRobotLabel
	sec = lab_serv.create(IRobotLabelType.I_LT_BAR_SECTION, USec_name[i])
	data = sec.data
	data.Type = IRobotBarSectionType.I_BST_NS_RECT
	data.ShapeType = IRobotBarSectionShapeType.I_BSST_RECT_FILLED
	nonst_data = IRobotBarSectionNonstdData
	nonst_data = data.CreateNonstd(0)
	nonst_data.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_RECT_B,USec_B[i])
	nonst_data.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_RECT_H,USec_H[i])
	data.MaterialName = USec_mat[i]
	data.CalcNonstdGeometry
	lab_serv.Store(sec)

OUT = "labels gemaakt"

hope this will work for you.

Message 4 of 6

Anonymous
Not applicable

Thanks very much!! You made my day

0 Likes
Message 5 of 6

Anonymous
Not applicable

In the line of the 

:data.CalcNonstdGeometry

 

The brackets are missed, should be:

 

data.CalcNonstdGeometry()

 

PD:I am just saying it, in case of someone will use the code.

0 Likes
Message 6 of 6

1234eddie
Advocate
Advocate

@Anonymous 

youre right. I experienced it that it didn't work without them.

 

Am i correct if i say you just need to activate the command?

 

Gr edward.

0 Likes