Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Converting Line to Rectangle Automatically

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
s.holland.cmc
5601 Views, 6 Replies

Converting Line to Rectangle Automatically

Hello all,

I have a query as to how I could automate the replacing of selected individual lines with predetermined sized rectangular blocks centered on the line at the angle and on the “0” layer . See attached file:

Would anyone have any ideas as to go about this. The rectangle need not necessarily be a polyline, 4 single lines would be sufficient. And whether the original line is or is not replaced is unimportant either.

6 REPLIES 6
Message 2 of 7

Hi,

 

>> replacing of selected individual lines

If "individual" means that there is no automatic way to select them I would create a block containing the 0.5x0.03 rectangle and including a alignment parameter with the insertion point in the middle of the rectangle.

The resulting job would be then to insert that block, having object-snap "mid" active and show one baseline after the other (and the alignment parameter rotates automatically the block parallel to the line).

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 7
hmsilva
in reply to: s.holland.cmc

Hi s.holland.cmc,

in addition to what Alfred wrote, and for curiosity, do you have lots of rectangles to draw or just a few?

In your .pdf example I noticed that some rectangles were not 0.03x0.5, they were 0.03x1.0 or two with 0.03x0.5?

What is the criteria to draw a diferent rectangle?

 

If you have lots of rectangles to draw, is possible to write a lisp code, to perform this task for you.

Or I can write one, or post at the Visual LISP AutoLISP and General Customization Forum, there you will find some help to write the code.

 

Henrique

EESignature

Message 4 of 7
s.holland.cmc
in reply to: hmsilva

Sorry about that. I did forget that if I have a line shorter than or equal to 1.50” it needs a 0.03” x 0.5” rectangle. Anything larger than that needs a 0.03” x 1.0” rectangle. I can have over 1000 lines to convert per job. I’ve looked into writing a lisp file, but I can’t understand the code. 

Message 5 of 7
hmsilva
in reply to: s.holland.cmc


@s.holland.cmc wrote:

Sorry about that. I did forget that if I have a line shorter than or equal to 1.50” it needs a 0.03” x 0.5” rectangle. Anything larger than that needs a 0.03” x 1.0” rectangle. I can have over 1000 lines to convert per job. I’ve looked into writing a lisp file, but I can’t understand the code. 


One way:

(defun c:test (/ A B C D E I LN P01 P02 P03 P04 P1 P2 P3 P4 SS)
  (if (and (not (prompt "\nSelect the lines to draw rectangles: "))
	   (setq ss (ssget ":L" '((0 . "LINE"))))
      );; and
    (progn
      (setq i (sslength ss))
      (while (not (minusp (setq i (1- i))))
	(setq ln (entget (ssname ss i))
	      p1 (cdr (assoc 10 ln))
	      p2 (cdr (assoc 11 ln))
	      p3 (mapcar '(lambda (a b) (/ (+ a b) 2)) p1 p2)
	      d (abs (distance p1 p2))
	      );; setq
	(if (<= d 1.5)
	   (setq c -0.25
		 e 0.5)
	   (setq c -0.5
		 e 1.0)
	  );; if
	(setq p4 (polar p3 (angle p3 p1) c)
	      p01 (polar p4 (+ (angle p1 p3) (* pi 0.5)) 0.015)
	      p02 (polar p01 (angle p3 p1) e)
	      p03 (polar p02 (- (angle p1 p3) (* pi 0.5)) 0.03)
	      p04 (polar p03 (angle p1 p3) e)
	      );; setq
	;(entdel (ssname ss i));; if you want to delete the lines uncomment this line
	(entmake (list '(0 . "LWPOLYLINE")
		       '(100 . "AcDbEntity")
		       '(100 . "AcDbPolyline")
		       '(90 . 4)
		       '(70 . 1)
		       (cons 10 P01)
		       (cons 10 P02)
		       (cons 10 P03)
		       (cons 10 P04)
		 );; list
	);; entmake
      );; while
    );; progn
  );; if
  (princ)
);; test

hope that helps
Henrique

EESignature

Message 6 of 7
s.holland.cmc
in reply to: hmsilva

Awesome! Thank You. That works perfectly.

Message 7 of 7
hmsilva
in reply to: s.holland.cmc

You're welcome, s.holland.cmc
Glad I could help

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost