Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

widths of new sample lines.

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
joantopo
642 Views, 8 Replies

widths of new sample lines.

Hi.

 

In this post, Partha showed how to create a new sample line group and a new sample lines within that slg:

http://adndevblog.typepad.com/infrastructure/2013/08/creating-samplelinegroup-and-sampleline-using-a...

 

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.

Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes
8 REPLIES 8
Message 2 of 9
joantopo
in reply to: joantopo

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);

 

Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes
Message 3 of 9
Jeff_M
in reply to: joantopo

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.

Jeff_M, also a frequent Swamper
EESignature
Message 4 of 9
joantopo
in reply to: Jeff_M

"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

imagen1.jpg

 

And the default value for create sample line command: (with left witdh and rigth witdh = 20 meters)

 

imagen3.jpg

 

And how can I convert "PropertyDouble" as double? because I have a  debug exception in:

 

double anchoDerecha = Convert.ToDouble(anchos.RightSwathWidth);

 

 

Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes
Message 5 of 9
Jeff_M
in reply to: joantopo

To answer your last question first:

double anchoDerecha = anchos.RightSwathWidth.Value;

I will have to do some testing regarding what is used by the Create method.

Jeff_M, also a frequent Swamper
EESignature
Message 6 of 9
Jeff_M
in reply to: Jeff_M

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.

Jeff_M, also a frequent Swamper
EESignature
Message 7 of 9
Jeff_M
in reply to: Jeff_M

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;
        }
    }
}

 

Jeff_M, also a frequent Swamper
EESignature
Message 8 of 9
joantopo
in reply to: Jeff_M

Oh my god! Smiley Frustrated

 

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.

 

Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes
Message 9 of 9
joantopo
in reply to: joantopo

With point2dCollection works fine.

 

capturada.jpg

Autocad C3D 2019 SP3, 2020 & 2021
Intel I9 9900K with frontal watercooler alphacool eisbaer 360 (original fans mounted in pull)- 3 fans Corsair 120 ML PRO in push.
MOBO Gygabyte Z390 Aorus Master- Corsair RGB Vengeance 64GB RAM (4x16) CL16
Nvidia Quadro RTX 4000
Samsung 970 EVO PLUS 1TB (unit C). Samsung 970 PRO 512GB (for data)
Power Supply: Corsair TX850M PLUS


Descubre mi programa VisorNET para Civil 3D:
https://apps.autodesk.com/CIV3D/es/Detail/Index?id=appstore.exchange.autodesk.com%3avisornet_windows32and64%3aes

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


 

Autodesk Design & Make Report