autolisp

autolisp

sudarsann
Advocate Advocate
752 Views
7 Replies
Message 1 of 8

autolisp

sudarsann
Advocate
Advocate

A Notepad having the many Dimensions of rectangles in the format of : "Length Width Height Desc".
(Ex: 36 24 65 aaaaa
48 30 72 bbbbb
)
the data having "tab space" between length, width, height and desc
I need to place the rectangles using length and width dimensons and also place the text inside the rectangles like
L: 36
W: 24
H: 65
Desc:aaaaa
I am trying to get the values individually but after getting 1st tab space value using the syntax (vl-string-search pattern string [start-pos]), I dont know how to get the remaining values of tab spaces.
I need help for solving the above problem?

0 Likes
Accepted solutions (1)
753 Views
7 Replies
Replies (7)
Message 2 of 8

Kent1Cooper
Consultant
Consultant

Post a small sample of such a file.  I know what a "tab" is, and what a "space" is, but not a "tab space."

 

Rectangles, or rectangular prisms [solid, with Z-axis-direction thickness]?

Kent Cooper, AIA
0 Likes
Message 3 of 8

paullimapa
Mentor
Mentor

One way is to use Lee Macs split string using space character as deliminater function to give you a list then you can extract the items from the list to place into the drawing 

http://www.lee-mac.com/stringtolist.html


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 8

Sea-Haven
Mentor
Mentor

A handy list of key codes.  Key codes (asawicki.info) 

you can also do (ascii (getstring)) will show key number for most common keys, like

, : ; A-Z a-z 0-9

0 Likes
Message 5 of 8

sudarsann
Advocate
Advocate

Mr Kent,

 

Notepad having sample data.

I need rectangles in autocad as shown in sample.png 

 

Thank you

Sudarsan

0 Likes
Message 6 of 8

sudarsann
Advocate
Advocate
In AutoCAD need 2D rectangles and having text LENGTH x WIDTH x HEIGHT x DESCRIPTION inside the rectangles
In Notepad "tab" between LENGTH AND WIDTH and remaining data.
0 Likes
Message 7 of 8

Sea-Haven
Mentor
Mentor

The answer is easy but one more question how do you propose spacing the rectangs, maybe in a long pattern on X axis, or a grid pattern, so for say in a line what is gap ?

0 Likes
Message 8 of 8

komondormrex
Mentor
Mentor
Accepted solution

that's it. draws rectangles in a raw with 10 units gap.

 

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

(defun c:draw_rectangle (/ txt_filename_full txt_id ml_point line_read rectangle_param_list)

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

	(defun string_to_list (input_string delimiter / delimiter_position output_list)
		(while (setq delimiter_position (vl-string-search delimiter input_string 0))
			(setq output_list (append output_list (list (substr input_string 1 delimiter_position)))
				  input_string (substr input_string (+ 2 delimiter_position))
			)
		)
		(append output_list (list input_string))
	)

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

	(defun get_filename (extension / txt_filename)
			(if (type acet-ui-getfile)
					(setq txt_filename (acet-ui-getfile "Enter the name of TXT file"
									     ""
									     extension
									     ""
									     2
							   )
					)
					(setq txt_filename (getfiled "Enter the name of TXT file"
								      ""
								      extension
								      2
							   )
					)
			)
			(if (= "" txt_filename)
				nil
				txt_filename
			)
	)

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

	(defun draw_rectangle (_length _width _height _comment ml_point / rect_llc rect_ruc text_string)
		(setq rect_llc (list (car ml_point) (- (cadr ml_point) (* 0.5 (atof _width))))
		      rect_ruc (list (+ (car ml_point) (atof _length)) (+ (cadr ml_point) (* 0.5 (atof _width))))
		      text_string (strcat _length " x " _width " x " _height " x " _comment)
		)
		(command "_rectang" "_non" rect_llc "_non" rect_ruc)
		(command "_text" "_j" "_mc" (mapcar '* '(0.5 0.5) (mapcar '+ rect_llc rect_ruc)) 2.5 0 text_string "")
	)

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

	(if (and (setq txt_filename_full (get_filename "txt"))
		 (setq txt_id (open txt_filename_full "r"))
	    )
		(progn
			(setq ml_point (getpoint "\nPick left middle point for starting rectangle: "))
			(read-line txt_id)
			(while (setq line_read (read-line txt_id))
				(setq rectangle_param_list (string_to_list line_read "\t"))
				(draw_rectangle (car rectangle_param_list)
						(cadr rectangle_param_list)
						(caddr rectangle_param_list)
						(cadddr rectangle_param_list)
						ml_point
				)
				(setq ml_point (list (+ (car ml_point) (atof (car rectangle_param_list)) 10) (cadr ml_point)))
			)
			(close txt_id)
			(princ (strcat "File \"" txt_filename_full "\" has been read"))
		)
	)
	(princ)
)

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

 

 

0 Likes