Migrate Dynamo studio to RSA with dynamo

Migrate Dynamo studio to RSA with dynamo

1234eddie
Advocate Advocate
1,548 Views
11 Replies
Message 1 of 12

Migrate Dynamo studio to RSA with dynamo

1234eddie
Advocate
Advocate

Hi all,

 

I found/read the article that dynamo studio will stop as a program inside the AEC collection.

at the moment i have a lot of scripts running on dynamo studio with the structural analysis package.

So after digging i will go over to RSA 2022 with dynamo extension. so i have to migrate my scripts.

but the problem which occurs is that i wrote a lot of python scripts inside the .dyn files. and these when i open the script wil run on 'ironpython2' and dynamo gives the message that i have to migrate to 'Cpython3'.

"Python Migraton"
This graph currently contains nodes that are using the old IronPython2 (Python 2) engine which will be deprecated in later versions. A new CPython3 (Python 3) has been implemented and is accessible inside the Python editor.

 

This is my old script which runs perfect with dynamo studio. and with dynamo add-on on RSA 2022(set to ironpython2)

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

from System import Environment
user = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
clr.AddReferenceToFileAndPath(user +r"\Dynamo\Dynamo Core\1.3\packages\Structural Analysis for Dynamo\bin\RSA\Interop.RobotOM.dll")
from RobotOM import *
from System import Object

USec_name= IN[0]
USec_mat = IN[1]
USec_B = IN[2]
USec_H = IN[3]

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


lab_serv = IRobotLabelServer 
lab_serv = labels

sec = IRobotLabel
sec = lab_serv.create(IRobotLabelType.I_LT_BAR_SECTION, USec_name)

data = sec.data
data.Type = IRobotBarSectionType.I_BST_NS_RECT
data.ShapeType = IRobotBarSectionShapeType.I_BSST_RECT_FILLED

nonst_data = IRobotBarSectionNonstdData
nonst_data = data.CreateNonstd(0)

nonst_data.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_RECT_B,USec_B)
nonst_data.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_RECT_H,USec_H)
#nonst_data.SetValue(IRobotBarSectionNonstdDataValue.I_BSNDV_RECT_T,0)
data.MaterialName = USec_mat

data.CalcNonstdGeometry()

lab_serv.Store(sec)

OUT = sec.name

this is the dynamo graph

Graph.JPG

this is the migration message

Migration message.JPG

as you can see the ironpython2 works but the Cpython3  not.

the code inside Cpython3 is still the same as the code above. but i get this error message:
error message.png

 

So my question is: did i miss something beceause dynamo is now an add-on or is there something else wrong. 

please help me with this.

 

@Rafal.Gaweda @okapawal @vise92 @gwizdzm @StefanoPasquini6790 @JacquesGaudin saw your names in the forum post related to dynamo

 

thanks in advance

ps: file is attached.

 

Gr Edward

 

 

1,549 Views
11 Replies
Replies (11)
Message 2 of 12

JacquesGaudin
Advocate
Advocate

Assuming that the new CPython 3 is using PythonNet (which would be great news IMO), you need to replace ``clr.AddReferenceToFileAndPath(<your path here>)" for "clr.AddReference(<your path here>)". Try that, chances are it will work.

0 Likes
Message 3 of 12

okapawal
Autodesk
Autodesk

I think the answer from @JacquesGaudin solves the issue.

 

We integrated the last Dynamo Core release 2.11 into RSA Extension.  I asked Dynamo team, they confirmed that there was this specific bug in the migrator, they has just fixed this function. 



Waldemar Okapa

Sr Product Owner
0 Likes
Message 4 of 12

1234eddie
Advocate
Advocate

@JacquesGaudin @okapawal thanks for your reactions so far.

i followed the description from @JacquesGaudin 

step 1 work fine(changing the 'addreferencetofileandpath' to 'addreference'.

but then i get this error

0_06 error 1.png

changed the c from create to a capital. (works. next error occurs)

0_06 error 2.png

so changed data into this:

0_06 error 3.png

 

and now i losed my mind in this. because this is what's in the API SDK tutorial.

SDK tutorial part 1.JPGSDK tutorial part 2.JPG

 

that's the source i use. So i don't get the point why i have to change these parts described above. I Hope someone of you can explain this to me so that i can solve my scripts easy.

(because i have some script over more than 500 lines)

 

thanks in advance.

 

0 Likes
Message 5 of 12

JacquesGaudin
Advocate
Advocate

The type inference with CPython works a bit differently to what IronPython is doing.

 

When you do ``sec = lab_serv.Create(...)`` you get a generic COM object that doesn't provide any interface. 

 

If you cast the object to the correct interface, you can start using it, like so:

 

``sec = IRobotLabel(lab_serv.Create(...))``

 

You'll get this issue a lot. I wrote my scripts with CPython and PythonNet so got used to it. Clearly in your case, you want it to be part of a migration script.

 

On another note, you don't need to assign the type to a variable before assigning a value in Python. So for example in:

 

```

sec = IRobotLabel

sec = lab_serv.Create(...)

```

 

The first line can be omitted altogether, I just assigns a value that gets overwritten in the next line.

 

 

0 Likes
Message 6 of 12

JacquesGaudin
Advocate
Advocate

@okapawal You're welcome. 

 

Whilst we're on the topic, I thought I would mention an issue I encountered when using the API under CPython.

 

If the CPython kernel is using PythonNet to communicate with the RSA API, there is an annoying bug in PythonNet where an integer value can't be cast to the correct enum type unless the value is explicitly defined in the enum.

 

This is annoying when the API enum doesn't declare the value you need, there is no way to just use an integer to substitute it, whereas in IronPython, an integer value would be automatically cast to the correct enum type.

 

I can provide more detail if you are interested.

0 Likes
Message 7 of 12

JacquesGaudin
Advocate
Advocate

@1234eddie Sorry forgot to ping you in the answer above.

0 Likes
Message 8 of 12

JacquesGaudin
Advocate
Advocate

@1234eddieI just checked that .dyn files are plain text, so if the migration script doesn't do the casting of new objects for you, you could think of writing a custom post-migration script to automate the fix of the issue mentioned above.

0 Likes
Message 9 of 12

1234eddie
Advocate
Advocate

Hello @okapawal 

 

I got some questions?

1. Is the migration tool going to be updated that it will transfer the scripts correct from ironpython2 to Cpython3?

(because I have multiple scripts with over more than 500 lines and several (15+) scripts like the one above. So converting these line by line would cost me more than a week to finish all these migrations.[not only for me, but I guess that a lot of other users will have to do the same.])

SO if the migration tool is going to be updated? When can we expect these upgrades?

 

2. If the migration tool doesn’t upgrade. Is there a list available which ironpython2 code corresponds to Cpython3?

(with this I and others don’t have to search through 2400 pages to find all codes we need)

 

3. When using the migration tool, it looks like that if you have wrote the ironpython2 format with ‘tabs’ the Cpython3 makes them spaces.

Is this the intended behavior of the migration and will this cause indentation errors?

 

I hope to hear from you soon. because as an engineer inside the company i have to discuss the above points with my director to how and when switch.(because these will have a big impact)

 

Thanks in advance.

 

Gr Edward

0 Likes
Message 10 of 12

okapawal
Autodesk
Autodesk

Dynamo update and integration to Robot could be planned in several months I guess.

 

But you can grab Dynamo Sandbox daily builds.  This issue is already fixed there.

you can find builds at https://dynamobuilds.com/

more information at this page https://github.com/DynamoDS/Dynamo/wiki/How-to-Utilize-Dynamo-Builds

 

Could you post your questions on the Dynamo forum please
https://forum.dynamobim.com/

We just integrate the the tools into Robot.  They will be able to answer your questions much sooner then me.



Waldemar Okapa

Sr Product Owner
0 Likes
Message 11 of 12

JacquesGaudin
Advocate
Advocate

@okapawal@1234eddie  

 

Just jumping in to avoid further disappointment.

 

 I just scanned through the migration source code and whilst the first issue with "AddReferenceToFileAndPath" is definitely fixed, the other of getting a bare COMObject when creating a new instance doesn't look like it's addressed.

 

 

0 Likes
Message 12 of 12

okapawal
Autodesk
Autodesk

@JacquesGaudin @1234eddie 

Could you report the issue at this thread

https://forum.dynamobim.com/t/new-feature-preview-python-3-support-issue-thread/51649/92

 

You may track changes to Python3 support at

https://github.com/DynamoDS/Dynamo/wiki/Work-in-progress-to-improve-Python-3-support

 



Waldemar Okapa

Sr Product Owner
0 Likes