Get elevation value in profile given station (c# for civil3d)

Through the api provided by civil3d, that is, the method provided by the profile profile class---public double ElevationAt(double station), you can easily obtain the elevation value at a certain station of the profile object, and then you can obtain the elevation value in batches. The implemented code is given below.

First write an extension method of the profile Profile class (the extension method is quite useful), which is used to return the elevation value at a station.

1          ///  <summary> 
2          /// Get the elevation value in the profile given the chainage value, April 21, 2018
 3          /// If the given chainage is within the range of the profile, return the corresponding Elevation value, otherwise return null
 4          ///  </summary> 
5          ///  <param name="profile"></param> 
6          ///  <param name="station"></param> 
7          ///  <returns></returns> 
8          public  static  double ? GetElevationFromProfile( this Profile profile, double station)
 9          {
 10              double ? elevation = null ;
//Define a nullable type of data 11              varstartStation = profile.StartingStation;
 12              var endStation = profile.EndingStation;
 13              if (station >= startStation && station <= endStation) // Judging that the station is within the range of the longitudinal station 
14              {
 15                  elevation = profile.ElevationAt(station );
 16              }
 17  
18              return elevation;
 19          }

 

Then you can get the elevation data corresponding to the stake by calling the above method.

1         [CommandMethod( " getElvFromProfile " )]
 2          public  static  void GetElvFromProfile()
 3          {
 4              Document doc = AcadApp.DocumentManager.MdiActiveDocument;
 5              Database db = doc.Database;
 6              Editor ed = doc.Editor;
 7              CivilDocument civilDoc = CivilApplication. ActiveDocument;
 8              var opt = new PromptEntityOptions( " \n Please pick a profile object " );
 9             opt.SetRejectMessage( " \n The object must be a profile object " );
 10              opt.AddAllowedClass( typeof (Profile), false );
 11              var res = ed.GetEntity(opt);
 12              if (res.Status != PromptStatus. OK)
 13              {
 14                  ed.WriteMessage( " \nYou have canceled the selection " );
 15                  return ;
 16              }
 17              var doubleResult = ed.GetDouble( " \nPlease enter a stake " );
 18             double station = doubleResult.Value;
20             using (DocumentLock docLock = doc.LockDocument())
21             using (Transaction trans = db.TransactionManager.StartTransaction())
22             {
23                 Profile profile = trans.GetObject(res.ObjectId, OpenMode.ForRead) as Profile;//获取纵断面对象
24                 double? elevation = profile.GetElevationFromProfile(station);//调用扩展方法,获取高程值
25                 //ed.WriteMessage(profile.GetElevationFromProfile(station).ToString());
26                 ed.WriteMessage(elevation?.ToString());
27             } 
28         }

If you want to get the elevation values ​​in batches, you can do it with the help of a loop.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324991081&siteId=291194637