Convert Civil 3D SurveyFigure to Polyline object

By Partha Sarkar

In some of the projects requirement, you may want to convert
the Civil 3D SurveyFigure objects to AutoCAD geometric object like polyline and
retain the curves, bulges etc. When you select a Civil 3D SurveyFigure object
and call the LIST command in Civil 3D, you would see each segment type and
associated details like the following screenshot.

Survey_Fig-01

 

From the Civil 3D SurveyFigure object we can access BaseCurve to get the base geometry which we can then append to Civil
3D Model space. Here is the relevant code snippet :

 

try
{
  SurveyFigure survFig = trans.GetObject(survFigId, OpenMode.ForWrite) as SurveyFigure;
 
  // get the projected curve from SurveyFigure  
  Curve baseCurve = survFig.BaseCurve;
 
  // Now append the curve to db
  BlockTable table = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
  BlockTableRecord model = trans.GetObject(table[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
 
  model.AppendEntity(baseCurve);
  trans.AddNewlyCreatedDBObject(baseCurve, true);
  // Remove the SurveyFigure
  survFig.Erase();
  trans.Commit();
}

 

 

And result of converting the SurveyFigure to Polyline object
:

 
Survey_Fig-02


Comments

13 responses to “Convert Civil 3D SurveyFigure to Polyline object”

  1. Great code Partha!
    As a side note, I don’t believe there is a need to call GetProjectedCurve() unless you want to project the baseCurve to a plane other than world.
    Also, if the survey figure has different elevations at each vertex the curve information will be represented as 3d line segments. In order for the curve data to come across in that situation, you would need to flatten the figure first.
    -Mark P.

  2. Thanks Mark ! You are right. GetProjectedCurve() is redundant here, unless someone want to project the baseCurve to a plane other than world. To retain the curves as it is we can simple get the BaseCurve and add that to DWG database using AddNewlyCreatedDBObject(). I have updated the original code snippet above to make it simpler.
    Cheers,
    Partha
    ADN

  3. Anton Huizinga Avatar
    Anton Huizinga

    You forgot to change the line:
    model.AppendEntity(projectedCurve);
    That should be the baseCurve.

  4. Thanks Anton ! Corrected now :)
    Cheers,
    Partha
    ADN

  5. jim haglund Avatar
    jim haglund

    Love what your code does. How can I load and use this code in Civil 3d drawings?
    Thanks
    Jim

  6. Hi Jim,
    You need to build a simple .NET plug-in app using this code and Civil 3D .NET API assembly. Then netload your application in Civil 3D and call your custom command. In the following link you will see useful resource like DevTV to build your plugin for Civil 3D or AutoCAD.
    http://usa.autodesk.com/adsk/servlet/index?id=1911627&siteID=123112
    http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=8007696
    Thanks,
    Partha

  7. Hi Partha –
    Silly question, but how does one go about converting SurveyFigure to Polyline2d to retain the ‘intelligent’ arcs, etc.?
    Do we need to ‘flatten’ the SurveyFigure first, to allow for BaseCurve to yield Polyline2d (with arcs, etc.)?
    Cheers

  8. Hi BlackBox –
    No need to flatten. We can get the base curve as shown in the above code sample –
    Curve baseCurve = survFig.BaseCurve;
    If you want Polyline2d, you can use the curve geometry to create a Polyline2d out of it.
    Thanks,
    Partha

  9. Hi.
    That code snippet is the same for Feature Lines to convert to polylines?
    Can I get Id of polyline after this:?
    ” trans.AddNewlyCreatedDBObject(baseCurve, true);”
    I would like to get a ObjectIdCollection of news polylines for erase later.
    Thank you.

  10. Partha,
    I have tried .basecurve, .GetProjectedCurve and .GetOrthoProjectedCurve to generate a 2d polyline, but each method will not generate a polyline with arc segments. They are the only approximated curves with line segments.
    The only way I can get a polyline with curves is to flatten the figure to a dummy surface first.
    Is there another method or is there a way to programatically flatten the figure to the same elevation?
    Thank you,
    Stacy

  11. Partha,
    You said that there is no need to flatten, but each method I have tried does not produce a polyline with curves.
    I tried:
    survfig.BaseCurve
    survfig.GetProjectedCurve
    survig.GetOrthoprojectedCurve
    If if manually flatten the figure using a dummy suface and the AeccFeatureElevsFromSurf command, the polyline derived from survfig.BaseCurve will then have actual arc segments.
    Is there another method or a way to flatten the figure programatically first?
    Thank you,
    Stacy

  12. Partha,
    You said that there is no need to flatten, but each method I have tried does not produce a polyline with curves.
    I tried:
    survfig.BaseCurve
    survfig.GetProjectedCurve
    survig.GetOrthoprojectedCurve
    If if manually flatten the figure using a dummy suface and the AeccFeatureElevsFromSurf command, the polyline derived from survfig.BaseCurve will then have actual arc segments.
    Is there another method or a way to flatten the figure programatically first?
    Thank you,
    Stacy

  13. Hi Stacy,
    I don’t see any API to flatten the SurveyFigure.
    You can try projecting the BaseCurve from SurveyFigure to a specific plane using the following –
    Curve projectedCurve = survFig.BaseCurve.GetProjectedCurve(plane, dir);
    Thanks,
    Partha
    ADN

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading