A given station gets the elevation values in the profile (C # for Civil3d)

Source: Internet
Author: User

The API provided by Civil3d, which is the method provided by the Profiles profile class---Public double elevationat, makes it easy to get the elevation value at a station of a profile object. The elevation values can then be obtained in batches. The code for implementation is given below.

First write an extension method for the Profiles profile class (the extension method is quite useful) to return the elevation value at a station.

1         /// <summary>2         ///gets the elevation value in the profile given the station value, April 21, 20183         ///if the given station is within the profile range, the corresponding elevation value is returned, otherwise null is returned4         /// </summary>5         /// <param name= "Profile" ></param>6         /// <param name= "station" ></param>7         /// <returns></returns>8          Public Static Double? Getelevationfromprofile ( ThisProfile profile,DoubleStation )9         {Ten             Double? elevation =NULL;//define a nullable type of data One             varStartstation =Profile . startingstation; A             varEndstation =Profile . endingstation; -             if(Station >= startstation && station <= endstation)//determine the station number within the longitudinal section of the station range -             { theelevation =Profile . Elevationat (station); -             } -  -             returnelevation; +}

You can then get the elevation data for the station by calling the method above.

1[Commandmethod ("Getelvfromprofile")]2          Public Static voidGetelvfromprofile ()3         {4Document doc =AcadApp.DocumentManager.MdiActiveDocument;5Database db =Doc. Database;6Editor ed =Doc. Editor;7Civildocument Civildoc =civilapplication.activedocument;8             varopt =NewPromptentityoptions ("\ n Please pick up a profile object");9Opt. Setrejectmessage ("\ n Object must be a profile object");TenOpt. Addallowedclass (typeof(profile),false); One             varres =ed. GetEntity (opt); A             if(Res. Status! =Promptstatus.ok) -             { -Ed. Writemessage ("you've canceled your choice."); the                 return; -             } -             varDoubleresult = ed. GetDouble ("\ n Please enter a station number"); -             DoubleStation =Doubleresult.value; -             using(Documentlock Doclock =Doc. LockDocument ()) +             using(Transaction trans =db. Transactionmanager.starttransaction ()) A             { atProfile profile = trans. GetObject (Res. ObjectId, Openmode.forread) asprofile;//getting profile objects -                 Double? elevation =Profile . Getelevationfromprofile (station);//Call the extension method to get the elevation value -                 //ed. Writemessage (profile. Getelevationfromprofile (station). ToString ()); -Ed. Writemessage (elevation?. ToString ()); -             }  -}

If you want to get an elevation in bulk, you can do it with a loop.

A given station gets the elevation values in the profile (C # for Civil3d)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.