Change the style of a surface using the Civil 3D API

Source: Internet
Author: User

If you need to change the style of the surface, such as changing the color of the contour, and so on, in civil 3D, you can change by selecting the surface in Toolspace, then right-clicking on "Edit surface style ..." and switching to "Display" tab:

The following code uses the API to achieve the same effect:

[Commandmethod("MyGroup","Surfacestyleexample",
"Surfacestyleexample",Commandflags. Modal)]
PublicvoidMyCommand ()//This method can has any name
{

DocumentDoc =Application. Documentmanager.mdiactivedocument;

if(Doc! =NULL)
{
Editored =Application. Documentmanager
. Mdiactivedocument.editor;



//Select a tin surface

promptentityoptionsPEO =Newpromptentityoptions(
"\nselect a tin Surface:");
Peo. Setrejectmessage ("\nonly Tin surface is accepted");
Peo. Addallowedclass (typeof(Tinsurface),true);
Promptentityresultper = ed. GetEntity (PEO);
if(per. Status! =Promptstatus. OK)return;

civildocumentCivildoc =civilapplication. ActiveDocument;

using(Transactiontrans = doc. TransactionManager
. StartTransaction ())
{
TinsurfaceSurface = trans. GetObject (per. ObjectId,
OpenMode. Forread) asTinsurface;

//exclude Invalid points, bonus function, exception points excluded

Surface. Buildoptions.execludemaximumelevation =true;
Surface. Buildoptions.maximumelevation = 5000;
Surface. Buildoptions.execludeminimumelevation =true;
Surface. Buildoptions.minimumelevation = 200;

//set the Maximum Triangle length, set the maximum edge length of the triangle

Surface. Buildoptions.maximumtrianglelength = 200;

//change the style, it's starting to change styles
ObjectIdStyleId;
if(CivilDoc.Styles.SurfaceStyles.Contains ("Standard"))
{
StyleId = civildoc.styles.surfacestyles["Standard"];
}
Else
{
//Create a new style called ' Example style ':
StyleId = CivilDoc.Styles.SurfaceStyles
. ADD ("Example Style");

}



//Modify the style

SurfacestyleSurfacestyle = Styleid.getobject (
OpenMode. Forwrite) asSurfacestyle;

//countours Smoothing

SurfaceStyle.ContourStyle.SmoothContours =true;
SurfaceStyle.ContourStyle.SmoothingType
=Contoursmoothingtype. Addvertices;
SurfaceStyle.ContourStyle.SmoothingFactor = 10;

SurfaceStyle.ContourStyle.MajorContourColorScheme
=Colorschemetype. Rainbow;

//major Contour, Red

Surfacestyle.getdisplaystyleplan (
Surfacedisplaystyletype. Majorcontour). Color
= Autodesk.AutoCAD.Colors.Color. Fromrgb (255, 0, 0);

//major Contour, layer 0

Surfacestyle.getdisplaystyleplan (
Surfacedisplaystyletype. Majorcontour). Layer ="0";

//mainor Contour, Gree

Surfacestyle.getdisplaystyleplan (
Surfacedisplaystyletype. Minorcontour). Color
= Autodesk.AutoCAD.Colors.Color. Fromrgb (0, 255, 0);

//mainor Contour, layer 0, if you want to put on another layer, make sure that the layer exists

Surfacestyle.getdisplaystyleplan (
Surfacedisplaystyletype. Majorcontour). Layer ="0";

//Display major contours:

Surfacestyle.getdisplaystyleplan (Surfacedisplaystyletype
. Majorcontour). Visible =true;
Surfacestyle.getdisplaystyleplan (Surfacedisplaystyletype
. Minorcontour). Visible =true;

//Turn off display of other items:

Surfacestyle.getdisplaystyleplan (Surfacedisplaystyletype
. usercontours). Visible =false;
Surfacestyle.getdisplaystyleplan (Surfacedisplaystyletype
. Directions). Visible =false;
Surfacestyle.getdisplaystyleplan (Surfacedisplaystyletype
. elevations). Visible =false;
Surfacestyle.getdisplaystyleplan (Surfacedisplaystyletype
. Slopes). Visible =false;
Surfacestyle.getdisplaystyleplan (Surfacedisplaystyletype
. Slopearrows). Visible =false;
Surfacestyle.getdisplaystyleplan (Surfacedisplaystyletype
. watersheds). Visible =false;

//todo:do the same for all model display settings as well
//


//Assign the style to the first surface in the document:

Surface. StyleId = StyleId;

//Commit the transaction

Trans.commit ();

//rebuild the surface
Surface. Rebuild ();
}

}



}

Before you change the image:

After running, the contour color has changed.

Hope this helps.

Change the style of a surface using the Civil 3D API

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.