Auto draw multiple rectangles

Auto draw multiple rectangles

kilama1331
Enthusiast Enthusiast
1,796 Views
13 Replies
Message 1 of 14

Auto draw multiple rectangles

kilama1331
Enthusiast
Enthusiast

I have over 300 manholes and valve pits to draw, and I have their center coordinates and dimensions. How best can I automate this process?

0 Likes
1,797 Views
13 Replies
Replies (13)
Message 2 of 14

Kent1Cooper
Consultant
Consultant

In what form do you "have" the information?

Kent Cooper, AIA
0 Likes
Message 3 of 14

kilama1331
Enthusiast
Enthusiast

In PDF but I can extract to excel.

0 Likes
Message 4 of 14

Kent1Cooper
Consultant
Consultant

If you can get it into an Excel file in .csv format, AutoLisp code can open and read lines from that, and separate the pieces of information around the comma separators, and draw rectangles.  That assumes that every line contains information in the same way, i.e. the pieces [center coordinates, sizes] are in the same order.  Are the rectangles always to be oriented orthogonally?  If not, presumably there's more information contained than what you've mentioned so far.

Kent Cooper, AIA
0 Likes
Message 5 of 14

Sea-Haven
Mentor
Mentor

If survey field data then yes angle will be a problem, but there is today another post about rotate a block to a close by pline.

 

The other suggestion is can read direct from Excel no need for a csv. 

 

Really need a Excel, a before dwg and an after.

0 Likes
Message 6 of 14

kilama1331
Enthusiast
Enthusiast
All are orthogonal
0 Likes
Message 7 of 14

hak_vz
Advisor
Advisor

Its a simple task. but provide data how to create this rectangles i.e. what you have:

centerpoint, width, height or what else.  Create small sample txt

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 8 of 14

Emmanuel_Kilama
Contributor
Contributor

Sorry for the late response

The responses seem to agree that it is possible, but none spell out how I can achieve it.
I have the center coordinate, the dimensions of the manhole, and the thickness

0 Likes
Message 9 of 14

hak_vz
Advisor
Advisor

1) you have .txt file with manholes positions and dimensions

row in data is

x,y,width,height, thickness

 

let say

 

 

100,100,150,150,25
500,500,150,150,25
300,300,150,150,25
1000,1000,150,150,25
1200,1200,150,150,25

 

 

2) Here is a list that creates manholes

 

 

(defun c:kilama (/ *error* string_to_list f file1 redak x y w h d dx dy p1 p2)

	(defun *error* ()
		(setvar 'cmdecho 1)
		(close file1)
	)
	(defun string_to_list ( str del / pos )
        (if (setq pos (vl-string-search del str))
            (cons (substr str 1 pos) (string_to_list (substr str (+ pos 1 (strlen del))) del))
            (list str)
        )
    )  
	(setvar 'cmdecho 0)
	(setq f (getfiled "Open File" (getvar "dwgprefix") "txt" 2))
	(setq file1 (open f "r"))
	(while (setq redak (read-line file1))
		(mapcar 'set '(x y w h d) (mapcar 'atof (string_to_list redak ",")))
		(setq dx (* 0.5 w) dy (* 0.5 h))
		(setq p1 (mapcar '- (list x y) (list dx dy)))
		(setq p2 (mapcar '+ (list x y) (list dx dy)))
		(command "_.rectangle" p1 p2)
		(command "_.offset" d (entlast) (list x y) "")	
	)
	(close file1)
	(command "_.zoom" "e")
	(setvar 'cmdecho 1)
	(princ)
)

 

 

 

As a result you receive

Screenshot 2024-03-19 183324.png

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 10 of 14

Sea-Haven
Mentor
Mentor

When we ask for say a Excel its to help you, Hak_vz has provided an answer but is frustrating when you have to redo code when it does not match real data.

 

So please post a Excel. Yes can read the Excel direct.

0 Likes
Message 11 of 14

Emmanuel_Kilama
Contributor
Contributor

Hello 
Here is an example of the data i would like to draw.

0 Likes
Message 12 of 14

Kent1Cooper
Consultant
Consultant

That doesn't contain enough information.  Isn't it pretty obvious what is lacking?

 

EDIT:  I think we can assume that A & B are plan dimensions, but are they inside or outside?  That is, if T is wall thickness, is that outward [my assumption] or inward from the A & B size?  Are A & B ever different from each other?  If so, which is in the Easting direction and which is in the Northing direction?  And the answer to that depends on them always being oriented orthogonally, but I can't imagine that's always the case -- I don't see anything that could be a rotation.  Or are they [not as this topic discusses, but could they be] circular, in which case maybe rotation wouldn't matter?  And it looks like H is Height from TOC [Top Of C...?] to BTM, but what is FGL?  Do we care for this purpose?

 

A simple diagram showing what the dimensions refer to would answer all questions.

Kent Cooper, AIA
0 Likes
Message 13 of 14

Sea-Haven
Mentor
Mentor

There is enough information. You have MH-O1, a X & Y, and the manhole is AxB in size.

 

Its late now maybe tomorrow will do.

 

 

0 Likes
Message 14 of 14

Sea-Haven
Mentor
Mentor

Try this matches your Excel, expects a block called MH01, which is a rectang 1.0x1.0 as a size ie 1000mm =1 metre. So for every manhole name need a block that fits in a 1x1 size. With insertion at midpoint.

 

Just open your Excel and then run program.

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/auto-draw-multiple-rectangles/td-p/12629624
; read excel and draw rectangs at X&Y and size.

(defun c:manholes ( / rows maxrow scx scy d1 d2)

(defun getrangexl ( / lst UR CR RADD )
  (setq lst '())
  (setq UR (vlax-get-property  (vlax-get-property myxl "ActiveSheet") "UsedRange"))
  (setq CR (vlax-get-property UR "CurrentRegion"))
  (setq RADD (vlax-get-property CR "Address"))
  (setq cnt (vlax-get-property CR  "Count"))
  (setq lst (_csv->lst58 radd))
  (setq st (vl-string-subst "" "$" (vl-string-subst "" "$" (nth 0 lst) )))
  (setq end (vl-string-subst "" "$" (vl-string-subst "" "$" (nth 1 lst) )))
  (setq st  (columnrow st))
  (setq end  (columnrow end))
)
; ColumnRow - Returns a list of the Column and Row number
; Function By: Gilles Chanteau from Marseille, France
; Arguments: 1
;   Cell$ = Cell ID
; Syntax example: (ColumnRow "ABC987") = '(731 987)
;default to "A1" if there's a problem
;-------------------------------------------------------------------------------
(defun ColumnRow (Cell$ / Column$ Char$ Row#)
  (setq Column$ "")
  (while (< 64 (ascii (setq Char$ (strcase (substr Cell$ 1 1)))) 91)
    (setq Column$ (strcat Column$ Char$)
          Cell$ (substr Cell$ 2)
    )
  )
  (if (and (/= Column$ "") (numberp (setq Row# (read Cell$))))
    (list (Alpha2Number Column$) Row#)
    '(1 1)
  )
)
; Alpha2Number - Converts Alpha string into Number
; Function By: Gilles Chanteau from Marseille, France
; Arguments: 1
;   Str$ = String to convert
; Syntax example: (Alpha2Number "ABC") = 731
;-------------------------------------------------------------------------------
(defun Alpha2Number (Str$ / Num#)
  (if (= 0 (setq Num# (strlen Str$)))
    0
    (+ (* (- (ascii (strcase (substr Str$ 1 1))) 64) (expt 26 (1- Num#)))
       (Alpha2Number (substr Str$ 2))
    )
  )
)

; thanks to Lee-mac for this defun 
; www.lee-mac.com
; 44 is comma 9 is tab 34 is space 58 is colon
(defun _csv->lst58 ( str / pos )
	(if (setq pos (vl-string-position 58 str))
		(cons (substr str 1 pos) (_csv->lst58 (substr str (+ pos 2))))
		(list str)
    )
)
;;	Thanks to fixo			;;
(defun getcell2 (row column / )
(setq cells (vlax-get-property  (vlax-get-property myxl "ActiveSheet") "Cells"))
(setq cell (vlax-get (vlax-variant-value  (vlax-get-property cells "Item" row column)) 'value))
)

(setq myxl (vlax-get-object "Excel.Application"))
 
(vla-put-visible myXL :vlax-true)
(vlax-put-property myxl 'ScreenUpdating :vlax-true)
(vlax-put-property myXL 'DisplayAlerts :vlax-true)

(setq rows 3)
(setq maxrow (- (cadr end) 2))

(repeat maxrow
(setq MH (getcell2 rows 2)
  X (getcell2 rows 3)
  Y (getcell2 rows 4)
  d1 (getcell2 rows 5)
  d2 (getcell2 rows 6)
)

(setq scx (/ d1 1000000.) scY (/ d2 1000.))

(command "-insert" mh (list x y) scx scy 0.0)

(setq rows (1+ rows))
)

(princ)
)

 

Re thickness most manholes if concrete are like 75-150 thick so just having 2 rectangs as block is fine. This still graphically indicates a wall thickness. The pit schedule implies the thickness.

0 Likes