Robot API Optimization Parameters - dynamo/python

Robot API Optimization Parameters - dynamo/python

Anonymous
Not applicable
3,644 Views
9 Replies
Message 1 of 10

Robot API Optimization Parameters - dynamo/python

Anonymous
Not applicable
Hello, I am trying to use the Robot API and dynamo in order to create a structure and design/optimize for all of the members. Everything has been going well, but I am struggling to figure out how to properly set the optimization parameters for the design. When I attempt to set the limit or option status for an optimization parameter (using SetLimit and SetOption), the commands change the value for both the limit and the option. So if I set the limit to 2, then the option changes to 2 as well. Also, the SetLimit command seems to round the limit value to the nearest integer, which is not very useful for smaller numbers since it rounds them to zero (and sets the Option to zero which deactivates the parameter) such as for minimum and maximum flange widths. If anyone has an idea as to why this is occurring any help is appreciated. Another issue I've been having is that I cannot seem to use the Solve command of the design module. When I input Nothing (None in python) to the function, it does not accept it and gives the error "ValueError: Could not convert argument 0 for call to solve", and then refuses to calculate. I've noticed that the function will accept other inputs, but still does not calculate the design. If anyone knows why this is happening, or if something has changed with the function it would be great if I could figure this out. Code is attached below, the problems are occurring the last few lines. Sorry if it is not well formatted, I am new to writing code. Thanks
0 Likes
Accepted solutions (2)
3,645 Views
9 Replies
Replies (9)
Message 2 of 10

Artur.Kosakowski
Autodesk Support
Autodesk Support

Is it for Steel Design? It seems that you missed the attachment (try to zip it).



Artur Kosakowski
0 Likes
Message 3 of 10

Anonymous
Not applicable

Sorry about that, I was having trouble posting earlier. Yes it's for steel design, here's the code and dynamo file:

 

import clr
clr.AddReferenceToFileAndPath(r"C:\Program Files\Dynamo1.0.0\Dynamo\Dynamo Core\1.0\ProtoGeometry.dll")
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN[0]
Span=IN[1]
NSpans=IN[2]
h=IN[3]
DefaultSection=IN[4]
Releases=IN[5]
LiveLoad=IN[6]
NPoints=NSpans*2+1
Lx=NSpans+1
x1=[i*(Span/NSpans) for i in range(Lx)]
x2_=x1[0:NSpans]
x2=[i+(Span/(2*NSpans)) for i in x2_]
z1=[]
lll=NSpans+1
z1=[0 for i in range(lll)]
z2=[]
z2=[h for i in range(NSpans)]
x1.extend(x2)
z1.extend(z2)
XCoords=x1
ZCoords=z1
# 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(r"C:\Program Files\Autodesk\Autodesk Robot Structural Analysis Professional 2016\System\Exe\Interop1.RobotOM.dll")

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

application=RobotApplicationClass()
project=application.Project
structure=project.Structure
prefs=project.Preferences
labels=structure.Labels
application=RobotApplicationClass()

project=application.Project
close=project.Close()
new=project.New(7)
active=prefs.SectionsActive
data=active.GetDatabase(1)
all=data.GetAll()
count=all.Count
sectionlist=[]
for i in range(1,count):
 name=all.Get(i)
 if "W 200x15" in name:
  if labels.Exist(3,name)==0:
   if "F" not in name:
    if "T" not in name:
     sectionlist=labels.Create(3,name)
     labels.Store(sectionlist)
materials=prefs.Materials.SetDefault(1,"STEEL 350W")

view=project.ViewMngr
view1=view.GetView(1)
view1.Projection=3
view1.Redraw(True)
project=application.Project
point=RobotGeoPoint3DClass()
j=range(3*NSpans)
structure=project.Structure
nodes=structure.Nodes
bars=structure.Bars
#create nodes
for i in j[0:NPoints]:
     nodes.Create(i+1,XCoords[i],0,ZCoords[i])
#create bars
#bottom
for i in j[1:NSpans+1]:
     bars.Create(i,i,i+1)
