horizontal polygon

horizontal polygon

omarsvn
Enthusiast Enthusiast
460 Views
6 Replies
Message 1 of 7

horizontal polygon

omarsvn
Enthusiast
Enthusiast

I created a basic code to let me move a polygon choosing one of its line, I just want to set horizontal one of its sides and the whole polygon respect of the chosen line, it doesn't need to be aligned with something, it works, the only thing I'm not able to do is move the things inside of the polygon, must of the time text and blocks.Screenshot (121).png

this is code

(defun c:vert ()
(setq picked_data (entsel "\nPick pline's linear segment: ")
picked_pline (car picked_data)
picked_point (vlax-curve-getclosestpointto picked_pline (cadr picked_data))
picked_param (fix (vlax-curve-getparamatpoint picked_pline picked_point))
p1 (vlax-curve-getpointatparam picked_pline picked_param)
p2 (vlax-curve-getpointatparam picked_pline (1+ picked_param))
p3 (list (car p2) (cadr p1)))
(command "_.align" picked_data "" "_non" p1 "_non" p1 "_non" p2 "_non" p3 "" "_No"))

0 Likes
Accepted solutions (1)
461 Views
6 Replies
Replies (6)
Message 2 of 7

ВeekeeCZ
Consultant
Consultant

You can simply select them...

 

(defun c:vert ()
  (setq ss (ssget)
	picked_data (entsel "\nPick pline's linear segment: ")
	picked_pline (car picked_data)
	picked_point (vlax-curve-getclosestpointto picked_pline (cadr picked_data))
	picked_param (fix (vlax-curve-getparamatpoint picked_pline picked_point))
	p1 (vlax-curve-getpointatparam picked_pline picked_param)
	p2 (vlax-curve-getpointatparam picked_pline (1+ picked_param))
	p3 (list (car p2) (cadr p1)))
  (command "_.align" ss "" "_non" p1 "_non" p1 "_non" p2 "_non" p3 "" "_No")
  (princ))

 

0 Likes
Message 3 of 7

Moshe-A
Mentor
Mentor
Accepted solution

@omarsvn hi,

 

check my ROTBYEDGE command built on your program but uses ROTATE command.

all contents inside the polygon is taken

the basepoint for rotation would be the close vertex (node) to the picked point.

 

enjoy

Moshe

 

(defun c:rotBYedge (/ _geometric aligned_angle  ; local functions
		      picked_data picked_pline elist picked_point picked_param p1 p2 ss tmp)

 ; Anonymous function
 (setq _geometric (lambda (l) (mapcar (function (lambda (item) (cdr item))) (vl-remove-if-not (function (lambda (item) (= (car item) 10))) l))))
 
 (defun aligned_angle (t1 t2 / a0 r ra)
  (setq a0 (angle t1 t2))
  (setq r (fix (/ a0 pi 0.5)))

  (setq ra (if (< (- a0 (* r pi 0.5)) (- (* (1+ r) pi 0.5) a0))
            (* r pi 0.5)
            (* (1+ r) pi 0.5)
           ); if
  ); setq

  (* -1 (- a0 ra))
 ); aligned_angle


 ; here start c:rotBYedge
 (setvar "cmdecho" 0)
 (command "._undo" "_begin")
  
 (if (and
       (setq picked_data (entsel "\nPick pline's linear segment: "))
       (setq picked_pline (car picked_data))
       (setq elist (entget picked_pline))
       (eq (cdr (assoc '0 elist)) "LWPOLYLINE")
       (= (logand (cdr (assoc '70 elist)) 1) 1) ; must be close
     )
  (progn
   (setq picked_point (vlax-curve-getclosestpointto picked_pline (cadr picked_data)))
   (setq picked_param (fix (vlax-curve-getparamatpoint picked_pline picked_point)))
   (setq p1 (vlax-curve-getpointatparam picked_pline picked_param))
   (setq p2 (vlax-curve-getpointatparam picked_pline (1+ picked_param)))

   (if (setq ss (ssget "_cp" (_geometric elist)))
    (progn
     ; choose vertex for rotation base point
     (if (< (distance p2 picked_point) (distance p1 picked_point))
      (setq tmp p1 p1 p2 p2 tmp)
     )

     (command "._rotate" "_si" ss p1 (angtos (aligned_angle p1 p2) 0 4))
    ); progn
   ); if
   
  ); progn
 ); if

 (command "._undo" "_end")
 (setvar "cmdecho" 1)
  
 (princ)
); c:rotBYedge

 

 

 

Message 4 of 7

omarsvn
Enthusiast
Enthusiast

it works fantastic, it is what I was looking for, is it possible works when the polygons are already blocks? I mean sometimes I convert the polygons and other objects into a block since there are lines outside the polygon I want to move according to it

0 Likes
Message 5 of 7

Sea-Haven
Mentor
Mentor

Have a look at GROUP command similar to a block.

Message 6 of 7

komondormrex
Mentor
Mentor

@omarsvn wrote:

I created a basic code to let me move a polygon choosing one of its line...


to move where? or you mean to straighten horizontally selected pline and its contents by rotating about picked  pline's linear segment vertex? 

Message 7 of 7

omarsvn
Enthusiast
Enthusiast

No where, just set it horizontal choosing one of its side and the whole polygon with it, including the text, blocks, lines are inside the polygon.

0 Likes