Hello Mr.kapetanovic,
I'm reaching you regarding an issue that I encoutered when I tried to apply claddings to some coordinates from a CSV file. Explaining from scratch, I have a csv file with lines giving id type and coordinates of each pieces and as a test we assume that they were all claddings. The goal was to transform it as a list of sublists of each materials and apply the claddings on each. Therefore, I used Dynamo in Robot directly to try Python Scripts but I had so many problems with RobotOM and class usage. I don't know if the best option is to create directly a Robot Add-On or to try again via Dynamo Python and instanciate a new Robot cause I saw on internet that it was impossible to save an old instance of Robot and that we were forced to do RobotApplicationClass().
I can give you an example of my code so you can analyse me errors for now and tell me what could be improved cause actually I have a lot of problems and tried a lot of things to make it work.
import clr
clr.AddReference('Interop.RobotOM')
import RobotOM
import time
# Entrée : liste de claddings sous forme [ID, label, x1, y1, z1, x2, y2, z2, ..., xn, yn, zn]
liste_claddings = IN[0]
# Nouvelle instance de Robot
robot = RobotOM.RobotApplicationClass()
robot.Visible = True
robot.Project.New(RobotOM.IRobotProjectType.I_PT_FRAME_3D)
time.sleep(0.5)
structure = robot.Project.Structure
objects = structure.Objects
factory = robot.CmpntFactory
results = []
def get_free_object_id(start=1):
free_id = start
while True:
try:
if objects.Get(free_id):
free_id += 1
else:
return free_id
except:
return free_id
for ligne in liste_claddings:
try:
ID = int(ligne[0])
nom = ligne[1]
coords = ligne[2:]
if len(coords) < 9 or len(coords) % 3 != 0:
results.append(f"Cladding {ID} ignoré : mauvais nombre de coordonnées")
continue
nb_pts = len(coords) // 3
pts = factory.Create(RobotOM.IRobotComponentType.I_CT_POINTS_ARRAY)
pts.SetSize(nb_pts)
for i in range(nb_pts):
x, y, z = coords[i*3], coords[i*3+1], coords[i*3+2]
pts.Set(i + 1, x, y, z)
obj_id = get_free_object_id(ID)
objects.CreateContour(obj_id, pts)
obj = objects.Get(obj_id)
if nom and structure.Labels.IsAvailable(RobotOM.IRobotLabelType.I_LT_CLADDING, nom):
obj.SetLabel(RobotOM.IRobotLabelType.I_LT_CLADDING, nom)
obj.Update()
results.append(f"Cladding {ID} créé")
except Exception as e:
results.append(f"Erreur cladding {ligne[0]} : {str(e)}")
OUT = results
This code may seem good but after the execution I'm gonna have the error "Unable to find reference interop robot om " even I have the dll file and after fixed it they say the SetSize is not usable for this class object.
Thank you in advance,
M.G