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: 

Feature line information

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
rfg018
958 Views, 11 Replies

Feature line information

Using lisp;

I would like to know how to get the feature line information using lisp?

 

At this point I'm looking for the angle between the end point where I pick the feature line.

My goal is to rotate the crosshair to match the feature line.  I can do this with a line or polyline.

 

Thanks

11 REPLIES 11
Message 2 of 12
Ajilal.Vijayan
in reply to: rfg018

Something Like this

 

(setq FLE (car (entsel "\nSelect the featureline: ")))
(setq FLE (vlax-ename->vla-object FLE))
(vlax-dump-object FLE T)

 then use vlax-get-property or method to get the information

 

Featureline Lisp

Message 3 of 12
Jeff_M
in reply to: rfg018

You can use the vlax-curve-* functions with featurelines.

Command: (setq ent (entsel))

Select object: (<Entity name: 7ffff519690> (1.78457e+006 291829.0 0.0))

Command: (setq crv (car ent) pick (cadr ent))
(1.78457e+006 291829.0 0.0)

Command: (setq pt (vlax-curve-getclosestpointto crv pick))
(1.78456e+006 291828.0 123.585)

Command: (setq param (vlax-curve-getparamatpoint crv pt))
0.584985

Command: (setq vec (vlax-curve-getfirstderiv crv param)
(0.755905 -0.654681 0.0))

Command: (setq ang (angle '(0.0 0.0) vec))
5.56942

 The last value is the angle of the segment selected in radians.

Jeff_M, also a frequent Swamper
EESignature
Message 4 of 12
RandyBenson
in reply to: Jeff_M

 

I'm not getting the right angle when I use that. What am I doing wrong?

  Given a feature line entity name (en) and a pick point (pp), I'm doing this:

...

(setq  e (entsel "\nSelect object to change snapangle to: ")
        en (car e)
        pp (cadr e)
    etype (cdr (assoc 0 (entget en)))

)

...

( cond

  ( (equal "AECC_FEATURE_LINE" etype)

    (setq p1 (vlax-curve-getclosestpointto en pp)

      param (vlax-curve-getparamatpoint en p1)

          vec (vlax-curve-getfirstderiv en param)

          ang (angle '(0.0 0.0) vec)
    )

  )

...

 

TIA,

Randy

 

Message 5 of 12
Jeff_M
in reply to: RandyBenson

The vlax-curve-getfirstderiv return a 3d vector. To get the angle represented by that vector use the (angle '(0.0 0.0 0.0) vec) . What makes you say that this is wrong? Note that the angle returned is in radians and in the AutoCAD direction, where 0 degrees is East, so you'd need to accomodate for that to get the true Azimuth or direction.

 

Here's the result of this using the attached featureline segment:

(setq ang1 (angle p1 vec);;per your code
        ang2 (angle '(0.0 0.0) vec);;as directed
)

ang2 = 3.48694
ang1 = 3.66281

 

(angtos ang1)
"209d51'50\""


(angtos ang2)
"199d47'12\"" <<<<correct

7-4-2013 3-51-19 PM.png

Jeff_M, also a frequent Swamper
EESignature
Message 6 of 12
RandyBenson
in reply to: Jeff_M

Hi Jeff!

I didn't expect a reply so soon! Thanks.

I absolutely didn't mean to imply that your answer was wrong; I meant MY interpretation of the answer was wrong and I knew it. But I'm still stumped.

Here's all I'm doing, and frustratingly it seems to work SOME of the time and fail as many times as it succeeds (even on different segments of the same feature line):

 

(defun c:sr ()

  (defun set-snapang (snang / ro)
    (setq ro (angtos snang 4 4))
    (princ (strcat "\nNew snap angle is " ro ". "))
    (setvar "snapang" snang)
    (setvar "cmdecho" 0)
  )

  (defun getro ( / en e pp p1 p2 etype)
    (while (null en)
      (setq  e (entsel "\nSelect object to change snapangle to: ")
            en (car e)
            pp (cadr e)
         etype (cdr (assoc 0 (entget en)))
      )
    )
    (cond
       ( (equal "AECC_FEATURE_LINE" etype)
        (setq p1 (vlax-curve-getclosestpointto en pp)
           param (vlax-curve-getparamatpoint en p1)
             vec (vlax-curve-getfirstderiv en param)
             ang (angle '(0.0 0.0) vec)
        )
        (set-snapang ang)
      )
      ( t
        (princ "\nMust be line, lwpolyline, xline, text, dimension,
                insert, hatch, feature line or viewport. Try again.")
      )
    )
  )

  (command "._UNDO" "BEG")
  (getro)
  (command "._UNDO" "END")
  (princ)
)

Message 7 of 12
Jeff_M
in reply to: RandyBenson

Hi Randy,

The only time it's not doing what I expect it to is when selecting and arc in a featureline. In those cases it is getting the angle at the start of the curve instead of at the slected point.I had never noticed this behavior before, but it is consistent. Not sure why the programmers didn't implement this correctly for the curves. If this occuring elswhere, could you post a sample dwg for me to check?

Jeff_M, also a frequent Swamper
EESignature
Message 8 of 12
RandyBenson
in reply to: Jeff_M

Here are the feature lines w'blocked from my working drawing; the ones that are giving me trouble aren't curves, just 3D f-lines.

Thanks for looking at this for me.

-Randy

Message 9 of 12
Jeff_M
in reply to: RandyBenson

OK, I see the issue. Not sure of the best way to workaround it. At one time the (vlax-curve-*) functions, when used with featurelines, ignored the elevations. I now see that this is no longer the case, so when using the (vlax-curve-getclosestpointto) function, it is using the selected point which is typically at 0 elevation so the closest point to it on the featureline is almost always a vertex. Need to somehow work on the f/l at 0 elevation OR snap the selected point to the f/l so the pt is at the correct elevation.

 

This affects a number of my custom commands that used to work just fine but now do not and I didn't even realize it until now. Thanks for bringing this to my attention!

Jeff_M, also a frequent Swamper
EESignature
Message 10 of 12
RandyBenson
in reply to: Jeff_M

Got it! (Please test.)

 

(setq p1 (vlax-curve-getclosestpointtoprojection en pp '(0.0 0.0 1.0))
         param (vlax-curve-getparamatpoint en p1)
           vec (vlax-curve-getfirstderiv en param)
           ang (angle '(0.0 0.0) vec)
)

...

Message 11 of 12
RandyBenson
in reply to: RandyBenson

UCS note: Vlax-Curve-GetClosestPointToProjection requires a WCS point and returns a WCS vector.

Message 12 of 12
Jeff_M
in reply to: RandyBenson

Yep, works for me. Now the question remains, why have I never used this function before? At least I sure don't recall using it.

Jeff_M, also a frequent Swamper
EESignature

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report