Creating SampleLineGroup and SampleLine using AutoCAD Civil 3D .NET API

By Partha Sarkar

In this post,
let's see how to create SampleLineGroup and SampleLine using new .NET API in
Civil 3D 2014 release.

Samplelines
are used to cut sections across an alignment. Samplelines are lines placed
along an alignment at a specified station interval (or at defined stations of
interest, such as at assemblies of a corridor object), using a specified left
and right swath width. SampleLine objects are contained in SampleLineGroup
objects, which organize multiple related sample lines. A SampleLine is used to
create a SectionView object, which displays some or all of the sections sampled
at that sample line.

We can create
a new SampleLineGroup object using SampleLineGroup.Create(string
groupName,  ObjectId alignmentId
)

And we can
create new SampleLine using the SampleLine.Create() static method which has two
different variants –

public static ObjectId Create(string sampleLineName, ObjectId sampleLineGroupId, double station);
    
 public static ObjectId Create(string sampleLineName, ObjectId sampleLineGroupId, Point2dCollection points);

 

C# code
snippet below, shows how to add a SampleLineGroup and a SampleLine using
Create(string sampleLineName, ObjectId sampleLineGroupId, Point2dCollection
points) –

Alignment alignment = trans.GetObject(alignmentId, OpenMode.ForWrite) as Alignment;
 
ObjectId slgId = SampleLineGroup.Create("My SampleLineGroup", alignment.ObjectId);
SampleLineGroup sampleLineGroup = trans.GetObject(slgId, OpenMode.ForWrite) as SampleLineGroup;
 
// Creating Sample line from a selected set of Points
 
Point2dCollection points = new Point2dCollection();
Point2d samplelineVertexPoint1 = new Point2d(4528.7808,3884.1900);
points.Add(samplelineVertexPoint1);
Point2d samplelineVertexPoint2 = new Point2d(4545.6858,3859.4065);
points.Add(samplelineVertexPoint2);
ObjectId slatStationId = SampleLine.Create("SampleLineByPoints", slgId, points);
 
SampleLine sampleLine = trans.GetObject(slatStationId, OpenMode.ForWrite) as SampleLine;
sampleLine.StyleId = civilDoc.Styles.SampleLineStyles[0];
 
 
Here is the result -

Comments

2 responses to “Creating SampleLineGroup and SampleLine using AutoCAD Civil 3D .NET API”

  1. I created Sample Line Group with using NET. AUDIT find two errors – not set parameters for Sample Line Group. In COM API this parameters may be set in method Add: AeccSampleLineGroup Add(string Name, string Layer, AeccGroupPlotStyle GroupPlotStyle, AeccSampleLineStyle SampleLineStyle, AeccLabelStyle SampleLineLabelStyle);
    Command line log:
    Command: _AUDIT
    Fix any errors detected? [Yes/No] : Y
    Auditing Header
    Auditing Tables
    Auditing Entities Pass 1
    Pass 1 5700 objects auditedSample Line Group (Sample Line Style)
    eNullObjectId Standard
    Sample Line Group (Label Style)
    eNullObjectId Standard
    Auditing Entities Pass 2
    Pass 2 5700 objects audited
    Auditing Blocks
    58 Blocks audited
    Auditing AcDsRecords
    Total errors found 2 fixed 2
    Erased 0 objects

  2. Thanks Dmitry !
    I could reproduce it. I have logged this issue in our internal system to investigate it further. I hope this would be addressed soon.
    Thanks again !
    Partha

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading