Apply loads to cases RSA 2024

Hi all,

since a few months RSA 2024 is out. in our company we do have quite a few scripts that we rewrote from ironpython2 tot Cpython3 due to the switch from ‘dynamo studio’ to integrated dynamo.

Now we run in RSA 2022 with Dynamo 2.11. Works perfectly fine.
In RSA 2024 its the new 2.17 Dynamo.

and when we now start checking our scripts we have a problem with the load assignment.

This is what we get with 2022
image
image

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(case)
rec = IRobotLoadRecordMngr(simplecase.Records)
count = rec.Count

for i in range(count+1)[::-1]:
    rec.Delete(i)

for j in range(len(objects)):
    #for k in range(len(objects[j])):
    Uniform = []
    Uniform.append(rec.New(ILRT))
    LoadRecord = IRobotLoadRecord(rec.Get(Uniform[0])) 
    LoadRecord.SetValue(0,LoadPX)
    LoadRecord.SetValue(1,LoadPY)
    LoadRecord.SetValue(2,LoadPZ[j])
    LoadRecord.Objects.FromText(' '.join(str(objects[j]) for el in objects))
        #CreatedLoads.append(LoadRecord.UniqueId)        
        #LoadRecord.Objects.FromText(str(objects[j][k])) 
application.Visible = True
application.Interactive = True
application.Project.ViewMngr.Refresh()

OUT = objects

And this is what we get with RSA2024 (same script no changes).

I hope someone can explain and help us out with this problem of the _comobject.

This topic is also avaible on the RSA forum. with robot file

Eindgebieden V1_8_RSA2024_f.dyn (15.9 KB)

@ina @solamour @sanzoghenzo

Many thanks in advance

Hi @1234eddie
I wrote it in the quick start guide, and I suppose things didn’t change (I don’t use RSA anymore): you cannot use CPython with RSA! install the Ironpython package and run your python scripts with it.

1 Like

@sanzoghenzo

I understand your view about this, but i won’t give up as i know that it should be possible. i only need to find the correct way.

@Maciek_Kubica @JacobSmall @Jonathan.Olesen @Kibar or other dynamo team members of the structural packages

Hi all,

got probably the wrong name somewhere
@jacob.small and maby @gwizdzm or other dynamo teammembers are available

Hi all,

A little update on ths question.
See also the RSA forum

It seems like ‘IRobotLoadRecord’ is missing the ‘SetValue’ options. Does anyone have the same experience with RSA2024 en Dynamo 2.17??

Dynamo file
Eindgebieden V1_8_RSA2024_f6.dyn (16.5 KB)

@jacob.small @Kibar @Maciek_Kubica @Jonathan.Olesen @solamour or any other member who can help us out with this?

Many thanks in advance

Sol is on vacation and I don’t have Robot installed at the moment. I may have a project starting soon which would require it, so if that kicks off I will jump in if I can.

@jacob.small
Thanks for your answer. hope to hear from you soon, or are there any other members you know of who are familiar with the Dynamo for RSA.

This isn’t as much of a Dynamo issue as a RSA one - I’d continue to raise the issue in the RSA forum where you’ve had some guidance.

Hi,

I don’t know RSA, but I just tested out of curiosity, it seems that the Create method is not deprecated

Hi. We haven’t changed API in that area. So, I checked “Loads” API in c# project (is easier to debugging) and there everything works fine. The problem is elsewhere, but I don’t know where. We will look at that.

2 Likes

Hi @gwizdzm

Good to hear from you. if there is any progress or questions, please let me know.

Many thanks in advance.

Gr Edward

