How to save it as a block?

How to save it as a block?

danglar
Advocate Advocate
903 Views
3 Replies
Message 1 of 4

How to save it as a block?

danglar
Advocate
Advocate

Attached program have a 2 subroutines

one c:raa (draw rotated rectangle - Lee Mak brilliant solution)

another one c:cross (draw cross line in rectangle and fill triangle created by it)

I combined these 2 subroutines to one by saving last element:

(setq e (entget (car (list (entlast)))))

My question is: These 2 subroutines returns 3 separated elements: rotated rectangle, cross line and solid for filled triangle. Is it possible to combine these elements to one (block or group)

Any help will be very appriciated

 

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

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try this quick...

... you really should never call the cross2 without c:raa. Erase the c: prefix.

 

(defun c:cross2 (/ pnt1 pnt2 pnt3 pnt4  lst e len n e1 ss)

   ;(setq ew (list (entlast)))


  (setq ss (ssadd (entlast)))
  
	(setq e (entget (entlast)))
	;get the entity list

  
	(setq len (length e))
	;get the length of the list

	(setq n 0)
	;set counter to zero
	(setq lst nil)
	(repeat len
	;repeat for the length of the entity list

	  (setq e1 (car (nth n e)))
	  ;get each item in the entity list
	  ;and strip the entity code number

	  (if (= e1 10)
	  ;check for code 10 (vertex)

	    (progn
	    ;if it's group 10 do the following

		(terpri)
		  ;new line
		(setq lst (if lst (append lst (list(cdr (nth n e))))(list(cdr (nth n e)))))	  
	    );progn

	  );if
	  (setq n (1+ n))
	  ;increment the counter

	);repeat
  (mapcar 'set '(pnt1 pnt2 pnt3 pnt4) lst)
  
	        (setq pnt1 (strcat(rtos(car pnt1))"," (rtos(cadr pnt1))))
	      
		(setq pnt2 (strcat(rtos(car pnt2)) ","(rtos(cadr pnt2))))

		(setq pnt3 (strcat(rtos(car pnt3)) ","(rtos(cadr pnt3))))

		(setq pnt4 (strcat(rtos(car pnt4)) ","(rtos(cadr pnt4))))

(command "line" pnt1 pnt3 "")
  (ssadd (entlast) ss)
  
;(command "line" pnt2 pnt4 "")
(command "solid" pnt1 pnt2 pnt3 "" "")
  (ssadd (entlast) ss)

  (command "_.COPYBASE" pnt1 ss "")
  (command "_.PASTEBLOCK" pnt1)
  (command "_.ERASE" ss "")
  
  
  (princ)
);defun

BTW The blue part is like +1, then -1... the result would be same without it.

This (setq e (entget (car (list (entlast)))))

 

And one more note... Lee's routine looks like it does the same thing as I was solving lately... with little less code:

(command "_.RECTANG" pause "_R" "_P" "@" (getpoint (getvar 'lastpoint)) pause)

 

Message 3 of 4

danglar
Advocate
Advocate

Thanks a LOT      

Works perfect, like I need

All your remarks (c: and about rectangle) will be accepted with pleasure

0 Likes
Message 4 of 4

Kent1Cooper
Consultant
Consultant

@danglar wrote:

.... Works perfect, like I need ....


 

But, if you'll pardon my butting in, seems a lot more complicated than necessary.  In addition, I would argue that you don't need the diagonal Line at all.  [It could be worth including if you make the Solid a different color, or put it on a different Layer, and want the diagonal edge of it bounded in the same way the rectangle's sides define its other edges.]  And, I would not go for the wacky Block name, such as A$Cc4a95499, that you'll get as a result, but would require the User to give the thing a name with some meaning.

 

Given that it starts with the assumption that the last thing drawn was a rectangle, see whether this will do the same for you [with the addition of soliciting a meaningful Block name]:

(vl-load-com); if needed
(defun c:cross3 (/ rect p1 bn) (setq rect (entlast)) (command "solid" "_none" (setq p1 (vlax-curve-getStartPoint rect)) "_none" (vlax-curve-getPointAtParam rect 1) "_none" (vlax-curve-getPointAtParam rect 2) "" "" "_.block" (setq bn (lisped "BlockName")) "_none" p1 rect (entlast) "" "_.insert" bn "_none" p1 "" "" "" ); command (princ) );defun

The drawing of the rectangle itself could also be built into the front of that, for a single consolidated command, and consider that the RECTANG command now has a Rotation option  that could help out with that.

 

Kent Cooper, AIA
0 Likes