<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Trying to add slope properties to the given code using .NET API in Civil 3D Customization Forum</title>
    <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/trying-to-add-slope-properties-to-the-given-code-using-net-api/m-p/13202789#M871</link>
    <description>&lt;P&gt;Thank you! it worked out for me&lt;/P&gt;</description>
    <pubDate>Tue, 10 Dec 2024 08:24:35 GMT</pubDate>
    <dc:creator>iqbalzain099</dc:creator>
    <dc:date>2024-12-10T08:24:35Z</dc:date>
    <item>
      <title>Trying to add slope properties to the given code using .NET API</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/trying-to-add-slope-properties-to-the-given-code-using-net-api/m-p/13200583#M869</link>
      <description>&lt;P&gt;I am trying to change the following settings using .NET API:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Analysis Type&lt;/STRONG&gt;:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Change from "Elevations" to "Slopes".&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Ranges&lt;/STRONG&gt;:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Set the "range" to 5&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Maximum and Minimum Slope:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Set Propeties as shown below&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="iqbalzain099_0-1733720885481.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1443643i5759310F3190CF7F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="iqbalzain099_0-1733720885481.png" alt="iqbalzain099_0-1733720885481.png" /&gt;&lt;/span&gt;&lt;P&gt;&lt;STRONG&gt;4. Code:&lt;/STRONG&gt;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices;
using Autodesk.Civil.DatabaseServices.Styles;
using System;

namespace CIVIL3D
{
    public class Class1 : IExtensionApplication
    {
        public void Initialize()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            ed.WriteMessage("\nHello,Plugin loaded.");
        }

        public void Terminate()
        {
            // Cleanup code if needed
        }

        [CommandMethod("CreateSurfaceDirect")]
        public void CreateSurfaceDirect()
        {
            // Get the active document and editor
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;

            try
            {
                // Start a transaction
                using (Transaction trans = db.TransactionManager.StartTransaction())
                {
                    // Get the Civil 3D document
                    CivilDocument civilDoc = CivilDocument.GetCivilDocument(db);

                    // Prompt the user to enter the surface name
                    PromptStringOptions surfaceNamePrompt = new PromptStringOptions("\nEnter the name of the surface: ");
                    surfaceNamePrompt.AllowSpaces = true;
                    PromptResult nameResult = ed.GetString(surfaceNamePrompt);

                    if (nameResult.Status != PromptStatus.OK)
                    {
                        ed.WriteMessage("\nInvalid input. Surface creation aborted.");
                        return;
                    }

                    string surfaceName = nameResult.StringResult;

                    // Get the slope surface style
                    ObjectId styleId = GetSlopeSurfaceStyle(civilDoc);
                    if (styleId == ObjectId.Null)
                    {
                        ed.WriteMessage("\nCould not find a suitable slope surface style.");
                        return;
                    }

                    // Create the surface using the slope style
                    ObjectId surfaceId = TinSurface.Create(surfaceName, styleId);

                    // Open the surface for modification if needed
                    TinSurface surface = surfaceId.GetObject(OpenMode.ForWrite) as TinSurface;
                    if (surface != null)
                    {
                        surface.Description = "Surface with slope visibility enabled";
                        ed.WriteMessage($"\nSurface '{surfaceName}' created successfully.");
                    }

                    // Commit the transaction
                    trans.Commit();
                }
            }
            catch (System.Exception ex)
            {
                ed.WriteMessage($"\nError: {ex.Message}");
            }
        }

        private ObjectId GetSlopeSurfaceStyle(CivilDocument civilDoc)
        {
            SurfaceAnalysis surfaceAnalysis = surface.Analysis;


            foreach (ObjectId styleId in civilDoc.Styles.SurfaceStyles)
            {
                SurfaceStyle style = styleId.GetObject(OpenMode.ForRead) as SurfaceStyle;
                if (style != null &amp;amp;&amp;amp; style.Name.Contains("Slope"))
                {
                    return style.ObjectId;
                }
            }

            return ObjectId.Null;
        }



        [CommandMethod("MyFirstCommand")]
        public void MyFirstCommand()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            ed.WriteMessage("\nThis is my first Civil 3D command!");

        }



    }
}​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The purpose of the code is to create a surface with a predefined slope visibility and adding contours to the surface automatically for a faster slope analysis,&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Mon, 09 Dec 2024 05:17:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/trying-to-add-slope-properties-to-the-given-code-using-net-api/m-p/13200583#M869</guid>
      <dc:creator>iqbalzain099</dc:creator>
      <dc:date>2024-12-09T05:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to add slope properties to the given code using .NET API</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/trying-to-add-slope-properties-to-the-given-code-using-net-api/m-p/13201814#M870</link>
      <description>&lt;P&gt;Have a look at &lt;A href="https://forums.autodesk.com/t5/civil-3d-customization/surface-properties-net-api/m-p/12835666#M25709" target="_blank" rel="noopener"&gt;THIS&lt;/A&gt; thread and see if it helps.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 18:22:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/trying-to-add-slope-properties-to-the-given-code-using-net-api/m-p/13201814#M870</guid>
      <dc:creator>Jeff_M</dc:creator>
      <dc:date>2024-12-09T18:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to add slope properties to the given code using .NET API</title>
      <link>https://forums.autodesk.com/t5/civil-3d-customization-forum/trying-to-add-slope-properties-to-the-given-code-using-net-api/m-p/13202789#M871</link>
      <description>&lt;P&gt;Thank you! it worked out for me&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2024 08:24:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/civil-3d-customization-forum/trying-to-add-slope-properties-to-the-given-code-using-net-api/m-p/13202789#M871</guid>
      <dc:creator>iqbalzain099</dc:creator>
      <dc:date>2024-12-10T08:24:35Z</dc:date>
    </item>
  </channel>
</rss>