Hi @1234eddie @c.poupin @jacob.small
I apologize for the late reply but we had vacation time. After few tests we know that problem occurs when CPython3 is used. If you install package with the older version of Python in the new Dynamo (and you adapt a litle your code) evrything will works fine. Evrything works with other lenguages (C++, C#) too. Test was made with two version of Dynamo and two vwerion of RSA and we see that only Python version is important.
This is not a problem with “LoadRecord”. We found a few RSA methods witch work inproperlly too and returns invalid object for CPython3, or object is invalid interpreted on CPython3 side.
In this moment we try to investigete behaviour of different Python version outside of Dynamo enviroment.
We have three potential sources of bug:

  • somthing in the Dynamo enviroment when CPython3 is used,
  • CPython3 (and other new versions of Pythons?) interpreter ,
  • different implementation of a few API method in RSA witch are invalid treated in new Python version.
    That’s all we know now. I will let you know if we find anything.

Hi @sanzoghenzo
You write in the article Quickstart Guide for Dynamo in RSA 2023 that COM API doesn’t work in CPython3. Is this your experience with RSA API or you found that information about COM API somewhere? I see similar information here: Troubles with switching from IronPython2 to CPython3 but without explanation. I still can’t find the reason, we were sure that it should work (but we are not Python specialist). Especially that it works for many RSA COM objects.

Hi @gwizdzm,
I wrote the quickstart guide from personal experience, after a week of trying to use Python3.

I’ve explained it here.

The key points here:

  • Robot COM API are old, and Autodesk needs to provide a better, .NET API for things to work well with dynamo and python3
  • pythonnet, the Cpython3 engine used in dynamo, doesn’t support com api and probably never will
  • Dynamo developers made a huge mistake in pushing cpython as the default interpreter, especially for RSA, since everybody thinks it can be used flawlessly when it obviously it isn’t the case.

That being said, there’s a workaround to handle com objects described here but it’s tedious to use that class to wrap every single COM object.

Do yourself a favour and stick with IronPython 2 until Autodesk developers fix this nightmare…

1 Like

Hi @Andrea_Ghensi
Thanks for information. It’s still not clear for me why some COM objects are interpreted in right way but part not:

The TLDR of this is that this simply isn’t something that Autodesk can fix. Python 2 (and therefore Iron Python 2) had to be removed from Dynamo for security reasons, as it is no longer supported and therefore unsecure. Python is owned by a separate entity. Autodesk could implement a different flavor which interacts with the .net environment (just like Iron Python 2 and Iron Python 3), it isn’t our area of expertise. Microsoft (who owns the .net environment, Component Object Model or COM, and the Common Language Runtime or CLR) was the driving force behind Iron Python for a half decade before abandoning the project. I can’t confirm it, but I suspect much of the reliability of Iron Python 2 is likely due to their involvement.

The good news in all of this is that while neither Dynamo nor Autodesk can fix Python implementation issues, we can provide options.

Iron Python 2 should you want to risk it, CPython 3, and Iron Python 3 are all available as engines for you to deploy in your work. Flexibility is good in general as we can ‘get stuff done’ and work to develop in a secure environment.

One last note on this, I suspect a lot will change with the conversion from .net 4.8 to a more modern .net implementation (6, 7 or 8) with the 2025 product line. While some existing code will break, I’m hopeful that more things will be fixed int he long term by that modernization effort.

For info, it’s works with IronPython3 with RevitPythonShell

PythonNet 2.5.x has bugs with the .Net environment and the arrival of .Net 6 may not help things if PythonNet 2.5.x is maintained (instead of PythonNet 3.x)

However, PythonNet 3.x has significant changes (break)

2 Likes

eternal question on how to find the balance between security and productivity

while knowing that the delivery dates of the projects never change (it would be too easy otherwise :joy: )

4 Likes

@gwizdzm
Many thanks for your reply.
so if there is a solution with the Cpython3 let me know.
Because it’s now holding us back on upgrading to newer RSA versions.

Gr Edward

Hi everyone,

Here is my 2 cents worth on the issue.

  • Robot COM API are old, and Autodesk needs to provide a better, .NET API for things to work well with dynamo and python3

Agreed. Also the API is a bit messy, incomplete and cumbersome. However, I can’t see it being fixed without rewriting extensive parts of RSA software. One may just as well start form scratch as Arup did with GSA.

  • pythonnet, the Cpython3 engine used in dynamo, doesn’t support com api and probably never will

PythonNet supports COM, I’ve used it with other software successfully (Excel for example works like a charm). For those who are not sure what COM is, check out the wikipedia page.
I suspect that the way Robot’s API is written is a bit substandard compared to a Microsoft bulletproof approach, hence the bugs we observe.
This is not to say PythonNet is perfect, but it’s been around for a while and is still being actively developed.
To be clear, PythonNet is a piece of software written in C# and Python that allows two things: embedding CPython in a .Net application (i.e. the software offers a Python console to interact with it as well as GUI buttons) and accessing a .Net library from Python (our case here). It’s not an “engine” and it can be used elsewhere than in Dynamo.

  • Dynamo developers made a huge mistake in pushing cpython as the default interpreter, especially for RSA, since everybody thinks it can be used flawlessly when it obviously it isn’t the case.

I would argue that choosing IronPython is the source of all evil, as Microsoft decided to dump this somewhat unsuccessful project. McNeel’s Rhino has the same headaches trying to revert back from that decision. IronPython was written at a time where most companies looked at CPython thinking it would disappear in the next ten years unless a large company like Microsoft supports it. There is a lesson to be learned here about the success of an open-source language like Python.

Now what I’ve learned from using PythonNet is that there are a few things which are tricky to handle, namely:

  • .Net interfaces (too bad, Robot’s API is entirely written using them :slight_smile: ): there is no such thing as an interface in Python, so it translates to a class but it can’t be instantiated so easily if I remember correctly.
  • methods with multiple signatures: again no such thing in Python which is / was a typeless language.
  • passing arguments by reference: python simply doesn’t do that because of the clever way it creates namespaces for each scope (you can find workarounds with global but it’s usually a sign of something gone wrong). This is a difference in paradigm between .Net languages and Python, not much we can do about that.
  • enumerations: my understanding is that Enum’s in .Net inherited from C, whereas Python has a enum class which is a layer above this to bring more flexibility. There’s been some work being done on that in PythonNet 3+, and Robot’s enums work better with this latest changes.
1 Like