#top    
for i in j[NSpans+1:NPoints-1]:
 bars.Create(i,i+1,i+2)
#diagonals
for i in j[2*NSpans:3*NSpans]:
 bars.Create(i,i-2*NSpans+1,i-NSpans+2)
 bars.Create(i+NSpans,i-2*NSpans+2,i-NSpans+2)
 
#create supports
labels=structure.Labels
pin1=labels.Create(0,"Roller X")
pin1.Data.UX=0
pin1.Data.UY=1
pin1.Data.UZ=1
pin1.Data.RX=1
pin1.Data.RY=0
pin1.Data.RZ=1

labels.Store(pin1)

nodes.Get(1).SetLabel(0,"Pinned")
nodes.Get(NSpans+1).SetLabel(0,"Roller X")

NBars=bars.GetAll().Count
j=range(NBars)
for i in j:
 bar=bars.Get(i+1)
 bar.SetLabel(3,DefaultSection)
 bar.SetLabel(4,Releases)
 
 labels=structure.Labels
cases=structure.Cases
#delete existing load cases
simple=structure.Selections.CreatePredefined(2)
combo=structure.Selections.CreatePredefined(3)
code=structure.Selections.CreatePredefined(4)
cases.DeleteMany(simple)
cases.DeleteMany(combo)
cases.DeleteMany(code)
#selfweight load case
SW1=cases.CreateSimple(1,"SelfWeight",0,1)
SWRecord=SW1.Records.New(7)
SWGetRecord=SW1.Records.Get(1)
SWGetRecord.SetValue(2,-1)
SWGetRecord.SetValue(15, 1)
#live load case
LL1=cases.CreateSimple(2,"LiveLoad1",1,1)
LL1Record=LL1.Records.New(0)
LL1GetRecord=LL1.Records.Get(1)
LL1GetRecord.SetValue(2,LiveLoad*-1000)
LL1GetRecord.Objects.FromText(3)
#load combinations
combogen=cases.CodeCmbEngine
combogen.Params.GenType=2
gen=combogen.Generate()
application.Preferences.multiprocessing=1
calca=project.CalcEngine
anaparams=calca.AnalysisParams
anaparams.IgnoreWarnings=1
anaparams.EquationSolvingMethod=7
calcproject=calca.Calculate()

dim=project.DimServer
allbars=bars.GetAll()
members=dim.MembersService
gen=members.Generate(allbars)

connect=dim.Connection
#define groups
groups=dim.GroupsService
g1=groups.New(0,1)
g1.Name="Chords"
g1.Material="STEEL 350W"
strm=connect.GetStream()
strm.Clear()
strm.WriteText("1 2 3 4 5 6 7")
g1.SetMembList(strm)
grpprof=connect.GetGrpProfs()
grpprof.Clear()
strm.Clear()
strm.WriteText("W")
grpprof.SetFamilies("CISC",strm)
g1.SetProfs(grpprof)
groups.Save(g1)

g2=groups.New(0,1)
g2.Name="Diagonals"
g2.Material="STEEL 350W"
clrstrm=strm.Clear()
strm.WriteText("8 9 10 11 12 13 14 15")
g2.SetMembList(strm)
g2.SetProfs(grpprof)
groups.Save(g2)

calc=dim.CalculEngine
calcpars=calc.GetCalcParam()
calcconfs=calc.GetCalcConf()
strm.Clear()
calcconfs.SetParamValue(3,0.9)
strm.WriteText("1 2")

#for memeber verification calcpars.SetObjsList(1,strm)
#for group verification calcpars.SetObjsList(2,strm)
calcpars.SetObjsList(3,strm)
calcpars.SetLimitState(1,1) #ULS on
calcpars.SetLimitState(2,0) #SLS off
strm.Clear()
calcpars.SetLoadsList(strm)
optpars=calcpars.GetOptimParam()



optpars.Optimization=1
optpars.SetOption(1,1)

optpars.SetOption(2,1)
optpars.SetLimit(2,0.5)

