Hi.
In this post, Partha showed how to create a new sample line group and a new sample lines within that slg:
I have checked what is the default sample lines width (create sample lines command):
Autodesk.Civil.Settings.SettingsCmdCreateSampleLines SobreanchosSamples = default(Autodesk.Civil.Settings.SettingsCmdCreateSampleLines); SobreanchosSamples = civilDoc.Settings.GetSettings<Autodesk.Civil.Settings.SettingsCmdCreateSampleLines>(); SettingsCmdCreateSampleLines.SettingsCmdSwathWidths anchos = SobreanchosSamples.SwathWidths; double anchoIzquierda = Convert.ToDouble(anchos.LeftSwathWidth); double anchoDerecha = Convert.ToDouble(anchos.RightSwathWidth);
But how can I put these values (left width and right width) for a new sample line?
Sample line class doesn´t have "left width" or "rigth width" property ¿?
Do I have to create a new vertex? However I think that I can´t add new vertex in vertexcollection.
Thanks in advance.
Solved! Go to Solution.
Solved by Jeff_M. Go to Solution.
Is it obligatory create sample lines by points if I want to create sample lines with widths?
public static ObjectId Create(string sampleLineName, ObjectId sampleLineGroupId, Point2dCollection points);
When creating a new Sample Line with
public static ObjectId Create(string sampleLineName, ObjectId sampleLineGroupId)
doesn't it use the values for the Command Defaults? If so, change the default to the desired value prior to creating the sample line. I don't have any code handy to verify this myself at the moment.
"doesn't it use the values for the Command Defaults? If so, change the default to the desired value prior to creating the sample line. I don't have any code handy to verify this myself at the moment."
No,it doesn´t.
Look at the screenshoots. I have created my sample line group and all sample lines have left width and rigth width = 0
And the default value for create sample line command: (with left witdh and rigth witdh = 20 meters)
And how can I convert "PropertyDouble" as double? because I have a debug exception in:
double anchoDerecha = Convert.ToDouble(anchos.RightSwathWidth);
Well, in my opinion the Create method that takes just the name and SampleLineGroup ID is broken...or at least unfinished. The SectionLine does get created but with just 1 vertex at the centerline. Since we have no mechanism to add or adjust offests with the API, this method is essentially useless to us.
That leaves the other Create method which needs the vertices passed, and thereby requires us to calculate the vertices ate the desired offsets.
Here's a solution to the inability to iuse the offsets directly. I created a method with 2 overloads, one will use the default offset values, the other allows you to pass any values for the right & left you like.
using Autodesk.Civil.ApplicationServices; using Autodesk.Civil.DatabaseServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.Civil.Settings; namespace Civil3D_Misc_Commands.Sections { public class SectionTests { [CommandMethod("SectionTest")] public void sectiontestcommand() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; CivilDocument civdoc = CivilApplication.ActiveDocument; using (Transaction tr = db.TransactionManager.StartTransaction()) { ObjectId alId = civdoc.GetAlignmentIds()[0]; //get the first Alignment in the drawing ObjectId slgId = SampleLineGroup.Create("TestGrp", alId); double station = 100.00; //add a section at station 100 Point2dCollection points = GetOffsetPoints(alId, station); ObjectId slId = SampleLine.Create("TestSampleLine1", slgId, points); tr.Commit(); } } //this overload will use the drawing's default offset values private Point2dCollection GetOffsetPoints(ObjectId alId, double station) { SettingsCmdCreateSampleLines.SettingsCmdSwathWidths widths = CivilApplication.ActiveDocument.Settings.GetSettings<SettingsCmdCreateSampleLines>().SwathWidths; return GetOffsetPoints(alId, station, widths.LeftSwathWidth.Value, widths.RightSwathWidth.Value); } //this overload accepts the offset values to use private Point2dCollection GetOffsetPoints(ObjectId alId, double station, double leftOffset, double rightOffset) { Point2dCollection result = new Point2dCollection(3); Alignment al = (Alignment)alId.GetObject(OpenMode.ForRead); double east = 0.0, north = 0.0; al.PointLocation(station, -leftOffset, ref east, ref north); Point2d pt = new Point2d(east, north); result.Add(pt); al.PointLocation(station, 0, ref east, ref north); pt = new Point2d(east, north); result.Add(pt); al.PointLocation(station, rightOffset, ref east, ref north); pt = new Point2d(east, north); result.Add(pt); return result; } } }
Oh my god!
A time ago I did my own function to get point from station and offset. jajajaja
I didn´t know PointLocation function.
I will try your code snippet. I think it will run fine.
Thanks Jeff.
With point2dCollection works fine.