[New Feature Preview] Python 3 Support Issue Thread

Hello @WrightEngineering - We are adding a Migration Assistant that will help migrate your IronPython2 code to CPython3 :slight_smile: The onus will be on the user to accept, or reject the proposed changes - and it won’t cover every single use case, but it should help save a lot of time and effort!

Beyond that I’m not entirely sure I’m reading your question correctly, but you can copy and paste existing Python code from Dynamo into other places, you’ll just have to strip out the Dynamo specific pieces (i.e myVar = IN[0] / OUT = 0).

2 Likes

Hello @takumi_ban - Dynamo 2.7 is not yet released into the wild - As of today our latest stable build is Dynamo 2.6.1. You’ll be able to explore it in the Sandbox variant in the not-to-distant future and can download here: https://dynamobuilds.com/

As @jacob.small said, however, you will need to wait for Revit to natively update to this version as Dynamo is no longer an Addin, but a feature of Revit.

2 Likes

That’s wonderful! Thanks solamour. What I mean exactly with my question: is will we eventually be able to copy dynamo nodes into a Python format? for example: In ArcGIS Pro, I can grab and drag a geoprocessing tool into a python window and see the tooltip with the required inputs. I am a beginner at using python windows within dynamo, so perhaps I just don’t understand how to leverage them correctly. I’ve just noticed that, as a beginner, I have trouble understanding how to translate dynamo node capabilities to a python window.

Perhaps, there is no equivalent/direct translation between them? Or I am just not familiar with documentation regarding this?

There are a couple of ways to do this :slight_smile: I’m not sure in the Civil3D world, but in the Revit one you can have a look into the https://thebuildingcoder.typepad.com/blog/revitlookup/.

In Dynamo native, you can use Python to explore this as follows:

  • Using the dir call to find the directory contents of an Unwrapped Element
  • Using the element.__doc__ to pull the DocStrings of an Unwrapped Element

Graph: WrightEngineering_Access_Directory_Via_Python.dyn (10.7 KB)

4 Likes

Great! I will look into this. Thank you so much!

1 Like

For Civils 3d there is also a similar Lookup tool called “Snoop Civil 3d” which can be found here(https://github.com/ADN-DevTech/Civil3DSnoop). This is installed/extracted to C:\Program Files\Autodesk\ApplicationPlugins

2 Likes

Hello everyone!

While we are still working on an Officially Supported Way(tm), here is how you can access these libraries today in Dynamo 2.7/2.8 as a workaround:

Note: Please make sure you are comfortable doing the following steps and make sure you read all of the Terms and Conditions to your satisfaction :pray:

Note: This isn’t the only way to do this, but is simply one way.

Steps:

  1. Download Anaconda - https://www.anaconda.com/products/individual

  2. After install, select the CMD.exe Prompt from the Home tab in the Anaconda Navigator (Install if you need to).

  1. This will open up the Command prompt in your (base) directory as Anaconda creates localized environments.

  2. Open up Dynamo 2.7 (or newer) and query the CPython version - as shown below (Note: Make sure you are in the CPython3 engine)

import sys

OUT = sys.version

  1. Go back to the Anaconda Command Prompt and create a new environment that uses the correct version of Python - In my case version 3.7.3. I’ve called this environment Dynamo373 and you use the following code to create it:
 conda create --name Dynamo373 python=3.7.3
  1. You then want to activate this environment, and do so by typing the following code directly into your Anaconda Command Prompt :
 conda activate Dynamo373 
  1. You can then use Pip to install to this particular environment with:
 pip install numpy 

Note you can install other packages here, like Pandas or Keras etc.

  1. Inside this Anacondas Command Prompt you will select the location path where they are being installed to your environment: In my case c:\users\amours\anaconda3\envs\dynamo373\lib\site-packages

  2. Back in Dynamo you will open up a new Python node, set it’s engine to CPython3 and then append this path to your sys.path location.

  3. Then you can simply import all of your desired libraries :slight_smile:

# Load the Python Standard and DesignScript Libraries
import sys
import clr

sys.path.append(r'C:\Users\amours\anaconda3\envs\Dynamo373\Lib\site-packages')
import numpy

zeros = numpy.zeros(5)
output = zeros.tolist()

OUT = output
14 Likes

Hello,
besides the differences between Python2 and Python3, there are also differences between IronPython and Pythonnet, for example with Pythonnet the conversion of Python objects is not the same as IronPython (Pythonnet does not convert all types of python objects to CLR object (Net))

There is also currently a big difference on the support of COMs objects, with Pythonnet we must use System.Reflection (with a wrapper or not ) to have access to properties and methods

9 Likes

Hello @c.poupin. Thanks for reporting. Your observation is correct, there is a conceptual difference between engines that goes beyond Python syntax. We are currently working on reducing the exposure of those differences to users.

This case in particular worked for me in the latest daily build of Dynamo. Please give it a try and let us know if there is something we missed. Thanks again for reaching out!

2 Likes

Thanks it’s works now, even with a recasting :slight_smile:

6 Likes

Here are a few things I have ran across, but perhaps these are all expected changes as well and I am just not familiar with CP3 to know.

I have found that the reference imports do not go as deep as they did in 2.7. For instance, this worked great in 2.7, but in CP3 I had to use ‘Visual.Generic’ inline to get to the depth I needed.

image

Also just a note that the ImportExtentions does not work as it did:

One other thing that could be nice for the converter would be “string.Contains” to if ‘char’ in str: since str.Contains(‘char’) doesn’t appear to work.

Another element for the converter may be list.Add to list.append
image

It also seems to be pretty slow and spins for a few moments when trying to Load up the autocomplete suggestions for imports etc. Previously you could keep typing, but now it stops, spins, spins, waits, then gives you a list.

1 Like

Thanks for the feedback @SeanP! We’ll get this into our backlog :slight_smile:

cc @Michael_Kirschner2 @Aaron_Tang @Aparajit_Pratap

1 Like

Hello some explanation

Basic Pythonnet package doesn’t implement this clr method (and others as IronPython, only GetClrType method as been implemented since 2017 ( Higher compatibility of the clr module with IronPython)

Note:
Anoter example we can’t use clr.Reference for pass a method as parameter
example here Link DWGs in Drafting Views? - #16 by Gui_Talarico
the workaround is using Reflection.

Pythonnet does not convert all python objects to CLR objects dynamically, some objects need a cast to use Net methods

Basic (additions are possible) Pythonnet’s Net implementation is nowhere near as good as Ironpython

2 Likes

in latest daily builds we have added ImportExtensions support.

4 Likes

We have now improved this process :slight_smile: Please have a look at the following link! https://github.com/DynamoDS/Dynamo/wiki/Customizing-Dynamo’s-Python-3-installation where we show you how to use Python 3 modules without having to install Anaconda.

11 Likes

@solamour Thank you for the link!

1 Like

Most welcome @Cezmi - it’s hot off the press this morning :smiley:

1 Like

Hello
some remarks with Dynamo 2.8 (but which are rather related to PythonNet)

  • Problem with auto-completion (native Python list has no “Add” method and PythonNet does not dynamically convert to NetList )


  • refs and out Parameter does not work (missing in PythonNet, I don’t know if you have the possibility to integrate it, or if there is a possibility of workaround)



  • Ditto for COM interfaces (missing in PythonNet, force to use reflection)




solution with Reflection without a wrapper

Note: clr.AddReferenceByName method does not exist under Pythonnet

I imagine that resolving Net compatibilities with de Pythonnet (especially coming from IronPython) should not be easy

8 Likes