API-new project creation Python

API-new project creation Python

Anonymous
Not applicable
2,796 Views
8 Replies
Message 1 of 9

API-new project creation Python

Anonymous
Not applicable

Hi all,

 

I have already used the Robot API through VBA and I am not trying to replicate some work with Python (I am relatively new to Python). I followed the methodology suggested here:

 

https://forums.autodesk.com/t5/robot-structural-analysis-forum/robot-amp-ironpython/m-p/7221364 

 

and it works perfectly in terms of establishing the connection to Robot.

However, I was wondering what is the syntax for a new project creation as where I try to set up a new Project using the I_PT_SHELL example in the SDK documentation I cannot seem to get the syntax right.

I defined Robot as in the post above and tried the following syntax structures:

 

 

Robot.Project.New('I_PT_SHELL')

 

 

 

Robot.Project.New("I_PT_SHELL")

 

May I ask you if you could advise in this regard?

Thank you!

0 Likes
Accepted solutions (1)
2,797 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable

Quick update: I was also trying to run fully the script in the post of my initial question but I receive this error:

Capture.PNG

 

has anyone else experienced this before?

0 Likes
Message 3 of 9

JacquesGaudin
Advocate
Advocate
Accepted solution

That must be because there is no open document.

 

Try to add a line to create a document:

 

from RobotOM import IRobotProjectType

project.New(IRobotProjectType.I_PT_SHELL)

 

0 Likes
Message 4 of 9

Anonymous
Not applicable

Hi @JacquesGaudin 

 

yes, that was also my understanding but I could not get the syntax right. I was using the same format of the label creation but clearly it was not working.

 

Thank you very much for your help!

It might have been a trivial question, but I am a bit new to Python...thanks again!!

0 Likes
Message 5 of 9

golkrz
Participant
Participant

Hi,

 

I am trying to use Robot API via python but I am struggling to use the data defined by Robot Object Model. I looked at SDK and I understand that the robotom.tlb needs to be added to the python IDE. Could you explain how did you manage to do that?

0 Likes
Message 6 of 9

JacquesGaudin
Advocate
Advocate

For plain CPython:

 

You need to install PythonNet and add a reference to `interop.RobotOM.dll`

 

import clr
from pathlib import Path

p = Path('c:/Program Files/Autodesk')
robot_dll_path = str(next(p.rglob('System/EXE/interop.RobotOM.dll')))

clr.AddReference(robot_dll_path)

import RobotOM

 

For IronPython:

 

import clr

robotom_path = "C:\Program Files\Autodesk\Autodesk Robot Structural Analysis Professional 2019\System\Exe\interop.RobotOM.dll"
clr.AddReferenceToFileAndPath(robotom_path)

import RobotOM

 

Then in both cases to create an instance of Robot application:

 

app = RobotOM.RobotApplication()
Message 7 of 9

Anonymous
Not applicable

Hi,

In the snap shot below you can see that there is no attribute as "AddReference", but in all the code above it is there please help ..

RANGREJ98_0-1614141406398.png

 

0 Likes
Message 8 of 9

JacquesGaudin
Advocate
Advocate

What's the output of:

 

import clr
dir(clr)
0 Likes
Message 9 of 9

mmaso64U7Y
Enthusiast
Enthusiast

Python.Net package aliases to 'clr', which is in conflict with 'clr' package. As stated by @JacquesGaudin , you can check whether 'clr' is pointing to 'pythonnet' or to 'clr' using 'dir()' function.

To install 'pythonnet' run the following commands:

 

pip uninstall clr

pip install pythonnet

 

See this topic.

0 Likes