Hi @c.poupin. You posted quite a few things there, let me go one by one.
Autocompletion
As you noticed, autocompletion for the CPython3 engine currently relies on the same mechanism used for the IronPython2 engine. Having an autocompletion engine specific for the new engine is currently on the works, but it didn’t make it to Dynamo 2.8.
Ref and Out
These two actually work with PythonNET but the way they do is not like in Iron Python and unexpected in my opinion. The ref/out parameters need to be provided but they are considered as inputs only. The output is actually obtained from the result of the function call, which is surprisingly a Python tuple. Here are a couple of examples showing this:
COM interop
For this one I don’t have a better workaround than yours, so I will have to cheat
Here is an example using Dynamo’s own .NET classes to help interact with Excel. Unfortunately
some of these functions are not public, but the idea can be used with a custom library that is part of a package for instance. That helps overcome the limitations regarding COM interop in PythonNET.
Thank you so much for the feedback @c.poupin. We will update our documentation with the issues you provided so that people can use it as reference in case they find themselves against them.
Just wanted to add an alternative for COM interop. This can be achieved also using Python --> COM integration, without going through .NET. There is a module called pywin32 that serves this purpose. Here is an example equivalent to the one I showed before but using this pywin32 instead of relying on a custom .NET library.
Hi @ustncz. I tried and got the same error you did. I think it’s because we are running Python from .NET, so the threading mode is already initialized.
I was actually able to use the library if I commented out the offending line, where CoInitializeEx is called.
Unsure if this is an actual error, or if it’s Error 45 (the error is 45 cm from the screen…)
I’ve followed the guidelines here to the point: Customizing Dynamo's Python 3 installation · DynamoDS/Dynamo Wiki · GitHub
and have been able to succesfully install ie pandas and numpy through pip.
Trying to use any of the modules gives me error messages like this one:
I am not an expert here and haven’t tried myself, but perhaps try changing line 13 to plt.pyplot.plot(lst,lst) and see where you get (would be a 45 degree line on a line chart if I am not mistaken).
Nah - this is more of a ‘wait this didn’t work, is it the code or the implementation?’ thing which the community is here for.
For reference, any issues I have seen have warnings like now ‘library of that name found,’ and will throw the error early when you do your imports (assuming you do them together and early), but your mileage may vary.
Hi, the current version of IronPython will be supported as a Dynamo extension which is wrapped as a Dynamo package so user should continue be able to use IronPython and leverage nodes written in IronPython. In a future version, CPython will be the default Python engine of Dynamo and IronPython will not be available OOTB, but you can always get it from package manager. So in short, no requirements yet.
I’m still struggling with collections and enumerators with CPython3. Here is an example using Dynamo for C3D.
If I want to get a particular alignment style with IronPython, I simply use: civdoc.Styles.AlignmentStyleCollection["MyStyleName"]
This does not work with CPython3. Can someone shed some light on this?
Thank you for looking at it. Here is the working code to get the object Id of an alignment style using IronPython. I’m trying to figure out what the CP3 equivalent is.
import clr
# Add Assemblies for Civil 3D APIs
clr.AddReference('AeccDbMgd')
# Import references for Civil 3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices.Styles import *
civdoc = CivilApplication.ActiveDocument
myStyleId = civdoc.Styles.AlignmentStyles["Basic"]
OUT = myStyleId
Here is what I came up with, but I would think there is a better way. Since I was unable to get the object id by name directly like I could with IronPython or C#, I needed to loop through the collection and query each objects name. Unfortunately, there is still a lot from the Civil 3D COM API that is not yet in the .NET API. Getting style names is one of those. Thank you to @c.poupin for the tip on using reflection.
This is definitely more difficult than IronPython.
import clr
# Add Assemblies for AutoCAD and Civil 3D APIs
clr.AddReference('acdbmgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('System.Reflection')
from System.Reflection import BindingFlags
# Import references from AutoCAD
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
# Import references for Civil 3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
adoc = Application.DocumentManager.MdiActiveDocument
civdoc = CivilApplication.ActiveDocument
styleId = None
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
styleCol = civdoc.Styles.AlignmentStyles
for i in styleCol:
styleObj = t.GetObject(i, OpenMode.ForRead)
comObj = styleObj.AcadObject
if comObj.GetType().InvokeMember("Name", BindingFlags.GetProperty, None, comObj, None) == "Basic":
styleId = i
break
OUT = styleId
import clr
# Add Assemblies for Civil 3D APIs
clr.AddReference('AeccDbMgd')
# Import references for Civil 3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices.Styles import *
civdoc = CivilApplication.ActiveDocument
myStyleId = civdoc.Styles.AlignmentStyles.get_Item("Basic")
OUT = myStyleId