lISP to edit survey figure style.

lISP to edit survey figure style.

cody.faltin
Advocate Advocate
1,336 Views
11 Replies
Message 1 of 12

lISP to edit survey figure style.

cody.faltin
Advocate
Advocate

I am hoping someone can provide me with assistance in developing a lisp or lisps that would edit survey figure styles.

 

What I am hoping to accomplish is to select one or more survey figures, and with a single command toggle their status between Flatten to 2D, at 0 elevation, and true 3 dimensional presentation.

 

I am not finding documentation on how to access the survey figure style through a lisp routine though.

 

I am not certain that this is even possible with lisp, I have found some documentation that leads me to believe that the portions of the api that reference survey figure styles have not been exposed to lisp, but I'm more a tinkerer with code than and experienced programmer, so I am not sure I am reading the documentation correctly.

 

I would also be willing to take a stab at it with C#, but my skills there are even more limited.

 

Thank you,

0 Likes
Accepted solutions (3)
1,337 Views
11 Replies
Replies (11)
Message 2 of 12

hosneyalaa
Advisor
Advisor

hi

Have you picture explain your idea

Or

Attached example drawing

 

Any way you need civil API com

0 Likes
Message 3 of 12

cody.faltin
Advocate
Advocate

Hosneyalaa,

 

Essentially I would like to be able to switch the styles between these two states with quick command.

STATE 1.JPG

STATE 2.JPG

The inspiration for this was a lisp routine I found which will toggle on the display of triangles in a civil 3D surface.  Which is the toggle triangles lisp I have attached.  Using that as a template I am able to get to the point where I can use the code below to select as survey figure, then have it perform an action to change the style.  At this point I am struggling with defining the action.

 

(vl-load-com)

