[New Feature Preview] Python 3 Support Issue Thread

Thanks @c.poupin,
I tried to translate the examples you provided to work with my code and unfortunatley I am either not getting it OR there is another issue that is stopping this from working.
Please see my amended snippet of my previous attempt:

  global adoc
    global cdoc
    s1 = "station" #dummy inputs as per advice on other threads
    o1 = "offset"
     # use float as no longer able to use
    # - strongbox functionality  as per ironpython i.e. Double #clr.Reference[float]()
    station = 1.23 
    offset = 1.23 

    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
                            # so trying to use 'dummy' inputs and station offset will be returned to assigned float vars?
                            station,offset=alignment.StationOffset(easting[ind], northing[ind],s1,o1) 
                            sta.append(station)
                            offs.append(offset)
                            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)

This crashes Civil 3d with unhandled Type Error.

Any further feedback appreciated, maybe @Paolo_Emilio_Serra1 could advise to correct solution here is possible, thanks.

Cm

@cjm
dummy variables must be same type as ref or out parameters

https://help.autodesk.com/view/CIV3D/2022/ENU/?guid=c6fe2704-261c-3cbd-d159-4d3324963f6f

@c.poupin Was there ever a solution/workaround for the family load code you pasted a while back? I’m trying to get that exact same code to work in CPython3 and am having the same issue you experienced (“interface takes exactly one arguement…”). Thanks!

Hi, @jpclark

currently, I didn’t found a stable solution

Hi @c.poupin,

any update on that issue? Could you solve it or is there no way to fix that?
I ran into the same problem unfortunately…
Thank you in advance for your answer!

Hello,
for which issue ? Net interface ?

Yeah, the bug with family load via .NET interface.

no, I have the impression that PythonNet 2.5.2 fails to Release all resources for some Revit Objects created.
I’m waiting for PythonNet 3.0 hoping that fixes the problem.

IronPython3 final should be released soon too

2 Likes

Hi all,

Has anyone already tried to connect to the Civil 3D COM API from inside Revit 2023 with CPython3?

This code gives me an error at the first run:

If I do a rerun, I get this:

Removing the “import Autodesk.AutoCAD.Interop” solves the "protected memory’ warning.

Am I missing something with this new Python engine?

Yes, but you may not have a good way around it.

Since CPython is running in C, and the COM apis are running in C#, I think you’ll need to explicitly import the windows COM client (win32com). If that doesn’t work then it may be that you’d have to go through the process of building the COM interop at the level which the Python engine is executing. However before you consider that, I’ll quote a stack exchange post:

implementing or using COM components in C requires a horrendous amount of work, but higher-level languages like Visual Basic have done a lot to ease the implementation and use of COM components

Assuming that is out, and you can’t find a way to interact with the win32com client directly, then you still ahve options.

  1. Install the DynamoIronPython2.7 package. This will give you IronPython and ensure previous code works, at the cost of having a possible security risk on the system.
  2. Switch out of the COM api and utilize the .net api directly. This would be the direction I’d recommend, as your code will be faster and more reliable than the COM library you’re using, and you’re already in the same tool so you need not marshal data between processes.

In the longer term, there is an IronPython implementation of a supported Python version which may be ported over to Dynamo in the future. Make no purchasing decisions, but I’ll be a proponent of this.

1 Like

Hi @DonnyVA
Which version do you have for Civil 3D

Hi Jacob,

I looked at the win32com module. It seems that module is not installed with Dynamo in Revit so that is an additional issue. How would you use/install that module and make sure that other users have it too?

Option 1 is possible but I rather would use it as a last resort.
Option 2 is not possible because I want to talk with Civil 3D from inside Dynamo in Revit. I’m not in the same tool so I do need to marshal data between processes (Civil 3D and Revit), or am I that wrong?

I know about the CivilConnection package but I already created my own custom nodes and scripts before that package was widely available.
Maybe I do have to use this package or create my own .NET nodes.

And hi Hosneyalaa,

It seems you didn’t read my question that well.
It doesn’t matter which Civil 3D I want to use.
I am unable to import ANY “Autodesk.AutoCAD.xxx” or “Autodesk.AECC.xxx” module with CPython3.

This is a part of windows. Might be best to look into how other tools accomplish this, in particular civil connection.

Hi @c.poupin - we’ve posted an experimental DynamoIronPython3 package to the package manager to checkout.

7 Likes

Wow, excellent we will be able to test it in a Revit, Civil, etc. application context :clap: :+1:

2 Likes

Hi, where I can learn more about IronPython 3 and why is it important?

this allows you to abandon Python2.7 and switch to python3 through the 2 python engines (Ironpython3 and CPython3/Pythonnet) which each have advantages (as example IronPython is Net native)

Eshan has summarized well here

3 Likes

I was using the upgrader thingy function to upgrade from 2 to 3…

But in a lot of my code all it did was suggest changing tabs to spaces.

I do recall somewhere there’s a function to set tab as your preference but I can’t find it. Someone point me in the right direction please :slight_smile:

There isn’t a button to do this, but if you use the CPython3 engine and try to tab, it will auto-convert these to 4x spaces :slight_smile:

And in the 2-->3 tool it will also do this for you.

Oh is that what’s happening! It’s been driving me crazy!
Can we have an upgrade to choose between tabs (good) and spaces (bad) :smiley: