Preview for Polyline root.

Preview for Polyline root.

smallƑish
Advocate Advocate
4,871 Views
47 Replies
Message 1 of 48

Preview for Polyline root.

smallƑish
Advocate
Advocate

For example, User picks 2 Points, we have 2 options to connect the 2 points with the orthogonal root.

 

lisp is here;

 

 

(defun c:1 ( / Z1 z2 z5 z6 z3 z4)
  
  (if (and (setq Z1 (getpoint "\n Top of L shape : "))
	   (setq z2 (getpoint Z1 "\n Bot of L shape : "))
	   (setq z3 (list (car Z1) (cadr z2) 0.))
	   (setq z6 (list (car z2) (cadr Z1) 0.))
	   (setq z4 (inters Z1 (polar Z1 (* 1.75 pi) 1.)
			    z3 z2 nil))
	   (setq z5 (inters z2 (polar z2 (* 1.75 pi) 1.)
			    Z1 z6 nil))
	   )
    (command "_.line" "_non" Z1 "_non" z3 "_non" z2 ""))
  (princ)
  )


(defun c:2 ( / Z1 z2 z5 z6 z3 z4)
  
  (if (and (setq Z1 (getpoint "\nTop of 7 shape: "))
	   (setq z2 (getpoint Z1 "\n Bot of 7 shape: "))
	   (setq z3 (list (car Z1) (cadr z2) 0.))
	   (setq z6 (list (car z2) (cadr Z1) 0.))
	   (setq z4 (inters Z1 (polar Z1 (* 1.75 pi) 1.)
			    z3 z2 nil))
	   (setq z5 (inters z2 (polar z2 (* 1.75 pi) 1.)
			    Z1 z6 nil))
	   )
    (command "_.line" "_non" Z1 "_non" z6 "_non" z2 ""))
  (princ)
  )

 

 

 

Any chance to preview option 1 and option 2 Before making the polyline ?

 

smallish_0-1700553442021.png

 

 

 

 

0 Likes
Replies (47)
Message 2 of 48

komondormrex
Mentor
Mentor
Accepted solution

check L7 custom command

 

;*************************************************************************************************************************

;	komondormrex, nov 2023

;*************************************************************************************************************************

(defun c:l7 (/ side_selected diagonal_point_1 diagonal_point_2 point_3_distance point_3 mid_point_1_2
			   point_3_angle_org point_3_angle error_occurred
			)
	(setq diagonal_point_1 (getpoint "\nPick 1st diagonal point: ")
		  diagonal_point_2 (getpoint diagonal_point_1 "\nPick 2nd diagonal point: ")
		  point_3_distance (distance (setq point_3 (inters diagonal_point_1 (polar diagonal_point_1 0 1) 
											 			   diagonal_point_2 (polar diagonal_point_2 (* 0.5 pi) 1) 
											 			   nil
									 			   )
									 )
									 (setq mid_point_1_2 (polar diagonal_point_1
																(angle diagonal_point_1 diagonal_point_2)
																(* 0.5 (distance diagonal_point_1 diagonal_point_2))
													     )
									 )
						   )
		  point_3_angle_org (angle mid_point_1_2 point_3) 
	)
	(while (not side_selected)
			(princ "\rMove to select side, <LMB> to confirm")
			(setq error_occurred (if (vl-catch-all-error-p (setq grread_data (vl-catch-all-apply 'grread (list t 12 0)))) t nil))
	    	(cond
				(
					error_occurred
						(redraw)
						(setq side_selected t)
				)
				(
					(or
				 		(equal grread_data '(2 13))															;	Enter
				 		(equal grread_data '(2 32))															;	Space
						(= 25 (car grread_data))                                                            ;	RMB
						(= 11 (car grread_data))                                                            ;	RMB
						(= 3 (car grread_data))                                                             ;	LMB
					)
						(vla-addlightweightpolyline (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
													(vlax-safearray-fill (vlax-make-safearray vlax-vbdouble '(0 . 5))
														(apply 'append (mapcar '(lambda (vertex) 
																					(mapcar '+ '(0 0) vertex)
																	   			) 
																	   			(list diagonal_point_1 point_3 diagonal_point_2)
																	   )
														)
													)
		    			)
						(redraw)
						(setq side_selected t)
				)
				(
					(= 5 (car grread_data))                                                             	;	moving
						(if (equal diagonal_point_2 (cadr grread_data))
							(setq grread_data (list 5 (polar diagonal_point_2 
															(+ (* 0.5 pi) (angle diagonal_point_1 diagonal_point_2))
															1
													  )
											  )
							)
						)
						(setq point_3_angle (angle (inters diagonal_point_1 diagonal_point_2
														   (cadr grread_data)
														   (polar (cadr grread_data) point_3_angle_org 1)
														   nil
												   )
												   (cadr grread_data)
											)
							  point_3 (polar mid_point_1_2 point_3_angle point_3_distance) 
						)
						(redraw)
						(grdraw diagonal_point_1 point_3 1)
						(grdraw diagonal_point_2 point_3 1)
				)
				(
				 	t
				)
			)
	)
	(princ)
)

;*************************************************************************************************************************

 

Message 3 of 48

smallƑish
Advocate
Advocate

As always your @komondormrex  reply is perfect. Thank you so much.

0 Likes
Message 4 of 48

Kent1Cooper
Consultant
Consultant

Here's another [shorter] way:

 

(defun C:LCORNERS ; = Orthogonal L between user-specified Corners [with to-which-side pick]
  (/ toward p1 p3 p2 p4 done cur L)
  (defun toward (pt); distance from cursor to line through pt parallel to diagonal
    (distance
      (cadr cur)
      (inters pt (polar pt (angle p1 p3) 1) (cadr cur) (polar (cadr cur) (+ (angle p1 p3) (/ pi 2)) 1) nil)
    ); distance
  ); defun
  (setq
    p1 (reverse (cdr (reverse (getpoint "\nOne corner/end of L: ")))); [XY only]
    p3 (reverse (cdr (reverse (getcorner p1 "\nOpposite corner/end, then pick to which side: "))))
    p2 (list (car p3) (cadr p1)); horizontal from p1
    p4 (list (car p1) (cadr p3)); horizontal from p3
  ); setq
  (while
    (and (not done) (setq cur (grread T 12 0)))
    (cond
      ((= (car cur) 5); moved cursor
        (if L (entdel L))
        (setq L
          (entmakex
            (list
              '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline")
              '(90 . 3); vertices
              (cons 70 (* (getvar 'plinegen) 128)); open; 128=generation on; PLINEGEN = 0 or 1
              (cons 10 p1)
              (cons 10 (if (< (toward p2) (toward p4)) p2 p4)); which other corner
              (cons 10 p3)
            ); list
          ); entmakex
        ); setq
      ); 5 condition
      ((= (car cur) 3) (setq done T)); picked - leave drawn Polyline, end (while) loop
    ); cond - grread possibilities
  ); while
  (prin1)
); defun - C:LCORNERS

 

Kent Cooper, AIA
Message 5 of 48

Sea-Haven
Mentor
Mentor

Could use a 2x2 custom dcl don't have example with "L's" but like this choose direction, then pick points.

SeaHaven_0-1700618521183.png

 

 

 

0 Likes
Message 6 of 48

smallƑish
Advocate
Advocate

@komondormrex 

@Kent1Cooper 

 

I have a question, If I m adding more options, example 45Drg Intersection points, Any possible options to make a loop of  grread possibilities by pressing any key (TAB KEY) on keyboard?

0 Likes
Message 7 of 48

komondormrex
Mentor
Mentor
Accepted solution

very likely) show what options you want to add.

this one utilizes <Tab> for switching between directions.

(defun c:l7 (/ side_selected diagonal_point_1 diagonal_point_2 point_3_distance point_3 mid_point_1_2
			   point_3_angle_org point_3_angle error_occurred
			)
	(setq diagonal_point_1 (getpoint "\nPick 1st diagonal point: ")
		  diagonal_point_2 (getpoint diagonal_point_1 "\nPick 2nd diagonal point: ")
		  point_3_distance (distance (setq point_3 (inters diagonal_point_1 (polar diagonal_point_1 0 1) 
											 			   diagonal_point_2 (polar diagonal_point_2 (* 0.5 pi) 1) 
											 			   nil
									 			   )
									 )
									 (setq mid_point_1_2 (polar diagonal_point_1
																(angle diagonal_point_1 diagonal_point_2)
																(* 0.5 (distance diagonal_point_1 diagonal_point_2))
													     )
									 )
						   )
		  point_3_angle (angle mid_point_1_2 point_3) 
	)
	(grdraw diagonal_point_1 point_3 1)
	(grdraw diagonal_point_2 point_3 1)
	(while (not side_selected)
			(princ "\rPress <Tab> to change position, <Space> to confirm")
			(setq error_occurred (if (vl-catch-all-error-p (setq grread_data (vl-catch-all-apply 'grread (list t 12 0)))) t nil))
	    	(cond
				(
					error_occurred
						(redraw)
						(setq side_selected t)
				)
				(
					(or
				 		(equal grread_data '(2 13))															;	Enter
				 		(equal grread_data '(2 32))															;	Space
						(= 25 (car grread_data))                                                            ;	RMB
						(= 11 (car grread_data))                                                            ;	RMB
						(= 3 (car grread_data))                                                             ;	LMB
					)
						(vla-addlightweightpolyline (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
													(vlax-safearray-fill (vlax-make-safearray vlax-vbdouble '(0 . 5))
														(apply 'append (mapcar '(lambda (vertex) 
																					(mapcar '+ '(0 0) vertex)
																	   			) 
																	   			(list diagonal_point_1 point_3 diagonal_point_2)
																	   )
														)
													)
		    			)
						(redraw)
						(setq side_selected t)
				)
				(
					(equal grread_data '(2 9))                      ;	tab
						(redraw)
						(setq point_3_angle (+ point_3_angle pi)
							  point_3 (polar mid_point_1_2 point_3_angle point_3_distance)
						)
						(grdraw diagonal_point_1 point_3 1)
						(grdraw diagonal_point_2 point_3 1)
				)
				(
				 	t
				)
			)
	)
	(princ)
)
Message 8 of 48

smallƑish
Advocate
Advocate

The options that I wish to add, look very complicated. Still attached dwg

0 Likes
Message 9 of 48

komondormrex
Mentor
Mentor

indeed they look so.

0 Likes
Message 10 of 48

Kent1Cooper
Consultant
Consultant

Those could probably be done.  For an example of something similar, see the RMP command in RectMidPoint.lsp >here<.  Try it, giving it either the Fillet or Chamfer option [before picking the midpoint] -- it can draw shapes more complex than just the L.  The (grread) function has a way of reading keyboard input [see the Dimensions option in RMP], so it should be possible to get Tab [or any other key you want] to cycle through options.

EDIT:  Link now fixed.

Kent Cooper, AIA
Message 11 of 48

komondormrex
Mentor
Mentor
Accepted solution

but actually they're not

;*************************************************************************************************************************

;	komondormrex, nov 2023

;*************************************************************************************************************************

(defun c:l7 (/ side_selected point_1 point_2 point_3_distance point_3 point_1_2
			   point_3_angle_org point_3_angle error_occurred option_number
			   angle_1_2 45_angle long_angle
			)
	(setq option_number 1
		  point_1 (getpoint "\nPick 1st diagonal point: ")
		  point_2 (getpoint point_1 "\nPick 2nd diagonal point: ")
		  point_3_distance (distance (setq point_3 (inters point_1 (polar point_1 0 1)
											 			   point_2 (polar point_2 (* 0.5 pi) 1)
											 			   nil
									 			   )
									 )
									 (setq point_1_2 (polar point_1
																(setq angle_1_2 (angle point_1 point_2))
																(* 0.5 (distance point_1 point_2))
													     )
									 )
						   )
		  point_3_angle (angle point_1_2 point_3)
		  45_angle (cond
			 			((< 0 angle_1_2 (* 0.5 pi)) (* 0.25 pi))
			 			((< (* 0.5 pi) angle_1_2 pi) (* 0.75 pi))
			 			((< pi   	   angle_1_2 (* 1.5 pi)) (* 1.25 pi))
			 			((< (* 1.5 pi) angle_1_2 (* 2 pi)) (* 1.75 pi))
				   )
		  long_angle (if (apply '< (mapcar '+ '(0 0) (mapcar 'abs (mapcar '- point_1 point_2)))) (* 0.5 pi) 0)
	)
	(grdraw point_1 point_3 1)
	(grdraw point_2 point_3 1)
	(while (not side_selected)
			(princ "\rPress <Tab> to change position, <Space> to confirm")
			(setq error_occurred (if (vl-catch-all-error-p (setq grread_data (vl-catch-all-apply 'grread (list t 12 0)))) t nil))
	    	(cond
				(
					error_occurred
						(redraw)
						(setq side_selected t)
				)
				(
					(or
				 		(equal grread_data '(2 13))															;	Enter
				 		(equal grread_data '(2 32))															;	Space
						(= 3 (car grread_data))                                                             ;	LMB
					)
						(foreach pline pline_list
							(vla-addlightweightpolyline (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
														(vlax-safearray-fill (vlax-make-safearray vlax-vbdouble (cons 1 (* 2 (length pline))))
															(apply 'append (mapcar '(lambda (vertex)
																						(mapcar '+ '(0 0) vertex)
																		   			)
																		   			(mapcar '(lambda (vertex) (trans vertex 1 0)) pline)
																		   )
															)
														)
		    				)
						)
						(redraw)
						(setq side_selected t)
				)
				(
					(or
						(equal grread_data '(2 9))                      									;	tab
						(= 25 (car grread_data))                                                            ;	RMB
						(= 11 (car grread_data))                                                            ;	RMB
					)

						(redraw)
						(setq option_number (1+ option_number))
						(if (= 9 option_number) (setq option_number 1))
						(cond
							(
								(= 1 option_number)
									(setq point_3 (polar point_1_2 point_3_angle point_3_distance)
										  pline_list (list (list point_1 point_3 point_2))
									)
									(grdraw point_1 point_3 1)
									(grdraw point_2 point_3 1)
							)
							(
								(= 2 option_number)
									(setq point_3_angle (+ point_3_angle pi)
										  point_3 (polar point_1_2 point_3_angle point_3_distance)
										  pline_list (list (list point_1 point_3 point_2))
									)
									(grdraw point_1 point_3 1)
									(grdraw point_2 point_3 1)
							)
							(
								(= 3 option_number)
									(setq point_3 (list (car point_1) (cadr point_1_2))
										  point_4 (list (car point_2) (cadr point_1_2))
										  pline_list (list (list point_1 point_3 point_4 point_2))
									)
									(grdraw point_1 point_3 1)
									(grdraw point_3 point_4 1)
									(grdraw point_4 point_2 1)
							)
							(
								(= 4 option_number)
									(setq point_3 (list (car point_1_2) (cadr point_1))
										  point_4 (list (car point_1_2) (cadr point_2))
										  pline_list (list (list point_1 point_3 point_4 point_2))
									)
									(grdraw point_1 point_3 1)
									(grdraw point_3 point_4 1)
									(grdraw point_4 point_2 1)
							)
							(
								(= 5 option_number)
									(setq point_3 (list (car point_1) (cadr point_1_2))
										  point_4 (list (car point_2) (cadr point_1_2))
										  pline_list (list (list point_1 point_3 point_4 point_2) (list point_1 point_2))
									)
									(grdraw point_1 point_3 1)
									(grdraw point_3 point_4 1)
									(grdraw point_4 point_2 1)
									(grdraw point_1 point_2 1)
							)
							(
								(= 6 option_number)
									(setq point_3 (list (car point_1_2) (cadr point_1))
										  point_4 (list (car point_1_2) (cadr point_2))
										  pline_list (list (list point_1 point_3 point_4 point_2) (list point_1 point_2))
									)
									(grdraw point_1 point_3 1)
									(grdraw point_3 point_4 1)
									(grdraw point_4 point_2 1)
									(grdraw point_1 point_2 1)
							)
							(
								(= 7 option_number)
									(setq point_3 (inters point_1 (polar point_1 45_angle 1) point_2 (polar point_2 long_angle 1) nil)
										  pline_list (list (list point_1 point_3 point_2))
									)
									(grdraw point_1 point_3 1)
									(grdraw point_3 point_2 1)
							)
							(
								(= 8 option_number)
									(setq point_3 (inters point_2 (polar point_2 45_angle 1) point_1 (polar point_1 long_angle 1) nil)
										  pline_list (list (list point_1 point_3 point_2))
									)
									(grdraw point_1 point_3 1)
									(grdraw point_3 point_2 1)
							)
							(
								t
							)
						)
				)
				(
				 	t
				)
			)
	)
	(princ)
)

;*************************************************************************************************************************
Message 12 of 48

Kent1Cooper
Consultant
Consultant

Would it make sense to have three options instead of six, and within each, have the same kind of preview-flipping depending on the cursor location?  Options 1 & 2 could be the L option, with flipping as in our previous routines, options 3 & 4 could be the Z option, similarly previewing, and options 5 & 6 the [I don't know what to call it] option.  They could be cycled through with Tab or something, or you could jump directly to any with a specific key.  [The cycling option could be preferable because you don't need to name them, nor know what the key is for each variation.]

Kent Cooper, AIA
Message 13 of 48

Kent1Cooper
Consultant
Consultant
Accepted solution

@Kent1Cooper wrote:

Would it make sense to have three options instead of six, and within each, have the same kind of preview-flipping depending on the cursor location?  Options 1 & 2 could be the L option, with flipping as in our previous routines, options 3 & 4 could be the Z option, similarly previewing, and options 5 & 6 the [I don't know what to call it] option.  They could be cycled through with Tab or something, or you could jump directly to any with a specific key. ....


As in the attached.  It actually lets you choose which shape in two ways, either directly by typing a letter [I decided to call the one with the diagonal the Dogleg shape, so the choices are L/Z/D] or by pressing Tab which causes it to cycle to the next possible shape.  The which-side preview-flipping operates within all shape options.  See the comments at the top.  [You can change the command name to something shorter if you want.]

LZDCORNERS.gif

It doesn't show the keystrokes part, but the first switches between shapes are by Tab, until it gets back to the L, and then I typed letter options [D then Z then L], ending with confirming the upper-left-ward L shape.

Kent Cooper, AIA
Message 14 of 48

smallƑish
Advocate
Advocate

@komondormrex 

I can see how complicated the program is. Thank you so much.

As always no words to express my gratitude 

 

0 Likes
Message 15 of 48

smallƑish
Advocate
Advocate

@Kent1Cooper 

Thank you so much for the kent version. 

 

0 Likes
Message 16 of 48

smallƑish
Advocate
Advocate

🙏

0 Likes
Message 17 of 48

smallƑish
Advocate
Advocate

I apologize, missed a few options earlier, if possible please consider;

smallish_0-1700685149253.png

 

 

Also, is that possible to continue the process as a loop?

That is once the L7 is completed, again activate L7 cmd, consider existing P2 as new P1, And ask the user to pick New P2 only.(to avoid the additional steps of calling L7 and pick P1)

0 Likes
Message 18 of 48

Kent1Cooper
Consultant
Consultant

What's the difference between Options 5 & 8, and between Options 6 & 7?  Does the color difference in your image mean anything?

 

As for Option 9, obviously a simple LINE [or PLINE if there's reason for it to be one] command would do that -- does it really need to be among cycling or key-coded options?

Kent Cooper, AIA
Message 19 of 48

smallƑish
Advocate
Advocate

My mistake, The Screen short re attached with the corrected options

Yes, 9 is just a line but adding in the options loop is useful in this case to continue the loop key coded options as you explained.

 

smallish_2-1700687127782.png

 

 

smallish_1-1700686909599.png

 

 

 

0 Likes
Message 20 of 48

Kent1Cooper
Consultant
Consultant

Well, the attached doesn't do your new variety of Options 5 & 6* [maybe later], but adding the straight-from-corner-to-corner option wasn't difficult.  I couldn't use D for Direct or Diagonal, so I called it the Straight option.  You still need to pick somewhere to confirm that's what you want, even though it doesn't show a change as you move the cursor from side to side, because you could still choose a different option by letter or Tab.

 

* For 5 & 6, is the idea that the extreme ends are the two picked locations, which are not really "corners" any more, because the route goes outside the rectangle they would be corners of?  And both segments would be in 45°-multiple directions?

Kent Cooper, AIA