(defun c:SF2D () (c:SurveyFigure2D))
(defun c:SurveyFigure2D (/ *error* acDoc obj)

(defun *error* (msg)
(if ss
(vla-delete ss)
)
(if acDoc
(vla-endundomark acDoc)
)
(cond ((not msg)) ; Normal exit
((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit)
((princ (strcat "\n** Error: " msg " ** "))) ; Fatal error, display it
)
(princ)
)

(if (ssget '((0 . "AECC_SVFIGURE*")))
(
; need code to change survey figure style from 3D to 2D here.
)

; Original surface style change is commented out below.
;(progn
; (vla-startundomark
; (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
; )
; (vlax-for x (setq ss (vla-get-activeselectionset acDoc))
; (vlax-put
; (setq obj
; (vlax-get (vlax-get (vlax-get x 'style) 'trianglestyle)
; 'displaystyleplan
; )
; )
; 'visible
; (1- (abs (vlax-get obj 'visible)))
; )
; )
;)
)

(*error* nil)
)

 

Thank you again.

0 Likes
Message 4 of 12

hosneyalaa
Advisor
Advisor

 

 Hi

 

As far as I know Style cannot be affected through Lisp It must be through .net

 

May i make a try through Lisp

 

https://help.autodesk.com/view/CIV3D/2022/ENU/?guid=780a165a-d1e7-0c12-10e7-44803e78e973

 

Screenshot_٢٠٢٣_٠٤٢٠_٢٢٤٤٣١.jpg

0 Likes
Message 5 of 12

cody.faltin
Advocate
Advocate

I had very much suspected that it may not be accessible through lisp.  Looks like I am going to have to dive into C# to accomplish this.  The reference you posted looks like it has a lot of the information I was missing.

 

Thank you,

 

I'm going to keep this open for a little bit, just in case anyone else has any good input, but thank you very very much.  Now I just have to learn more about C#.

0 Likes
Message 6 of 12

rl_jackson
Mentor
Mentor

My workflow has a process where I import 3D figures into a drawing for surface creation. Then I have another drawing that has the figures for 2D plan data. Here I generally convert the figures to 2d polylines to minimize file size, and the surface drawing is data referenced into the 2D file.


Rick Jackson
Survey CAD Technician VI

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.

EESignature

0 Likes
Message 7 of 12

hosneyalaa
Advisor
Advisor
Accepted solution

@cody.faltin 

After you get an idea  About C Sharp & CIVIL 3D API
CAN be used  this  CODE With some changes

 

///  https://forums.autodesk.com/t5/civil-3d-customization/how-to-change-style-of-parcel/m-p/10233647

 var doc = Application.DocumentManager.CurrentDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var civdoc = CivilApplication.ActiveDocument;
            var styleId = civdoc.Styles.ParcelStyles["Lot"];
            var entOpts = new PromptEntityOptions("\nSelect Parcel");
            entOpts.SetRejectMessage("...not a parcel, try again!");
            entOpts.AddAllowedClass(typeof(Parcel), true);
            var sel = ed.GetEntity(entOpts);
            if (sel.Status != PromptStatus.OK)
                return;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                var parcel = (Parcel)tr.GetObject(sel.ObjectId, OpenMode.ForWrite);
                var style = (ParcelStyle)tr.GetObject(styleId, OpenMode.ForRead);
                dynamic oParcel = parcel.AcadObject;
                oParcel.Style = style.AcadObject;
                tr.Commit();
            }

 

0 Likes
Message 8 of 12

cody.faltin
Advocate
Advocate

Thank you so much, between this and a few other tutorials I have followed I feel like I may be able to pull this together.  Once I have I will post the finished code.

0 Likes
Message 9 of 12

cody.faltin
Advocate
Advocate
Accepted solution

After a fair amount of trial and error and a great deal of searching I was able to put together the following.

At the moment the two methods only apply to the hard coded style of "Test", but I feel confident I can rework it to allow it to function based on a selection.  You will note that several lines are commented as not being necessary, I have left them in place for now as I feel I may be able to use them as a basis for defining the styleID variable based on user selection.  But based on my current understanding they are not actually passing any data to the database.

 

 

One thing I have not been able to determine would be how to specify the elevation that figure styles are flattened to. I have located the following reference, but I am unsure of how to implement the get set functionality.

https://help.autodesk.com/view/CIV3D/2022/ENU/?guid=f321bd87-e521-1e82-6471-326b9ed5a896 

 

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices.Styles;
using Autodesk.Civil.DatabaseServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.ApplicationServices;

namespace CDF.SFStyles
{
    public class Commands
    {
        [CommandMethod("SF2D")]
     
        public void SurveyFigure2D()
        {
            
            var doc = Application.DocumentManager.CurrentDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var civdoc = CivilApplication.ActiveDocument;
            var styleId = civdoc.Styles.SurveyFigureStyles["Test"];
            var entOpts = new PromptEntityOptions("\nSelect SurveyFigure");//These lines are not actually necessary.
            entOpts.SetRejectMessage("...not a survey figure, try again!");//These lines are not actually necessary.
            entOpts.AddAllowedClass(typeof(SurveyFigure), true);           //These lines are not actually necessary.
            var sel = ed.GetEntity(entOpts);                               //These lines are not actually necessary.
            if (sel.Status != PromptStatus.OK)                             //These lines are not actually necessary.
                return;                                                    //These lines are not actually necessary.
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {                
                var style = (SurveyFigureStyle)tr.GetObject(styleId, OpenMode.ForWrite);
                style.NetworkDisplayMode = SurveyElevationDisplayType.FlattenElevation;
                tr.Commit();
            }

        }

        [CommandMethod("SF3D")]

        public void SurveyFigure3D()
        {

            var doc = Application.DocumentManager.CurrentDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var civdoc = CivilApplication.ActiveDocument;
            var styleId = civdoc.Styles.SurveyFigureStyles["Test"];
            var entOpts = new PromptEntityOptions("\nSelect SurveyFigure");//These lines are not actually necessary.
            entOpts.SetRejectMessage("...not a survey figure, try again!");//These lines are not actually necessary.
            entOpts.AddAllowedClass(typeof(SurveyFigure), true);           //These lines are not actually necessary.
            var sel = ed.GetEntity(entOpts);                               //These lines are not actually necessary.
            if (sel.Status != PromptStatus.OK)                             //These lines are not actually necessary.
                return;                                                    //These lines are not actually necessary.
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {               
                var style = (SurveyFigureStyle)tr.GetObject(styleId, OpenMode.ForWrite);
                style.NetworkDisplayMode = SurveyElevationDisplayType.UseElevation;
                tr.Commit();
            }

        }


    }

    
}

 

This post provided me with the breakthrough for assigning the Elevation display type.

https://forums.autodesk.com/t5/civil-3d-customization/create-survey-figure-style-c/td-p/4882108

 

 

Thank you everyone for your assistance.

 

Message 10 of 12

Jeff_M
Consultant
Consultant
Accepted solution

To flatten to 0 it should just be:

style.NetworkDisplayMode = SurveyElevationDisplayType.UseElevation;
style.FlattenToElevationBy = 0.0;
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 11 of 12

cody.faltin
Advocate
Advocate
Jeff_M, thank you that was exactly what it needed.
0 Likes
Message 12 of 12

cody.faltin
Advocate
Advocate

Functional code with a few refinements.  Now loops through a selection set.  Added another method to flatten to a specified elevation.  Also added a regenall to the end of all the methods.

 

Thank you very much Hosneyalaa, and Jeff_M

 

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices.Styles;
using Autodesk.Civil.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;

namespace CDF.SFStyles
{
    public class Commands
    {


        [CommandMethod("SF2D")]

        public void SurveyFigure2D()
        {

            var doc = Application.DocumentManager.CurrentDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var civdoc = CivilApplication.ActiveDocument;                                             
            
            PromptSelectionResult result = SelectFigures();
            if (result.Status == PromptStatus.OK)
            {

                
                
                foreach (var objectId in result.Value.GetObjectIds())
                {
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        SurveyFigure figure = (SurveyFigure)tr.GetObject(objectId, OpenMode.ForRead);
                        SurveyFigureStyle figureStyle = (SurveyFigureStyle)tr.GetObject(figure.StyleId, OpenMode.ForRead);
                        dynamic oFigureStyle = figureStyle.AcadObject;
                        var figureStyleName = oFigureStyle.Name;
                        var styleId = civdoc.Styles.SurveyFigureStyles[$"{figureStyleName}"];

                        figureStyle.NetworkDisplayMode = SurveyElevationDisplayType.FlattenElevation;
                        
                        tr.Commit();
                    }
                    doc.SendStringToExecute("REGENALL ", true, false, true);
                    Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"Flattened to 0'");
                }
                
            }
        }

        [CommandMethod("SF2Z")]

        public void SurveyFigure2Z()
        {

            var doc = Application.DocumentManager.CurrentDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var civdoc = CivilApplication.ActiveDocument;
            var targetZElevIn = ed.GetDouble("\nEnter the desired elevation for flattening survey figures: " );
            var targetZElev = targetZElevIn.Value;

            PromptSelectionResult result = SelectFigures();
            if (result.Status == PromptStatus.OK)
            {



                foreach (var objectId in result.Value.GetObjectIds())
                {
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        SurveyFigure figure = (SurveyFigure)tr.GetObject(objectId, OpenMode.ForRead);
                        SurveyFigureStyle figureStyle = (SurveyFigureStyle)tr.GetObject(figure.StyleId, OpenMode.ForRead);
                        dynamic oFigureStyle = figureStyle.AcadObject;
                        var figureStyleName = oFigureStyle.Name;
                        var styleId = civdoc.Styles.SurveyFigureStyles[$"{figureStyleName}"];

                        figureStyle.NetworkDisplayMode = SurveyElevationDisplayType.FlattenElevation;
                        figureStyle.FlattenToElevationBy = targetZElev;
                        tr.Commit();
                    }
                    doc.SendStringToExecute("REGENALL ", true, false, true);
                    Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"Flattened to {targetZElev}'");
                }

            }
        }

        [CommandMethod("SF3D")]

        public void SurveyFigure3D()
        {

            var doc = Application.DocumentManager.CurrentDocument;
            var db = doc.Database;
            var ed = doc.Editor;
            var civdoc = CivilApplication.ActiveDocument;

            PromptSelectionResult result = SelectFigures();
            if (result.Status == PromptStatus.OK)
            {



                foreach (var objectId in result.Value.GetObjectIds())
                {
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        SurveyFigure figure = (SurveyFigure)tr.GetObject(objectId, OpenMode.ForRead);
                        SurveyFigureStyle figureStyle = (SurveyFigureStyle)tr.GetObject(figure.StyleId, OpenMode.ForRead);
                        dynamic oFigureStyle = figureStyle.AcadObject;
                        var figureStyleName = oFigureStyle.Name;
                        var styleId = civdoc.Styles.SurveyFigureStyles[$"{figureStyleName}"];

                        figureStyle.NetworkDisplayMode = SurveyElevationDisplayType.UseElevation;

                        tr.Commit();
                    }
                    doc.SendStringToExecute("REGENALL ", true, false, true);
                    Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"Using true elevations");
                }

            }
        }


        private PromptSelectionResult SelectFigures()
        {
            var options = new PromptSelectionOptions();
            options.MessageForAdding = "Add Survey Figures";
            options.MessageForRemoval = "Remove Survey Figures";

            var filter = new SelectionFilter(new TypedValue[]
            {
                new TypedValue((int)DxfCode.Start, "AECC_SVFIGURE")
            });
            return Application.DocumentManager.MdiActiveDocument.Editor.GetSelection(options, filter);
        }


    }
}