optpars.SetOption(3,1)
optpars.SetLimit(3,0.1)
optpars.SetOption(4,1)
optpars.SetLimit(4,0.01)
optpars.SetOption(5,0)
optpars.SetLimit(5,0.01)
optpars.SetOption(6,0)
optpars.SetOption(7,0)

calcpars.SetOptimParam(optpars)
calc.SetCalcParam(calcpars)
calc.SetCalcConf(calcconfs)

calc.Solve(None)

Message 4 of 10

Anonymous
Not applicable

Hi Artur,

 

Any idea about how to solve these problems specifically?

 

Optimization parameters problem:

 

Optimization Parameters Problems.PNG

 

Calculate/solve problem:

Calculation problem.PNG

Message 5 of 10

Artur.Kosakowski
Autodesk Support
Autodesk Support

This is not something I'll be able to solve myself but I'm trying to find somebody who could be of help for you. This means that it may take me a bit of time.



Artur Kosakowski
Message 6 of 10

Artur.Kosakowski
Autodesk Support
Autodesk Support
Accepted solution

Try to rename the original and copy the attached dll to the System\exe folder of Robot 2017 (applies to this version only). Let me know if this allows you to run your code.

 

If you find your post answered press the Accept as Solution button please. This will help other users to find solutions much faster. Thank you.

 

 



Artur Kosakowski
Message 7 of 10

Anonymous
Not applicable

This fixed the problem with the optimization parameters, but I am still unable to calculate run the design calculations (member/group verification, group design, optimization). Any idea why the Solve function is not accepting None as an input, or whether there is something else I'm doing wrong?

 

Thanks

 Calculate Problem.PNG

Message 8 of 10

Artur.Kosakowski
Autodesk Support
Autodesk Support
Accepted solution

'The Solve function is implemented in C++ as STDMETHOD(Solve)(IDispatch* observer) but at the moment observer doesn’t impact on any functionality and in simply words it isn’t used inside function Solve. This stuff was defined for future use. So your previous thought to use project interface as parameter to this function was quite fine because doing so the IDispatch inteface is passing to the function and the problem why the Solve function is not accepting None as an input becomes insignificant. To check results of performing Calcul function please rewrite and modify proper part of VB code from attached file into your Phyton project. Results receiving examples are placed at points 5 to 9.'

 

If you find your post answered press the Accept as Solution button please. This will help other users to find solutions much faster. Thank you.



Artur Kosakowski
Message 9 of 10

Anonymous
Not applicable

It is working now, thank you very much!

0 Likes
Message 10 of 10

Anonymous
Not applicable

Hi everyone,unfortunately I need to solve the same problem that you seem to have solved.

I was not able to translate the vba code and in particular the "null" argument into Solve.

I am attaching some photos to be clearer

 

..
...
app = RobotApplicationClass()
project = app.Project
dim = project.DimServer
calc = dim.CalculEngine
calcpars = calc.GetCalcParam()
calcconfs = calc.GetCalcConf()

strm.Clear()
calcconfs.SetParamValue(3,0.9)
strm.WriteText("1 2 3 4")
calcpars.SetObjsList(3,strm)
calcpars.SetLimitState(1,1) #ULS on
calcpars.SetLimitState(2,0) #SLS off
strm.Clear()
calcpars.SetLoadsList(strm)
optpars = calcpars.GetOptimParam()
optpars.Optimization=1
optpars.SetOption(1,1)
optpars.SetOption(2,0)
optpars.SetLimit(2,0.5)
optpars.SetOption(3,0)
optpars.SetLimit(3,0.1)
optpars.SetOption(4,0)
optpars.SetLimit(4,0.01)
optpars.SetOption(5,0)
optpars.SetLimit(5,0.01)
optpars.SetOption(6,0)
optpars.SetOption(7,0)
calcpars.SetOptimParam(optpars)
calc.SetCalcParam(calcpars)
calc.SetCalcConf(calcconfs)
calc.Solve(null)

ROBOTT.JPG

 

0 Likes