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(); } } }
Solved! Go to Solution.
Solved by Jeff_M. Go to Solution.
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)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
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.
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)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
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 )
Enjoy & Merry Christmas!
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)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
So, how does this code line up with later versions of C3D. I have C3D 2019, and i've been having trouble NETLOADing into C3D.
The error is below
"Assembly file name: C:\Users\Robo\Favorites\Useful Info\CAD EXE's\FeaturelineTools\FeaturelineTools.dll
Cannot load assembly. Error details: System.IO.FileLoadException: Could not load file or assembly 'file:///C:\Users\Robo\Favorites\Useful Info\CAD EXE's\FeaturelineTools\FeaturelineTools.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
File name: 'file:///C:\Users\Robo\Favorites\Useful Info\CAD EXE's\FeaturelineTools\FeaturelineTools.dll' ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Autodesk.AutoCAD.Runtime.ExtensionLoader.Load(String fileName)
at loadmgd()"
@Jeff_M - this is working great for me.
I'd like to add this as a new command to my right click shortcut menu - I know how to add to the right click menu but not sure what to add in the macro box to create the new command - can you advise please?
neilyj (No connection with Autodesk other than using the products in the real world)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Thank you so much, Jeff. This was extremely useful. It works just fine. By the way, could you point me in the direction of resources for AutoCAD programming. It would be useful to have the know how to do what you do.
@neilyj666 this should work:
^C^Cnetload "C:/PATHTOTHEFILE/FeaturelineTools.dll" FeatureHighLow
@ookumo you're welcome.
First, I bought the book "C# for Dummies".
For general learning I used Google a lot and found sites that helped with learning c# such as https://stackoverflow.com and https://www.codeproject.com.
For AutoCAD/Civil3D I used the Autodesk forums .NET & Civil 3D Customization as well as TheSwamp.org
@Jeff_M Many thanks - I'll try it in the few minutes...:)
EDIT: works with no problem...😁
neilyj (No connection with Autodesk other than using the products in the real world)
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.