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 % the same.
As such, we still enable access to IronPython2 via the Package Manager for workflows that are not captured.
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
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.
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).
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.
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