CreateOffsetAlignment Python script Fatal Error

I started to create a script using CreateOffsetAlignment Method (Database, String, String, Double, String). Something in the code causing C3D fatal error, but interestingly it crashes even if I comment out everything leaving only one line in the block. Tried it with every line but I cannot find the problem. Other scripts are working, tried it with multiple drawings in C3D 2021.2.1 and 2020.6, same result.
multipleoffsetalignments.dyn (13.8 KB)
Thanks in advance.

Hi @kovacsv,

I also got a Fatal Error when trying to run your script. attached is a modified script that does not crash Civil 3D :slight_smile:

I tried to check where your script is causing Civil 3D to crash, but it is still a mystery to me.
multipleoffsetalignments.dyn (19.1 KB)


Thank you, @Assem.Daaboul. I wanted to try the other CreateOffsetAlignment methods, but your version gives the desired result so that will work for me :smile: , thanks.

Hi @Assem.Daaboul , do you any idea if it is possible to add the offset profiles as well? Can we access that option it via the API?

Thanks everyone! Great content in this forum!

Hi @Tiago.Caldeira,

I believe that you are referring to the option of creating offset profiles while creating the offset alignments similar to the below, right?

I’m not aware of a method to create the offset profiles while creating offset alignments. I’ve checked the documentation [here] (CreateOffsetAlignment Method) with no luck. Maybe you should create a new question for this?

Hey Guys,
I extended the code with offset profile. It is in the 2021.1 API guide.
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
		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
						# 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
						# Right offset Alignment Profile
						roprofile = profile.CreateOffsetProfileBySlope(rightoffsetalname,rightoffsetalname,offsetprofilestyle,slopepercent)				

	except Exception() as ex:
	return result

# Assign your output to the OUT variable.
OUT = cmoalignments(align,alignmentstyle,offset,offsetprofilestyle,slope)