Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change Feature Line Style in LISP

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
dwcouch123
8855 Views, 13 Replies

Change Feature Line Style in LISP

This has got to be something simple, but I can't get my head around it.  I want to take a feature line that has been created by the "stepped offset" command and change its style, in LISP, of course.  I have the entity name and have dumped the object, but the style of the FL is not one of them. It shows up in the properties box, but how do I get to it to change it??

 

Dave 

13 REPLIES 13
Message 2 of 14
Partha.Sarkar
in reply to: dwcouch123

I don't see 'Style' is exposed for AeccLandFeatureLine COM object.

Without digging it further, I doubt we can access the style.

 

Thanks,

 



Partha Sarkar
Developer Technical Services
Autodesk Developer Network

Message 3 of 14
dwcouch123
in reply to: Partha.Sarkar

How about a "simple" .NET routine that could be called by LISP? I have used a couple of those types of routines for other tasks.

Dave
Message 4 of 14
Partha.Sarkar
in reply to: dwcouch123

Hi Dave -

 

Using .NET API you should be able to do this.

 

Check this -

 

FeatureLine.StyleName -> Gets or sets the Featureline's style name.

 

Hope this helps.

 

Thanks,

Partha Sarkar

Autodesk



Partha Sarkar
Developer Technical Services
Autodesk Developer Network

Message 5 of 14
dwcouch123
in reply to: Partha.Sarkar

Partha, thank you.  Yes I tracked this down yesterday also.  Now I am trying to get it working.  I have the Feature Line object and I think I need to get the StyleId to get to the StyleName property.  I am working in C#, but I am an extreme novice.   Any help would be appreciated.

 

Dave 

Message 6 of 14
dwcouch123
in reply to: dwcouch123

Partha, (or anyone), my ignorance of C# will show below.  I am trying to change the style of a feature line.  O have a LSIP routine that will call this C# routine.  The inputs are the Feature Line Object Name and the Style to change it to.  I have not figured out the correct program lines.  Here is what I have.  Any help would be arrpeciated.

 

Here is the LISP code to call the C# routine.

 

(defun C:ChangeStyle ()
  (Setq FLLine (car (entsel "\nSlect Featrue Line to change style: ")))
  (setq FLObject (vlax-ename->vla-object FLLine))
  (setq newstyle "Curb")
  (FLStyleSetLisp FLObject newstyle)
)  

 And here is the C# code that I have so far that obviously does not work.

 

 

namespace FLStyleOverride
{
    
    public class FLStyleOverride

    {
       [LispFunction("FLStyleSetLisp")]
        
        public ResultBuffer cfunctionFLStyleSet(ResultBuffer rbfArgs)
               {
            try
            {
                Database db = Application.DocumentManager.MdiActiveDocument.Database;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    //Get the arguments passed in...
                    Array arInputArgs = null;
                    
                    arInputArgs = rbfArgs.AsArray();
                    ObjectId objId = (ObjectId)((TypedValue)arInputArgs.GetValue(0)).Value;
                    String Newstyle = (String) ((TypedValue)arInputArgs.GetValue(1)).Value;

                    Object NewStyleId = objId.GetObject(OpenMode.ForWrite);
                    String StyleName = Newstyle;


                    ResultBuffer rbfResult = default(ResultBuffer);
                    rbfResult = new ResultBuffer(new TypedValue(Convert.ToInt32(5005), "ProbableSuccess"));
                    tr.Commit();
                    return rbfResult;
                }
            }
            catch
            {
                ResultBuffer rbfBadResult = new ResultBuffer(new TypedValue((short)LispDataType.Nil));
                //ResultBuffer rbfBadResult = String Newstyle;
                return rbfBadResult;
            }
        }
    }
}

 Dave

Message 7 of 14
Jeff_M
in reply to: dwcouch123

First week of elk hunting was hot & dusty. Didn't see a thing. Week 2 starts Saturday in Washington with my son, already snowing where we are headed in the morning. Should have better chances.

 

Now, here's what worked for me. First the lisp, then the c# code:

