Profile.CreateOffsetProfileBySlope() in python node keeps crashing

Hi,
If anyone can assist with this python code I am trying to run the .net api function Profile.CreateOffsetProfileBySlope() from a python node.
I am trying to test if its possible to create an offset alignment and offset profile and keep the dynamic mode for these as per GUI tools in order to preserve desiign intent.

I have a test dwg I am uploading where I am trying GUI workflows for creating Offset Alignments and Offset Profiles and also comparing with doing same in Dynamo and comparing results to see if its possible to get dynamic mode between alignments and profiles?
Please if any experts have the knowledge can you advise if this cannot be done at this time and whether future versions will allow?
Also would be interested in any workarounds for this in multi team project environments where design will go through different stages and be worked on by many individuals mostly using GUI tools, but if a consistent dynamo philosphy to tackle this has been concieved already ??

Anyways here is my dynamo graph and code:

Here is an image of the dynamo graph:


offset_profiles_test.dyn (43.6 KB)
offset_profiles_test.dwg (962.5 KB)

Here is the python node code

# Load the Python Standard and DesignScript Libraries
import sys
import clr

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')

# 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 from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
# Input variables from Dynamo
profileName = IN[0]  # Name for the new offset profile
offsetAlignmentName = IN[1]  # Name of the existing offset alignment
styleName = IN[2]  # Profile style name
slope = IN[3]  # Slope for the offset profile

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

with adoc.LockDocument():
    with adoc.Database as db:

        with db.TransactionManager.StartTransaction() as t:
            # Create the offset profile by slope
            offset_profile_id = Profile.CreateOffsetProfileBySlope(
            profileName,
            offsetAlignmentName,
            styleName,
            slope
        )

            # Commit before end transaction
            t.Commit()
            pass

# Assign your output to the OUT variable.
OUT = offset_profile_id

keep getting error No Method matches given arguments OnExit:(<class 'Autodesk.AuoCAD.ApllicationServices.DocumentLock…and unhandled exception then it bombs CAD!

Any help appreciated
cjm

Try this:

# Load the Python Standard and DesignScript Libraries
import sys
import clr

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('Civil3DNodes')


# 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 from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

# Import references for Dynamo for Civil 3D
from Autodesk.Civil.DynamoNodes import Alignment as DynAlignment

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
civdoc = CivilApplication.ActiveDocument

parentprofilein = IN[0]           #profile
offsetalignmentname = IN [1]        #offsetalignment name, str
offsetprofilestyle = IN[2]        #style, str
slope = IN[3]                     #slope, double

result = []

def cmoalignments(parentprofilein,offsetalignmentname,offsetprofilestyle,slope):
	global adoc
	global editor
	global civdoc
	
	try:	
		with adoc.LockDocument():
			with adoc.Database as db:
				with db.TransactionManager.StartTransaction() as t:
					slopepercent = slope/100
					parentprofileId = parentprofilein.InternalObjectId
					parentprofile = t.GetObject(parentprofileId, OpenMode.ForRead)
					offsetprofile = parentprofile.CreateOffsetProfileBySlope(offsetalignmentname,offsetalignmentname,offsetprofilestyle,slopepercent)
					t.Commit()

	except Exception() as ex:
		result.append(ex.message)
	return result

# Assign your output to the OUT variable.
OUT = cmoalignments(parentprofilein,offsetalignmentname,offsetprofilestyle,slope)


Hi Kovacsv ,
Thanks for your assistance with this, unfortunatley it is still crashing, I am uploading a screenshot of warning message and the crash dump.txt Not sure If you have any ideas?
Regards,
cjm


crash_dump.txt (98.6 KB)

Try switching to Ironpython 2.7. If you don’t have it, you can download it as a package.
It works for me

Hi Kovacsv,
Very Interesting… Thankyou so much for this, I think it is great we can create offset profiles and maintain the objects dynamic mode in c3d!
I have posted another thread discussing the lack of this functionality and how it impacts on complex workflows, this is obviusly a good hack until we get support for it to work in cpython moving forward.
Any tips how you retro installed Iron Python in the latest dynamo versions??
Regards,
cjm

sorry yes you said you can download as a package, my bad, I found it now, cheers

Hi @cjm,

There is an issue in your code that will cause it to fail regardless of which version of the Python engine is used.

offset_profile_id = Profile.CreateOffsetProfileBySlope(profileName, offsetAlignmentName, styleName, slope)

This API call is an instance method, which means that it must be called using the object ID of the parent profile. You can see this in the API documentation:
image

In your code, you are attempting to call the method as if it were a static method. You can see the difference in the sample from @kovacsv:

parentprofileId = parentprofilein.InternalObjectId
parentprofile = t.GetObject(parentprofileId, OpenMode.ForRead)
offsetprofile = parentprofile.CreateOffsetProfileBySlope(offsetalignmentname,offsetalignmentname,offsetprofilestyle,slopepercent)
1 Like

Hi @mzjensen,
Thankyou for your assistance. Yes I noticed this after @kovacsv sent me his code, but even after I have modified my original It still crashes.
Here is message:

Here is Code:

# Load the Python Standard and DesignScript Libraries
import sys
import clr

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')

# 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 from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

# .net api inputs for creating offset profile
parentprofilein = IN[0]  # profile
offsetalignmentname = IN[1]  # offsetalignment name, str
offsetprofilestyle = IN[2]  # style, str
slope = IN[3]  # slope, double

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

with adoc.LockDocument():
    with adoc.Database as db:

        with db.TransactionManager.StartTransaction() as t:
            # 
            slopepercent = slope/100
            parentprofileId = parentprofilein.InternalObjectId
            parentprofile = t.GetObject(parentprofileId,OpenMode.ForRead)
            OffsetProfName = offsetalignmentname+"dynProf"
            offsetprofile = parentprofile.CreateOffsetProfileBySlope(OffsetProfName,offsetalignmentname,offsetprofilestyle,slopepercent)
            t.Commit()
            pass

# Assign your output to the OUT variable.
OUT = parentprofileId

Any further help appreciated.
Regards,
cjm

@kovacsv said

Try switching to Ironpython 2.7

Thankyou @hosneyalaa

I think it would be better if we could get a cpython solution here moving forward?

not sure if it’s just me, but I have had similar issues trying to get other api code to work in cpython.

it can be discouraging for those of us who spend most of their time as designers and just dip in and out of coding, when there is available time.

It would be great to expand the examples of working code using cpython, I have done c# coding and yes it’s great and provides more robust solutions, but if you are a real scripter, someone who just tinkers now and then to get solutions to automate workflows, then python is the fastest way, to prototype if we have templates for working code, otherwise you can waste alot of valuable time.

Anyways excuse my moaning :slight_smile: I think you all understand my point of view.

cjm

Hi,

Can you update the script to take List input? right now it only takes a single input. I have so many alignments.