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 ??
# 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!
# 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
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
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:
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:
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:
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 I think you all understand my point of view.