(defun C:ChangeStyle ()
  (Setq FLLine (car (entsel "\nSlect Featrue Line to change style: ")))
  (setq FLObject (vlax-ename->vla-object FLLine))
  (setq newstyle "Curb")
  (FLStyleSetLisp (vlax-get FLObject 'Handle) newstyle)
)  

 

    public class FLStyleOverride
    {
        [LispFunction("FLStyleSetLisp")]

        public ResultBuffer cfunctionFLStyleSet(ResultBuffer rbfArgs)
        {
            try
            {
                Database db = Application.DocumentManager.MdiActiveDocument.Database;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    //Get the arguments passed in...
                    Array arInputArgs = null;

                    arInputArgs = rbfArgs.AsArray();
                    TypedValue tv = (TypedValue)arInputArgs.GetValue(0);
                    ObjectId objId = db.GetObjectId(false, new Handle(Int64.Parse((string)tv.Value, System.Globalization.NumberStyles.AllowHexSpecifier)), 0);
                    string Newstyle = (string)((TypedValue)arInputArgs.GetValue(1)).Value;

                    FeatureLine fl = (FeatureLine)objId.GetObject(OpenMode.ForWrite);
                    fl.StyleName = Newstyle;


                    ResultBuffer rbfResult = default(ResultBuffer);
                    rbfResult = new ResultBuffer(new TypedValue(Convert.ToInt32(5005), "ProbableSuccess"));
                    tr.Commit();
                    return rbfResult;
                }
            }
            catch
            {
                ResultBuffer rbfBadResult = new ResultBuffer(new TypedValue((short)LispDataType.Nil));
                //ResultBuffer rbfBadResult = String Newstyle;
                return rbfBadResult;
            }
        }
    }

 

Jeff_M, also a frequent Swamper
EESignature
Message 8 of 14
dwcouch123
in reply to: Jeff_M

Jeff, better luck this week.  I copied the code in and I am getting the same error I was getting earlier.  It is not recognizing the FeatureLine Object.  I get the following error.

 

Error 1 The type or namespace name 'FeatureLine' could not be found (are you missing a using directive or an assembly reference?) 

 

I looked at the API reference and it showed the Assembly AeccDbMgd as Version 10.0.1111.0, my version is 9.0.2566.0.  I am in C3d 2012.  Could this be the problem??  This is the header info.

 

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

 

And here are the references.

 

References.jpg

I plan on retiring in a little less than 2 years.  There is no way I will learn enough .NET to make it worth while.  I think I will just keep on stumbling along with LISP.

 

Thanks again for your help.

Dave

 

 

 

Message 9 of 14
Jeff_M
in reply to: dwcouch123

Make sure your usings are like so for the code I posted:(I should have shown this):

 

using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.Civil.Land.DatabaseServices; //(for 2013+ omit the Land.)

Jeff_M, also a frequent Swamper
EESignature
Message 10 of 14
dwcouch123
in reply to: Jeff_M

Jeff, adding the .Land.DataBaseServices fixed it.  Once more, thank you.  Also, just another reason I won't be spending a lot of time on .NET.  WAY to involved.  I guess I'm just too old to learn new tricks. 

 

Dave

Message 11 of 14
Partha.Sarkar
in reply to: dwcouch123

Dave -

 

Using .NET its just one line of code to change FeatureLine style 🙂

 

Check this -

 

http://adndevblog.typepad.com/infrastructure/2013/11/civil-3d-featureline-labeling-and-style-changin...

 

Cheers,

Partha



Partha Sarkar
Developer Technical Services
Autodesk Developer Network

Message 12 of 14
dwcouch123
in reply to: Partha.Sarkar

Thank you, Partha.  I expect I will be playing more with .NET.  I will be adding this site you referenced to my favorites.

 

Dave 

Message 13 of 14
MTaha
in reply to: Partha.Sarkar

hi, 

How can i change Line Styles for Detail Lines using API not UI ?

i cant find any function can set the line style for any detail line using API

Message 14 of 14
nick.amey
in reply to: dwcouch123

Hi Guys,

 

I don't have a great understanding of all the coding that you do, but i have an idea that I'm putting out there to see if it is possible. 

 

I would like to have an .dwg file with a bunch of layers sitting in it, and i would like to be able to create a feature line style from each of these layers. The idea is that it would grab the layer name, colour, lineweight, linetype.. Essentially it would just convert a layer into a Feature Line style.

 

I understand that i could go in and manually create feature line styles and assign the layer to each of them but that is quite time consuming and each of my clients have different drafting and design standards.

 

Thanks,

Nick

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report