add user contours and extract polylines 2012

add user contours and extract polylines 2012

wang890
Collaborator Collaborator
861 Views
3 Replies
Message 1 of 4

add user contours and extract polylines 2012

wang890
Collaborator
Collaborator

i know 2013 are more exposed and the .net can extract contours.

 

however using 2012 at the moment. so my plan is using .net to add the user contours and then use com object to extract.

 

so far i can get the surface object and asign to two differnt surface variable one is .net and one is com.

 

i am looking at the surfaceanalysis object and can't figure out how to add contours at user elevation. it is also read only in the surface object. but i find this:

 

SetContourData

(analysisData()

 

which is obvious not read only.

 

so anybody have a sample code of the procedure of assign user contours?

 

thank you.

Stantec
Dell Precision 5530, Prism M320PU, C3D 14/17/19
0 Likes
862 Views
3 Replies
Replies (3)
Message 2 of 4

Jeff_M
Consultant
Consultant

For each UserDefinedContour you need to create a SurfaceAnalysisUserDefinedContourData() and add it to an array of SurfaceAnalysisUserDefinedContourData[] This array is passed to the SetUserDefinedContourData method of the SurfaceAnalysis.

 

When you create a new instance of SurfaceAnalysisUserDefinedContourData(), it uses the dtatbase defaults, then you can set the Elevation desired for that UDC.

Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 3 of 4

wang890
Collaborator
Collaborator

hi jeff

 

can you like put that in a "sentence" : )

 

can't figure out still.

Stantec
Dell Precision 5530, Prism M320PU, C3D 14/17/19
0 Likes
Message 4 of 4

Jeff_M
Consultant
Consultant

Here ya go, Bob.

using System.Collections.Generic;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Civil.Land.DatabaseServices;
using CivDb = Autodesk.Civil.Land.DatabaseServices;

namespace C3D_Surface_Test
{
    public class SurfaceTest
    {
        [CommandMethod("TestUserContours")]
        public void testusercontours()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptEntityOptions pmptEnt = new PromptEntityOptions("\nSelect entity:");
            pmptEnt.SetRejectMessage("Not a Surface, try again!");
            pmptEnt.AddAllowedClass(typeof(CivDb.Surface), false);
            PromptEntityResult entRes = ed.GetEntity(pmptEnt);
            if (entRes.Status != PromptStatus.OK)
                return;
            using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
            {
                LinetypeTable ltt = (LinetypeTable)db.LinetypeTableId.GetObject(OpenMode.ForRead);
                ObjectId ltId = ltt["HIDDEN"];
                LineWeight lw = LineWeight.LineWeight015;
                Color color = new Color();
                color = Color.FromColorIndex(ColorMethod.ByColor, 1);
                CivDb.Surface surf = (CivDb.Surface)entRes.ObjectId.GetObject(OpenMode.ForWrite);
                double[] elevs = { 2.2, 3.7, 4.5 };
                List<double> contourelevations = new List<double>(elevs);
                List<SurfaceAnalysisUserDefinedContourData> data = new List<SurfaceAnalysisUserDefinedContourData>();
                foreach (double elev in contourelevations)
                {
                    SurfaceAnalysisUserDefinedContourData ucd = new SurfaceAnalysisUserDefinedContourData();//elev,, color, ltId, lw); //using the full constructor fails with the ltId...
                    ucd.Elevation = elev;
                    ucd.Color = color;
                    ucd.LineTypeId = ltId;
                    ucd.LineWeight = lw;
                    data.Add(ucd);
                }
                surf.Analysis.SetUserDefinedContourData(data.ToArray());
                tr.Commit();
            }
        }
    }
}

 

Jeff_M, also a frequent Swamper
EESignature
0 Likes