CPython 3, Apply loads to Load cases

Hi all,

We are trying to migrate our scripts from IronPython2 to CPython3.

I am trying to apply loads to the load case “GCW” as picture shows. The original script is attached, it was done with version IronPython2 and it works, however when turning to CPython 3, there are some errors.

Warning: AttributeError : ‘__ComObject’ object has no attribute ‘Records’ [’ File “”, line 32, in \n’]

and I got problems with IRobotLoadRecordMngr.Count. Could you help me checking what is wrong with the script?

Thank you in advance.

Files are attached.

Best regards,

Stefany


import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

from System import Environment
user = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
sys.path.append(user+r"\Dynamo\Dynamo Core\2.11\packages\Structural Analysis for Dynamo\bin\RSA\Interop.RobotOM.dll")
clr.AddReference('interop.RobotOM')
#clr.AddReference(user+r"\Dynamo\Dynamo Core\2.11\packages\Structural Analysis for Dynamo\bin\RSA\Interop.RobotOM.dll")
from RobotOM import *
from System import Object

objects = IN[0]
LoadCaseID = IN[1]
ILRT = IN[2]
LoadPX = IN[3]
LoadPY = IN[4]
LoadPZ = IN[5]


application = RobotApplicationClass()
project = application.Project
structure = project.Structure
labels = structure.Labels
loads = structure.Cases

CreatedLoads = []
case = structure.Cases.Get(LoadCaseID)
simplecase = IRobotSimpleCase
simplecase = case
rec = IRobotLoadRecord
IRobotLoadRecordMngr = simplecase.Records
count = IRobotLoadRecordMngr.Count
for i in range(count+1)[::-1]:
	rec = simplecase.Records.Delete(i)
#for i in range(1,count+1,1):
#	rec = simplecase.Records.Delete(i)

for j in range(len(objects)):
	for k in range(len(objects[j])):
		Uniform = []
		Uniform.append(simplecase.Records.New(ILRT))
		LoadRecord = simplecase.Records.Get(Uniform[0])
		LoadRecord.SetValue(0,LoadPX)
		LoadRecord.SetValue(1,LoadPY)
		LoadRecord.SetValue(2,LoadPZ[j])
		LoadRecord.Objects.FromText(objects[j][k])
		CreatedLoads.append(LoadRecord.UniqueID)

application.Visible = True
application.Interactive = True
application.Project.ViewMngr.Refresh()

#Assign your output to the OUT variable.
OUT = CreatedLoads, count

Hi All,

Maybe @ina or @solamour or @sanzoghenzo can point you in a direction where these COM API are descibed how to call them with Cpython3

Hi,
in short, you can’t use CPython3 with robot.
Take a look at this discussion for more information.
Just use IronPython2 as I described in the quickstart guide.

1 Like

@sanzoghenzo
i’m sorry but i don’t agree with your statement.
on the RSA forum are already people who are using Cpython3.

The big difference between the IronPython2 and Cphyton3 is that you have to (re) call the correct _com objects.
for example: think of it as a tree with branches and leaves. with ironpython2 you could jump from leaf to leaf, with Cphyton3 you have to go back to the branch the leaf is connected to

Gr Edward

1 Like

Sorry @1234eddie, you’re right… it can be done. what I should have written is that you can’t do it easily

the friendlier way is to use this class to wrap each com object you encounter:

class ComObj:
    def __init__(self, obj):
        self.obj = obj
        self.typ = obj.GetType()

    def __getattr__(self, name):       
        def newm(*args):
            args = args or (None,)
            return self.typ.InvokeMember(
                name, 
                BindingFlags.InvokeMethod | BindingFlags.GetProperty, 
                None,
                self.obj,
                *args,
            )
        return newm

then @stefanyC6JZ7 can do:

case = loads.Get(LoadCaseID)
simplecase = ComObj(case)
records = ComObj(simplecase.Records)  # not sure if it's necessary, didn't try it

and use records in place of all the simplecase.Records calls.

@stefanyC6JZ7 : I see that you copy-pasted some low-quality code from this forum, I suggest you to read my quickstart guide and another code I refactored - with comments - to clean it up.

1 Like