Looking to match x and y coordinates of polylines then perform a specific action

Looking to match x and y coordinates of polylines then perform a specific action

Anonymous
Not applicable
1,156 Views
3 Replies
Message 1 of 4

Looking to match x and y coordinates of polylines then perform a specific action

Anonymous
Not applicable

Hello to all:

 

I am using LISP routines to send geometry in a block to various layers depending on certain conditions.  I am stuck at this issue:  I want to send a closed polyline with 4 vertices to one of two layers based on the following criteria:

 

If the y-coordinate of the first vertex matches the y coordinate of the second vertex,
-then put the polyline object on the "ROLLERS" layer
Else if the x-coordinate of the first vertex matches the x coordinate of the seCond vertex,
-then put the polyline object on the "FRAMES" layer

 

Here's how it would fit in my program:

 

..............

(setq ymatch (cdr(vlax-get b 'coordinates)) ;;NOT SURE ABOUT THIS PART IN PARTICULAR
;;getting each line/polyline object
(cond ;;applying conditions here


((and (vlax-curve-isclosed b)
(equal vnum 4)
(????) if the Y-coordinate of the first vertex matches the Y coordinate of the second vertex
)
;;the object is a closed polyline WITH 4 VERTICES MATCHING THE FIRST CONDITION MENTIONED ABOVE
(addprop b "HILMOT-CONV-BLK-ROLLERS")
;; then add to this layer
)


((and (vlax-curve-isclosed b)
(equal vnum 4)
(????) if the X-coordinate of the first vertex matches the X coordinate of the second vertex
)
;;the object is a closed polyline WITH 4 VERTICES MATCHING THE SECOND CONDITION MENTIONED ABOVE
(addprop b "HILMOT-CONV-BLK-FRAMES")
;; then add to this layer
)

 

Does my request make sense?  Basically...

 If the Polyline resembles a telephone pole standing up, it should go on the "ROLLERS" layer

 If the Polyline resembles a telephone pole laying on the ground, it should go on the "FRAMES" layer

 

Thanks for any help in this matter!

0 Likes
Accepted solutions (1)
1,157 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant
Accepted solution

Because the 'Coordinates VLA Property is just an un-divided list of coordinate values, (cdr) on it is going to give you the whole list minus only the first X coordinate.  I think it would be easier to pull coordinates from the first two vertices as start-point and parameter-1 values:

 

(if (and (vlax-curve-isClosed b) (= vnum 4))

  (cond

    ((equal (cadr (vlax-curve-getStartPoint b)) (cadr (vlax-curve-getPointAtParam b 1)) 1e-4)

      (addprop b "HILMOT-CONV-BLK-ROLLERS")

    ); same-Y condition

    ((equal (car (vlax-curve-getStartPoint b)) (car (vlax-curve-getPointAtParam b 1)) 1e-4)

      (addprop b "HILMOT-CONV-BLK-FRAMES")

    ); same-X condition

  ); cond

); if

 

That won't do anything to one if it's diagonal.  IF you can assume that they will always be either horizontal or vertical [never diagonal], it could be simplified/shortened with an (if) function instead of (cond), inside one  (addprop) function.  

Kent Cooper, AIA
Message 3 of 4

Anonymous
Not applicable

YES!!

Thank you sir!  No diagonal lines will ever be involved here, so your answer is picture perfect Smiley Happy

0 Likes
Message 4 of 4

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... No diagonal lines will ever be involved ….


Then this should do it:

(if (and (vlax-curve-isClosed b) (= vnum 4))

  (addprop b

    (if (equal (car (vlax-curve-getStartPoint b)) (car (vlax-curve-getPointAtParam b 1)) 1e-4)

      "HILMOT-CONV-BLK-FRAMES" ; then [same X]

      "HILMOT-CONV-BLK-ROLLERS" ; else [same Y]

    ); if

  ); addprop

 

); if

Kent Cooper, AIA
0 Likes