Robot Structural Analysis Forum
Welcome to Autodesk’s Robot Structural Analysis Forums. Share your knowledge, ask questions, and explore popular Robot Structural Analysis topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Robot&IronPython

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
Anonymous
3746 Views, 7 Replies

Robot&IronPython

Help to connect to the Robot COM, what to write here where the question marks? 

app = System.Runtime.InteropServices.Marshal.GetActiveObject(???)
7 REPLIES 7
Message 2 of 8
Artur.Kosakowski
in reply to: Anonymous

Hi @Anonymous

 


Help to connect to the Robot COM, what to write here where the question marks? 

app = System.Runtime.InteropServices.Marshal.GetActiveObject(???)

“Robot.Application”

 

Here is a sample code which I hope should  create a node label using IronPython

 

import clr

# add Robot Structural Analysis API reference

clr.AddReferenceToFileAndPath(path to  interop.RobotOM.dll")

# add needed import to be able to use Robot Structural Analysis objects

from RobotOM import *

from System import Object

# Connect to the running instance of Robot Structural Analysis

application = RobotApplicationClass()

# Get a reference of the current project

project = application.Project

# Get a reference of the current model

structure = project.Structure

# Get a reference of the label server

labels = structure.Labels

nodeSupportName  = ”testName”

# create a new label of type support node with the name

out = labels.Create(IRobotLabelType.I_LT_NODE_SUPPORT, nodeSupportName)

# assign the node support definition to the Robot Structural Analysis object

out.Data.UX = false

out.Data.UY = false

out.Data.UZ = false

out.Data.RX = false

out.Data.RY = false

out.Data.RZ = false

 

# store the new created label in the open document

labels.Store(out)

 

I hope this helps.

 

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 3 of 8
Anonymous
in reply to: Artur.Kosakowski

Don`t work 

import System
app = System.Runtime.InteropServices.Marshal.GetActiveObject(“Robot.Application”)

print app

Traceback (most recent call last):
File "I:\PythonScripts\WORK\0022 RobotVariants.py", line 6, in <module>
EnvironmentError: System.Runtime.InteropServices.COMException (0x800401E3):

Message 4 of 8
Anonymous
in reply to: Artur.Kosakowski

But this is not a problem, because you showed me how to connect to the open ROBOT project. Thank you very much!

Message 5 of 8
Anonymous
in reply to: Anonymous

My first Python script for Robot 

import clr
# add Robot Structural Analysis API reference
clr.AddReferenceToFileAndPath("c:/Program Files/Autodesk/Autodesk Robot Structural Analysis Professional 2016/System/Exe/Interop.RobotOM.dll")
# add needed import to be able to use Robot Structural Analysis objects
from RobotOM import *
# Connect to the running instance of Robot Structural Analysis
Robapp = RobotApplicationClass()
# Get a reference of the current project
Robproj = Robapp.Project
# Get a reference of the current model
rStruct = Robproj.Structure
n1 = rStruct.Nodes.FreeNumber
rStruct.Nodes.Create(n1,0.0,0.0,0.0)
for i in range(5):
	nn = rStruct.Nodes.FreeNumber
	rStruct.Nodes.Create(nn,5.0,0.40*i,0.0)
	nb = rStruct.bars.FreeNumber
	rStruct.bars.Create(nb, n1, nn)
Message 6 of 8
ArunNDinesh
in reply to: Anonymous

@Anonymous  Is this working? I'm getting the following error .please comment

 clr.AddReferenceToFileAndPath('C:\Program Files\Autodesk\Robot Structural Analysis Professional 2023\Exe\Interop.RobotOM.dll')
AttributeError: module 'clr' has no attribute 'AddReferenceToFileAndPath'
Message 7 of 8

There seems to be multiple clr modules and it could be, that you aren't using the correct module. Have you tried the following:

 

pip uninstall clr
pip install pythonnet

Then import clr as you have been (strange, I know). Using the clr from pip install clr and printing the directories:

print(dir(clr))

['StyleBuilder', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__module__', '__name__', '__package__', '__path__', '__spec__', '_styles', 'black', 'blue', 'bold', 'cyan', 'dim', 'green', 'hidden', 'inverse', 'italic', 'key', 'light_black', 'light_blue', 'light_cyan', 'light_green', 'light_magenta', 'light_red', 'light_white', 'light_yellow', 'magenta', 'on_black', 'on_blue', 'on_cyan', 'on_green', 'on_light_black', 'on_light_blue', 'on_light_cyan', 'on_light_green', 'on_light_magenta', 'on_light_red', 'on_light_white', 'on_light_yellow', 'on_magenta', 'on_red', 'on_white', 'on_yellow', 'red', 'strikethrough', 'style_builder', 'sys', 'underline', 'value', 'white', 'yellow']

Then uninstalling clr and installing pythonnet:

import clr
print(dir(clr))

['AddReference', 'FindAssembly', 'GetClrType', 'ListAssemblies', '__class__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '__version__', '_add_pending_namespaces', '_available_namespaces', '_extras', '_load_clr_module', 'clrmethod', 'clrproperty', 'getPreload', 'loader', 'setPreload']

 

It seems the function name has changed to AddReference(). However, this should work.

 

Let me know!

Message 8 of 8
bjoern_steinhagen8PD9X
in reply to: Anonymous

How is this library being called in Python? I don't know of the System.Runtime. ... in Python? What library / module is that? 🙂

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report