[New Feature Preview] Python 3 Support Issue Thread

Hi Ben, good question! Please do note that the backing of both Python engines is different, and there will be differences because of that. We’ve endeavoured to meet parity wherever we could but it won’t ever be :100: % the same.

As such, we still enable access to IronPython2 via the Package Manager for workflows that are not captured.

That being said, any ideas on this one @Michael_Kirschner2 or @Aaron_Tang ? :slight_smile:

1 Like

it’s a known issue

should be fixed in next release of PythonNet

4 Likes

Found an alternative for Excel (without package installation) :wink:
need to deepen this


thanks for making the OpenXml assembly available in python engines

5 Likes

Hi,
Not sure if this bug has been reported, but for info the current version of PythonNet (2.5.1 in Dynamo) does not support Net math operator
here are 2 examples with comparator and geometry operation

1 Like

thanks @c.poupin I have not seen it before. I think it’s because ElementId is IComparable<T> - not IComparable, even pythonnet 3 does not seem to support the generic type.

3 Likes

@Michael_Kirschner2
not sure but this fix can be solved the bug ? seems to be implemented in future version of PythonNet (v3.?.?)

Yes, I ran into this a while back and was a huge pain to extract then add each value first, then make a new point again.

2 Likes

I’m having trouble translating a difference between IronPython2 and CPython3 within Dynamo. A lot of my code is breaking when I try to get methods that return lists, using a single element.

This is the error that I get, regardless of the method that returns a list:
Warning: TypeError : No method matches given arguments for GetValidTypes: (<class ‘Autodesk.Revit.DB.Viewport’>) [’ File “”, line 20, in \n’]

The same code has different outputs.
Index 1 is type(index 0).

.GetTypeId() works fine but .GetValidTypes() results in the error above.

Can anyone help?

import clr

#Revit References/Imports
clr.AddReference("RevitAPI")
clr.AddReference("RevitServices")

from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory
from RevitServices.Persistence import DocumentManager


doc = DocumentManager.Instance.CurrentDBDocument #Get the current document.

#Get all viewports in the current document.
allVports = FilteredElementCollector(doc) \
            .OfCategory(BuiltInCategory.OST_Viewports) \
            .WhereElementIsNotElementType() \
            .ToElements()

#vpId = allVports[0].GetTypeId()
#vpTypes = allVports[0].GetValidTypes()

OUT = [allVports[0], type(allVports[0])]

This seems to be related to PythonNet Overloading,
try using the static method
image

1 Like

I’m still missing something. Am I on the right track?

Add GetValidTypes to the lists of imported RevitDB modules. You can copy the exact text and paste it in after a comma appended to the end of line 8. :slightly_smiling_face:

I did try that. It’s a method in the Element Class though so it doesn’t recognize it. Any other suggestions? Having trouble wrapping my head around it.

Try element? I’ll give it a quick look tonight.


overloads resolution should be much better in future PythonNet version

an alternative solution with reflection (instance method), just for example

2 Likes

That’s exactly what I was looking for. Thank you!
Thanks for also including some code improvements in other lines.

1 Like

Hi all!
Did you know how to use strongboxes and overloads.fuctions in CPython3?
Thanks

you could try for the out params: Python NET call C# method which has a return value and an out parameter - Stack Overflow

overloads are definitely buggy in the current version of python net - see above.

3 Likes

Any ideas how to correct way to get civil 3d api c# types, for example this code originally from Poalo got station pffsets, works fine in iron python, but we dont have strongbox functionality in cpython3, I have tried lots of test code, not getting it to work:

typimport clr
#import System

# Add Assemblies for AutoCAD and Civil 3D APIs
clr.AddReference('acmgd')
clr.AddReference('acdbmgd')
clr.AddReference('accoremgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('AeccPressurePipesMgd')
clr.AddReference('acdbmgdbrep')
clr.AddReference('System.Windows.Forms')

# Add standard Python references
import sys

#sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')
import os
import math

# Add references to manage arrays, collections and interact with the user
from System import *
from System.IO import *
from System.Collections.Specialized import *
from System.Windows.Forms import MessageBox

# Create an alias to the Autodesk.AutoCAD.ApplicationServices.Application class
#import Autodesk.AutoCAD.ApplicationServices.Application as acapp

# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

# Import references for PropertySets
from Autodesk.Aec.PropertyData import *
from Autodesk.Aec.PropertyData.DatabaseServices import *

# Import references for Civil 3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

adoc = Application.DocumentManager.MdiActiveDocument
cdoc = CivilApplication.ActiveDocument
ed = adoc.Editor

names=IN[0]
northings=IN[1]
eastings=IN[2]

# Example function
def get_soe_by_en(name, easting, northing):
    """
    Returns a dictioanry with station and offset from the alignment.

    :param name: The name of the alignment
    :param easting: The easting value
    :param norhting: The northing value
    :returns: a dictionary with station and offset
    """

    global adoc
    global cdoc
# ------ strongbox funtionality not in cpython3 ------------
    station = clr.Reference[float]()
    offset = clr.Reference[float]()

    output = []
    nm=[]
    sta=[]
    offs=[]

    with adoc.LockDocument():
        with adoc.Database as db:
            with db.TransactionManager.StartTransaction() as t:
                bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
                btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
                alignment = None
                for ind,x in enumerate(name):
                    #ind=name.index(i)             
                    for oid in cdoc.GetSitelessAlignmentIds():
                        al = t.GetObject(oid, OpenMode.ForRead)
                        if al.Name == name[ind]:
                            alignment = al
                            alignment.StationOffset(easting[ind], northing[ind], station, offset)
                            sta.append(station.Value)   # how to return these guy's ???
                            offs.append(offset.Value)
                            break
                            
                    # Couldn't find the alignment with the given name
                    if alignment is None:
                        return
    #need to allow for start and and points and for flipping osl and os right points
    return [sta, offs]


OUT = get_soe_by_en(names, northings, eastings)e or paste code here

any help appreciated
cjm

hello @cjm
for Ref and Out parameter, see this post

more explanations here

2 Likes

Hi,
the UnwrapElement() method doesn’t work with Dictionaries (works fine with IronPython)
Here an example

1 Like