Hey Guys,
I extended the code with offset profile. It is in the 2021.1 API guide.
https://help.autodesk.com/view/CIV3D/2021/ENU/?guid=176ac8e5-a883-70d8-5617-015c9d466419
Needs some refinement (for e.g. making sure the right parent profile is used, and error massages) but does the job.
adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
civdoc = CivilApplication.ActiveDocument
align = IN[0]
alignmentstyle = IN[1]
offset = IN[2]
offsetprofilestyle = IN[3]
slope = IN[4]
result = []
def cmoalignments(align,alignmentstyle,offset,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
n = align.Count
for i in range(0,n):
# get parent alignments to offset
alignment = align[i]
alignmentId = alignment.InternalObjectId
al = t.GetObject(alignmentId, OpenMode.ForRead)
alname = al.Name
# offset alignment name suffix and side variables
bbsz = "BBSZ"
jbsz = "JBSZ"
lso = offset * -1
rso = offset * 1
# get parent profile
profileId = al.GetProfileIds()[0]
profile = t.GetObject(profileId, OpenMode.ForWrite)
profilename = profile.Name
# Left offset Alignment
leftoffsetalname = alname + " " + bbsz
leftoffsetId = al.CreateOffsetAlignment(lso)
leftoffsetal = t.GetObject(leftoffsetId, OpenMode.ForWrite)
leftoffsetal.Name = leftoffsetalname
leftoffsetal.StyleName = alignmentstyle
result.append(leftoffsetalname)
# Left offset Alignment Profile
loprofile = profile.CreateOffsetProfileBySlope(leftoffsetalname,leftoffsetalname,offsetprofilestyle,slopepercent)
# Right Offset Alignment
rightoffsetalname = alname + " " + jbsz
rightoffsetId = al.CreateOffsetAlignment(rso)
rightoffsetal = t.GetObject(rightoffsetId, OpenMode.ForWrite)
rightoffsetal.Name = rightoffsetalname
rightoffsetal.StyleName = alignmentstyle
result.append(rightoffsetalname)
# Right offset Alignment Profile
roprofile = profile.CreateOffsetProfileBySlope(rightoffsetalname,rightoffsetalname,offsetprofilestyle,slopepercent)
t.Commit()
except Exception() as ex:
result.append(ex.message)
return result
# Assign your output to the OUT variable.
OUT = cmoalignments(align,alignmentstyle,offset,offsetprofilestyle,slope)