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
Solved! Go to Solution.
Solved by Jeff_M. Go to Solution.
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
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.
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
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
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)
)
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?
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
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!
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)
)
...
UCS note: Vlax-Curve-GetClosestPointToProjection requires a WCS point and returns a WCS vector.