[New Feature Preview] Python 3 Support Issue Thread

I tried a lot of things, but I didn’t try that. This works! Thank you so much.

1 Like

Hi @keith.sowinski,

Just wanted to add a note here: Due to how they are designed (Out of our hands), there won’t ever be full parity between IronPython2 and CPython3 unfortunately. We have reached a large degree of parity, but to cover other bases we also now ship IronPython2 on the Package Manager to enable you to keep your original content and workflows :slight_smile:

2 Likes

Any ideas on how to resolve this difference? I want to return the actual type, not the value number.


https://help.autodesk.com/view/CIV3D/2020/ENU/?guid=a11fcbba-1e90-ad37-d265-2243da4da299

Hello,
is there an implementation of IronPython 3 in the near future ?
The current target a Python 3.4 compatible release and the “DO NOT USE” instruction has recently been removed

2 Likes

It has been in the “Do not use” state for a long time - hence why we made the decision to implement CPython3 :slight_smile:

2 Likes

I don’t think we have any plans to implement ironPython 3.x - but it’s possible - there is some work to enable fully dynamic engine selection, serialization, etc - if someone wanted to do this -
then I think it would make sense to make it a package like we have done for IronPython2 - so IronPython 3 is just another dependency of the graph that can be downloaded using the workspace references tool.

2 Likes

The Figure is generate from within Dynamo Node?
In my case, nothing happens after plt.show() is executed.

2 Likes

@jostein_olsen managed to get plt.show() working in his set-up, but had to change something to do so. We’ve had a cursory look and were unable to figure out what was going wrong without a deeper dive :frowning:

If anyone else in this thread knows, then please do sing out! Otherwise, there is a workaround right now to use the Bitmap library, as follows by @c.poupin Python 3 Skelitonization - plt.show() not work - #7 by c.poupin

1 Like

Hello,
Although it was mentioned in the wiki, here is an example of a bug with a family load via a .NET interface.

Screenshot_9

import clr
import System
import uuid
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

class FamilyOption(IFamilyLoadOptions) :
    def OnFamilyFound(self, familyInUse, overwriteParameterValues):
        overwriteParameterValues = False
        return True

    def OnSharedFamilyFound(self, sharedFamily, familyInUse, source, overwriteParameterValues):
        overwriteParameterValues = False      
        return True

path = System.String(IN[0])
TransactionManager.Instance.EnsureInTransaction(doc)
opts = FamilyOption()
dummyFamily = None
loadFamily = doc.LoadFamily(path, opts, dummyFamily )
TransactionManager.Instance.TransactionTaskDone()


OUT = loadFamily

I try to change the namespace of the class (with __namespace__ attribute) but it’s unstable.
Example
If I modify a family parameter (in family editor) and i re-load with the same script Revit crash

maybe related issues

2 Likes

CC @Aaron_Tang @martin.misol

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’.

I have started this topic on the Robot Structural Analysis forum and was directed to share my problem here. Could someone of you @DynamoTeamMembers have a look?(check also message 11)

and possible reply to these 3 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?

Thanks in advance

Gr Edward

Hi @1234eddie I’ll try to address your questions.

But first something to keep in mind - you can disable the ironPython warnings in the settings menu - eventually Dynamo may no longer ship Ironpython - but you can still use it if you don’t want to or can’t move up to CPython3. The IronPython engine is available as a package on the dynamopackage manager.

  1. That is not the main goal of the migration tool - currently it migrates python2 to python3 syntax.
    It will also try to migrate a few extremely common differences between ironPython2 and PythonNet (how Dynamo access CPython3) that are found.

If you have suggestions for other common issues that could be fixed by the migrator let us know here or in GitHub issues on the dynamo project - it’s most likely to be investigated if each report is easily reproducible with few dependencies, and is broken out from a giant script.

  1. In general, the migrator is pretty good at python2 vs python3 - likely the issues you are running into are IronPython vs PythonNet - the wiki, (posted above in this thread) is a good place to check, Work in progress to improve Python 3 support · DynamoDS/Dynamo Wiki · GitHub, and this thread is another to ask for specific issues, also the pythonNet GitHub is a good resource. GitHub - pythonnet/pythonnet: Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET developers.

  2. This should not cause indentation errors, but you’ll likely need to use spaces thereafter.

Hello,
strangely with the CPython3 engine non-iterable objects contain an __iter__ method

2 Likes

:grimacing:

1 Like

does this happen with all element types or only views?

Obviously, this happens with any type of object

1 Like

yep

appears the base class PythonNet CLR object wrapper tries to implement iter for IEnumerable - I don’t think theres a great fix for it, maybe add a custom encoder for Revit element types - or document it very well. Will have to think think about it.

3 Likes

Not limited to Revit. This was created using Sandbox:
Python Iter attr issue

This is rather breaking in a good many packages, so fairly significant in terms of finding a resolution. Since strings (and I’d assume paths) and basic geometry also fail I don’t think Revit team is first up to fix. Filed a GitHub issue here: Python 3 incorrectly reports `__iter__` atribute. · Issue #11869 · DynamoDS/Dynamo · GitHub

5 Likes

ah nice, it seems another bug that is fixed in PythonNet 3 - .NET class instances considered Iterable · Issue #1234 · pythonnet/pythonnet · GitHub

4 Likes

CPython returning different results than IronPython

below is the result in both versions of the list named “views”

and now the result of view.ViewType

any ideas?

import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)


dataEnteringNode = IN
reset = IN[0]

doc = DocumentManager.Instance.CurrentDBDocument
if reset > -2:
	collector = FilteredElementCollector(doc)
	viewz = collector.OfClass(View).ToElements()
	
viewlist = list()
for view in viewz:
	if view.ViewType == ViewType.ThreeD:
		if not(view.IsTemplate):
			viewlist.append(view)
	else:
		viewlist.append(view)



viewtemplates = []
views = []

plans=[]

for view in viewlist:
	if view.IsTemplate == True:
		viewtemplates.append(view)
	else:
		views.append(view)
	
if IN[1]:
	typ='ThreeD'
else:
	typ='EngineeringPlan'
outlist=[]
for viewinst in views:
	outlist.append(viewinst.ViewType)
	if str(viewinst.ViewType) == typ:
		plans.append(viewinst)
	

#OUT=views
OUT = outlist