AutoCAD Civil 3D Customization

Reply
*Expert Elite*
Jeff_M
Posts: 3,967
Registered: ‎07-22-2003
Message 1 of 7 (565 Views)
Accepted Solution

Example C# code to temporarily show High/Low points of a featureline

565 Views, 6 Replies
12-22-2011 02:09 PM

As I mentioned on the main C3D Forum, here is the source code and an attached Zip file with a compiled .NET dll.

 

// Example to display the High and Low points of a Featureline or 3DPolyline using temporary
// markers which are removed upon command completion.
// Jeff Mishler, permission to use this code for personal or corporate use is hereby granted.
// No commercial use is authorized.
// Copyright 2011

using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Civil.Land.DatabaseServices;
using aGi = Autodesk.AutoCAD.GraphicsInterface;

namespace FeatureHighLowExample
{
    public class FeatureHighLow
    {
        private static DBObjectCollection m_mrkers = new DBObjectCollection();
        private static IntegerCollection intColl = new IntegerCollection();

        [CommandMethod("FeatureHighLow")]
        public void featurehighlowcommand()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            Database db = Application.DocumentManager.MdiActiveDocument.Database;
            PromptEntityOptions entOpts = new PromptEntityOptions("\nSelect Featureline line or 3DPolyline: ");
            entOpts.SetRejectMessage("\n...not an allowed object type, try again.");
            entOpts.AddAllowedClass(typeof(FeatureLine), true);
            entOpts.AddAllowedClass(typeof(Polyline3d), true);
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                PromptEntityResult res = ed.GetEntity(entOpts);
                while (res.Status == PromptStatus.OK)
                {
                    Curve crv = (Curve)tr.GetObject(res.ObjectId, OpenMode.ForRead);
                    Point3d low = new Point3d(0,0,999999);
                    Point3d high = new Point3d(0,0,-999999);
                    for (int i = (int)crv.StartParam; i <= (int)crv.EndParam; i++)
                    {
                        Point3d tmp = crv.GetPointAtParameter((double)i);
                        if (tmp.Z < low.Z)
                            low = tmp;
                        if (tmp.Z > high.Z)
                            high = tmp;
                    }
                    if (Math.Abs(low.Z - high.Z) < 0.001) //the object is level
                    {
                        ed.WriteMessage("\n Object is level!");
                    }
                    else
                    {
                        showHighpoint(high);
                        showLowpoint(low);
                    }
                    res = ed.GetEntity(entOpts);
                }
                removeMarkers();
                tr.Commit();
            }
        }

        private void showCircle(Point3d pt, int color)
        {
            //code to temporarily display a circle of the specified color. Uses a simple color index, 1-255.
            Vector3d v3d = new Vector3d(0, 0, 1); //this is the Normal of the object. May want to include code for use in UCS other than World
            double size = 10;//this is the radius of the circle. Adjust as desired, or, better yet, make this a ratio of the current screen size.
            Circle circle = new Circle(pt, v3d, size);
            m_mrkers.Add(circle);
            circle.ColorIndex = color;
            aGi.TransientManager.CurrentTransientManager.AddTransient(circle, aGi.TransientDrawingMode.DirectShortTerm, 128, intColl);
        }

        private void showHighpoint(Point3d pt)
        {
            showCircle(pt, 2); //add a yellow circle
        }


        private void showLowpoint(Point3d pt)
        {
            showCircle(pt, 3); //add a green circle
        }

        private void removeMarkers()
        {
            //remove them all when we are done....don't want screen clutter!
            for (int i = 0; i < m_mrkers.Count; i++)
            {
                aGi.TransientManager.CurrentTransientManager.EraseTransient(m_mrkers[i], intColl);
                m_mrkers[i].Dispose();
            }
            m_mrkers.Clear();
        }
    }
}

 

Jeff_M, also a frequent Swamper
*Expert Elite*
neilyj
Posts: 3,479
Registered: ‎08-01-2008
Message 2 of 7 (554 Views)

Re: Example C# code to temporarily show High/Low points of a featureline

12-23-2011 12:31 AM in reply to: Jeff_M

Excellent code Jeff - very useful - but I wonder if it could be extended to put the high/lowpoints on a new layer and leave them on the drawing for reference?? I have no idea haow to program in C#.....!!!!!!

 

Thanks

neilyj
(No connection with Autodesk other than using the products in the real world)


