Message 1 of 7
Robot API with Python 2.7 using comtypes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'm trying to connect to the running Robot 2017 application using python 2.7 and with the comtypes package
the following code that imports the type library file robotom.tlb gets successful.
#Comtypes importing
import sys
import os
import comtypes.client
from comtypes import COMError
from comtypes.client import CreateObject, GetModule, GetActiveObject
import array
#____
def main():
try:
rbt_tlb_path = "C:/Program Files/Autodesk/Autodesk Robot Structural Analysis Professional 2017/System/Exe/robotom.tlb"
GetModule(rbt_tlb_path)
print "Type library is successfully imported"
print "______________"
except(OSError,COMError):
print "Error: a step has failed."
print "______________"
if __name__ = '__main__':
main()The result at the first time of running the script is
# Generating comtypes.gen._F3A37BD0_AA2D_11D2_9844_0080C86BE4DF_0_1_0 # Generating comtypes.gen._00020430_0000_0000_C000_000000000046_0_2_0 # Generating comtypes.gen.RobotOM
I then opened both of the generated modules
#directory folder is "C:/Python27/Lib/site-packages/comtypes/gen"
_F3A37BD0_AA2D_11D2_9844_0080C86BE4DF_0_1_0.py #refers directly to robotom.tlb _00020430_0000_0000_C000_000000000046_0_2_0.py #refers to C:/Windows/System32/stdole2.tlb
added the line
import comtypes.gen.RobotOM
at the end of the try statement block to import the newly generated module.
then tried these 2 ways to get the running Robot instance (at the end of the try statement block)
robotapp = GetActiveObject("Robot.Application") #progid is guessed #couldn't find any actual one#the instantiation mentioned in the "Getting started" documentation file.
robotapp = RobotOM.RobotApplicationClass() #found out that there's no class with that name in the generated module, what a surprise! """ However, there's RobotApplication class, but with no listed methods or properties relevant to the actual documented Object Model.
They're somehow listed under this attribute ((IRobotApplication._methods_)), but I've
no clue of how to connect to the running instance to take advantage of them. """
Sadly, both ways fail.
The generated python modules are attached here in the zip file, they would be helpful for better understanding of the issue.
I'll be thankful for any help and any insight.