In Civil 3D
.NET API, Alignment class has an overloaded method named
CreateOffsetAlignment() which allows us to create an offset Alignment. One of
the overloaded methods Alignment.CreateOffsetAlignment (Double) is now obsolete
[ 2013 & 2014 release].
There is a
code sample on how to create offset Alignment available at Civil 3D
installation folder :
<Civil 3D
Installation Folder>SampleCivil 3D APIDotNetCSharpOffsetAlignmentDemo
This sample
uses the following version of CreateOffsetAlignment() –
public
static ObjectId CreateOffsetAlignment(
string alignmentName,
ObjectId parentAlignmentId,
double offset,
ObjectId styleId
)
Alignment.CreateOffsetAlignment(String.Format("Offset {0} Right", d), alignId, d, styleId);
In the Code
sample you will notice it tries to get the styleId for a specific Alignment
style and if that style object is not present in your test DWG file your
application will throw an error. So, you need to be careful to modify the
following line of the sample code as per your requirement –
var styleId = doc.Styles.AlignmentStyles["Offsets"];
And here is
the result you will see if you successfully run the same code sample in Civil
3D :


Leave a Reply