y-coordinate of a point on a curve/ pline

y-coordinate of a point on a curve/ pline

Anonymous
Not applicable
1,101 Views
10 Replies
Message 1 of 11

y-coordinate of a point on a curve/ pline

Anonymous
Not applicable

Hi all,is there an autolisp/ visual lisp function which returns the y-coordinate of a point on  a curve/ pline in current ucs if the x-coordinate of the point is given? I appreciate any help.

0 Likes
Accepted solutions (1)
1,102 Views
10 Replies
Replies (10)
Message 2 of 11

Kent1Cooper
Consultant
Consultant

I don't know of one, but one could be built easily enough.  I am picturing something that would draw a temporary vertical Line at the given X coordinate, and use the (intersectwith) method to find where it crosses the object.  From that location, the Y coordinate could be extracted, or it could report that it doesn't cross that X coordinate, or that it crosses it more than once.  Since you mention the current UCS, is the 3rd dimension a possibility?  That makes it more complicated, but it should be possible.

Kent Cooper, AIA
0 Likes
Message 3 of 11

Anonymous
Not applicable

Thank you for your reply kent, that is a good idea,and there is no possibility of the third dimension,the pline is always on the xy plane.

0 Likes
Message 4 of 11

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Thank you for your reply kent, that is a good idea,and there is no possibility of the third dimension,the pline is always on the xy plane.


Next questions:

 

Should the User be asked to select the object [whatever it is], and specify the X coordinate as a typed-in number, or pick a point on-screen, or some other approach?

 

Should the result be reported at the Command: line, or in a mid-screen Alert, or saved to a variable, or used in a calculation of something else, or written to a file, or put into the drawing as Text at or near the (intersectwith) point, or...?

Kent Cooper, AIA
0 Likes
Message 5 of 11

Anonymous
Not applicable

It is part of an autolisp routine which i am trying to write. what i need exactly is a function which i could pass two arguments (VARIABLES) to it (1. the entity name of the pline and 2. the x-coordinate of the point  which is an int value) and which returns and stores the y coordinate into a variable which i use for  another sub routine.

0 Likes
Message 6 of 11

Kent1Cooper
Consultant
Consultant

Try this:

 

(setq plobj (vlax-ename->vla-object yourEntityName))

(vla-getboundingbox plobj 'minpt 'maxpt)
(command "_.line"

  "_none" (list yourXcoord (cadr (vlax-safearray->list minpt)) 0)

  "_none" (list yourXcoord (cadr (vlax-safearray->list maxpt)) 0)

  ""

); command

(setq Ycoord

  (cadr

    (safearray-value

      (variant-value

        (vla-intersectwith

          (vlax-ename->vla-object (entlast))

          plobj

          acExtendNone

        )

      )

    )

  ); cadr

); setq

(entdel (entlast))

 

I tried extending both objects, with a short Line, but if the Polyline has an arc segment at either end, the extension of that can mean it finds virtual intersection you don't want.  That's why I went with getting the Y coordinates from the Polyline's bounding box to draw the temporary vertical Line.

 

That assumes one such crossing.  If the Polyline might be shaped such that there could be more than one, that would take some more playing around with some criterion to choose which one you want.

 

It puts nil in the Ycoord variable if the X coordinate is beyond the bounding box of the Polyline.

Kent Cooper, AIA
Message 7 of 11

hmsilva
Mentor
Mentor
Accepted solution

@Anonymous wrote:

It is part of an autolisp routine which i am trying to write. what i need exactly is a function which i could pass two arguments (VARIABLES) to it (1. the entity name of the pline and 2. the x-coordinate of the point  which is an int value) and which returns and stores the y coordinate into a variable which i use for  another sub routine.


Another

 

(vl-load-com)
(defun get_ycoord (ent xpt / int space xline)
   (if (and (= (type ent) 'ENAME)
            (or (= (type xpt) 'REAL)
                (= (type xpt) 'INT)
            )
       )
      (progn
         (setq space (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object)))))
         (setq xline (vla-addXline
                        space
                        (vlax-3d-point (trans (list xpt 0.0) 1 0))
                        (vlax-3d-point (trans (list xpt 1.0) 1 0))
                     )
         )
         (setq int (vlax-invoke xline 'IntersectWith (vlax-ename->vla-object ent) acExtendNone))
         (vla-delete xline)
         (if int
            (cadr (trans (list (car int) (cadr int)) 0 1))
         )
      )
   )
)

 

Hope this helps,
Henrique

EESignature

Message 8 of 11

Kent1Cooper
Consultant
Consultant

@hmsilva wrote:
.... 
....
         (setq xline (vla-addXline
....

 


Of course -- I should have thought of an Xline.  In my routine, you could replace this much:

(vla-getboundingbox plobj 'minpt 'maxpt)
(command "_.line"

  "_none" (list yourXcoord (cadr (vlax-safearray->list minpt)) 0)

  "_none" (list yourXcoord (cadr (vlax-safearray->list maxpt)) 0)

  ""

); command

 

with just this:

 

(command "_.xline" "_none" (list yourXcoord 0 0) "_none" "@0,1,0" "")

Kent Cooper, AIA
0 Likes
Message 9 of 11

hmsilva
Mentor
Mentor

@Kent1Cooper wrote:

@hmsilva wrote:
.... 
....
         (setq xline (vla-addXline
....

 


Of course -- I should have thought of an Xline.  

...


I do agree.

 


@Kent1Cooper wrote:
...
 In my routine, you could replace this much:

(vla-getboundingbox plobj 'minpt 'maxpt)
(command "_.line"

  "_none" (list yourXcoord (cadr (vlax-safearray->list minpt)) 0)

  "_none" (list yourXcoord(cadr (vlax-safearray->list maxpt)) 0)

  ""

); command

with just this:

(command "_.xline" "_none" (list yourXcoord 0 0) "_none" "@0,1,0" "")


Correct,

but the OP asked

'...the y-coordinate of a point on  a curve/ pline in current ucs ...'

and the return from vla-intersectwith is in WCS...

 

Henrique

EESignature

0 Likes
Message 10 of 11

Anonymous
Not applicable

Kent and Henerique, Thank you so much for your awesome suggestions and solutions, Henrique's  function is working great ! in wcs and  current ucs,that is one important step on developing my autolisp routine.

 

0 Likes
Message 11 of 11

hmsilva
Mentor
Mentor
You're welcome, solarch
Glad it's useful for you!

Henrique

EESignature

0 Likes