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.
I also got a Fatal Error when trying to run your script. attached is a modified script that does not crash Civil 3D
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 , 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!
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?
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 alignmentstyle = IN offset = IN offsetprofilestyle = IN slope = IN 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() 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)