How to enter Robot API through Python

How to enter Robot API through Python

Anonymous
Not applicable
7,013 Views
6 Replies
Message 1 of 7

How to enter Robot API through Python

Anonymous
Not applicable

Hello,

I'm looking for (kind of) guidelines/tutorial on how to translate Robot API commands into Python script.

What are main principles, what rules to follow etc.

This forum is rich of API content but there's only few threads about Python. I've read them all and found few information: how to add references or create bars/nodes/labels.

I see its similar e.g. 

 

Dim robapp As New RobotApplication
Dim section As RobotLabel
Set section = robapp.Project.Structure.Labels.Create(I_LT_BAR_SECTION, "pipe")

 

in Python equals to:

 

robapp = RobotApplicationClass()
section = robapp.Project.Structure.Labels.Create(IRobotLabelType.I_BAR_SECTION, "VALUE")

but why  IRobotLabelType. jumps into brackets?

 

And how to translate the rest API script:

Dim sectionData As RobotBarSectionData
Set sectionData = section.Data
sectionData.ShapeType = I_BSST_USER_CIRC_FILLED
sectionData.Type = I_BST_NS_TUBE
Dim ns As RobotBarSectionNonstdData
Set ns = sectionData.CreateNonstd(0)
ns.SetValue I_BSNDV_TUBE_D, 0.3
sectionData.CalcNonstdGeometry
robapp.Project.Structure.Labels.Store section

Python:

section.Data.ShapeType = I_BSST_USER_CIRC_FILLED
section.Data.Type = I_BST_NS_TUBE
ns = section.Data.CreateNonstd(0)
ns.SetValue(IRobotBarSectionNonstd(0).I_BSNDV_TUBE_D, 0.3)
section.Data.CalcNonstdGeometry
labels.Store section

?

 

Python allows me to use Dynamo/Robot cooperability much more effective than "Structural Analysis" package.

So.. what to start with ?

 

Regards
Marcin

 

 

 

 

0 Likes
7,014 Views
6 Replies
Replies (6)
Message 2 of 7

Romanich
Mentor
Mentor

Hi @Anonymous,

Maybe this topic will help https://forums.autodesk.com/t5/robot-structural-analysis-forum/robot-amp-ironpython/m-p/7221364

Do you find the posts helpful? "LIKE" these posts!
Have your question been answered successfully? Click 'ACCEPT SOLUTION' button.

Roman Zhelezniak

Robot Evangelist & Passionate Civil Structural Engineer

LinkedIn | Robot & Хобот | App Store for Robot
EESignature


0 Likes
Message 3 of 7

Anonymous
Not applicable

Thank you, I've read it (as any other on this forum with Python tag:).

This topic does not help much. e.g. why&when in Python brackets should be deleted? - user in last post uses command

RobApp.Project.Structure.Nodes.FreeNumber
 While in API, this command has '()'   🙂
Apiforum.PNG

but in this case (Python):
# Connect to the running instance of Robot Structural Analysis
application = RobotApplicationClass()
brackets appear.
0 Likes
Message 4 of 7

Romanich
Mentor
Mentor

I would not recommend to delete the nodes using API

https://forums.autodesk.com/t5/robot-structural-analysis-forum/api-nodes-freenumber-after-nodes-dele...

Do you find the posts helpful? "LIKE" these posts!
Have your question been answered successfully? Click 'ACCEPT SOLUTION' button.

Roman Zhelezniak

Robot Evangelist & Passionate Civil Structural Engineer

LinkedIn | Robot & Хобот | App Store for Robot
EESignature


0 Likes
Message 5 of 7

Anonymous
Not applicable

hey @Romanich, you missed the point. I don't want to use this particular command, I mention this example to show difference in code between Python/API   - brackets.


The issue is still up to date, anyone with Python/API experience is very welcome to share his knowledge.

0 Likes
Message 6 of 7

Anonymous
Not applicable

Hi @Anonymous 

 

I am also encountering a similar problem. I managed to use part of @Artur.Kosakowski's code as per post above, but after calling the API it is not possible to go further.

 

I posted a similar query here:

https://forums.autodesk.com/t5/robot-structural-analysis-forum/api-new-project-creation-python/m-p/9490299#M81448 

 

as it looks like the API is connected but further operations are not allowed. It would be very helpful to get some feedback on this topics, I agree with @Anonymous 

 

Thank you in advance!

0 Likes
Message 7 of 7

JacquesGaudin
Advocate
Advocate

Python's syntax requires brackets for any function call. I've put a sample function I wrote recently to help understand how it works.

 

def createRelease(name, start, end):
    struct =  rb.Project.Structure
    if not struct: return None
    
    start = strToReleaseParams(start) if isinstance(start, str) else start
    end = strToReleaseParams(end) if isinstance(end, str) else end
    

    start_release = {
        "UX": start[0],
        "UY": start[1],
        "UZ": start[2],
        "RX": start[3],
        "RY": start[4],
        "RZ": start[5],
    }

    end_release = {
        "UX": end[0],
        "UY": end[1],
        "UZ": end[2],
        "RX": end[3],
        "RY": end[4],
        "RZ": end[5]
    }

    release_values = {
        True: IRobotBarEndReleaseValue.I_BERV_STD,
        False: IRobotBarEndReleaseValue.I_BERV_NONE
    }

    labels = struct.Labels

    release = IRobotLabel(labels.Create(IRobotLabelType.I_LT_BAR_RELEASE, name))
    data = IRobotBarReleaseData(release.Data)
    start_data, end_data = IRobotBarEndReleaseData(data.StartNode), IRobotBarEndReleaseData(data.EndNode)

    for data, input in zip([start_data, end_data], [start_release, end_release]):
        for dof, val in input.items():
            setattr(data, dof, release_values[bool(val)])

    labels.StoreWithName(release, name)