IDSP Premium 2014 (mainly Civil 3D 2014 UKIE SP1 & Infraworks with some limited 3ds Max Design)
Win 7 Pro x64, 256Gb SSD, 300Gb 15,000 rpm HDD
16Gb Ram Intel Xeon CPU E5-1607 0 @ 3.00GHz (4 CPUs), ~3.0GHz
NVIDIA Quadro 4000, Dual 27" Monitor, Dell T3600
*Expert Elite*
Jeff_M
Posts: 3,967
Registered: ‎07-22-2003
Message 3 of 7 (550 Views)

Re: Example C# code to temporarily show High/Low points of a featureline

12-23-2011 07:14 AM in reply to: neilyj

Thanks, Neil. Sure the code could be amended as you describe, and it could also have these settings saved with different options, but that's something I don't have time to do right now. Perhaps someone else would like to take this on, otherwise I will do what I can when I get a chance.

 

In the mean time, attached is some slightly altered code, source and compiled dll, that leaves the markers after the command ends. They will remain on until either the new command CLEARHIGHLOWMARKERS is run, or the drawing is closed. 

Jeff_M, also a frequent Swamper
*Expert Elite*
neilyj
Posts: 3,479
Registered: ‎08-01-2008
Message 4 of 7 (546 Views)

Re: Example C# code to temporarily show High/Low points of a featureline

12-23-2011 09:29 AM in reply to: Jeff_M

Thanks for the updated code - I'll not get a chance to play with it until after the holidays......... 

neilyj
(No connection with Autodesk other than using the products in the real world)


IDSP Premium 2014 (mainly Civil 3D 2014 UKIE SP1 & Infraworks with some limited 3ds Max Design)
Win 7 Pro x64, 256Gb SSD, 300Gb 15,000 rpm HDD
16Gb Ram Intel Xeon CPU E5-1607 0 @ 3.00GHz (4 CPUs), ~3.0GHz
NVIDIA Quadro 4000, Dual 27" Monitor, Dell T3600
*Expert Elite*
Jeff_M
Posts: 3,967
Registered: ‎07-22-2003
Message 5 of 7 (537 Views)

Re: Example C# code to temporarily show High/Low points of a featureline

12-23-2011 10:58 AM in reply to: neilyj

I was just given the rest of the day off (it's only 11 a.m. Friday here). So looks like I will have a bit of time to play some more with this.

 

 

Jeff_M, also a frequent Swamper
*Expert Elite*
Jeff_M
Posts: 3,967
Registered: ‎07-22-2003
Message 6 of 7 (528 Views)

Re: Example C# code to temporarily show High/Low points of a featureline

12-24-2011 10:42 AM in reply to: neilyj

Attached is a zip file containing a new .NET DLL and the complete Visual Studio 2008 C# Project. This version has a Settings form, accessible any time at the Select object prompt is displayed. The settings are saved in a simple Text file in the ProgramData\C3DUtilities folder. I have limited the color options for the Temporary markers to colors 1-15, and the size of all markers may be 1-25 units. The command remains "FeatureHighLow" and the "ClearMarkers" command is still there to remove any Temp markers added using the Session option.

 

The VS Project was built against C3D2010 but runs in 2010-2012. If loading the project on a system without C3D2010 installed the references for the Acad, Aec, and AcDb dll's will need to be updated.

 

I doubt I will be making any updates to this code, although others may freely do so as long as it isn't included in any ForSale product. I hope at least 1 or 2 people find it useful to use and/or to see how one can implement custom commands using .NET & C# (although, since I'm far from a professional programmer, this may not be a shining example of good coding practice, but it works for me :smileywink: )

 

Enjoy & Merry Christmas!

Jeff_M, also a frequent Swamper
*Expert Elite*
neilyj
Posts: 3,479
Registered: ‎08-01-2008
Message 7 of 7 (425 Views)

Re: Example C# code to temporarily show High/Low points of a featureline

01-30-2012 03:01 AM in reply to: Jeff_M

Hats off to Jeff again - perfect tool..... can only give one kudos though

neilyj
(No connection with Autodesk other than using the products in the real world)


IDSP Premium 2014 (mainly Civil 3D 2014 UKIE SP1 & Infraworks with some limited 3ds Max Design)
Win 7 Pro x64, 256Gb SSD, 300Gb 15,000 rpm HDD
16Gb Ram Intel Xeon CPU E5-1607 0 @ 3.00GHz (4 CPUs), ~3.0GHz
NVIDIA Quadro 4000, Dual 27" Monitor, Dell T3600

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Civil 3D Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for AutoCAD Civil 3D helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Civil 3D

Twitter

Facebook

Blogs