Creat rectangel and insert with defrent insertion point

Creat rectangel and insert with defrent insertion point

abdulellah.alattab
Advocate Advocate
531 Views
20 Replies
Message 1 of 21

Creat rectangel and insert with defrent insertion point

abdulellah.alattab
Advocate
Advocate

Hi - every one , i need help to creat lisp follow this steps 

1- ask user about rectanle length .(x direction )

2- ask user about rectanle width ( y direction ) 

3 - ask user about insertion point like JUSTIFY POINT IN  DTEXT COMMAND ( center -center left - center right -  bottom left -bottom center -  bottom right - top left - top center - top right ) 

4- ask user to click to draw  rectangle at insertion point 

5- ask user to define rotation angle 

 

Thank you  for all

0 Likes
Accepted solutions (3)
532 Views
20 Replies
Replies (20)
Message 21 of 21

Sea-Haven
Mentor
Mentor

Give this a try.

; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/creat-rectangel-and-insert-with-defrent-insertion-point/td-p/13819504
; custom DCL example by AlanH Sept 2025

(defun c:rectjust ( / ans butlst fo y x val dcl_id fname pt ang len ht)

(defun butval ( / X l but)
(setq x 0)
(repeat (length butlst)
    (setq l (strcat "Rb" (rtos x 2 0)))
    (if  (= (get_tile l) "1" )
        (setq but x)
    )
    (setq x (+ x 1))
)
(setq ans (nth but butlst))
(princ)
)

(setq butlst (list "TL" "TM" "TR" "ML" "MC" "MR" "BL" "BM" "BR"))

(setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))
(write-line  "RECTANGINSPT : dialog {" fo)
(write-line  (strcat "	label = " "\"Please enter & choose \"" " ;" ) fo)
(write-line " : column {" fo)
(write-line " width = 30 ;" fo)
(setq y 0)
(foreach val (list "Length" "Height" "Angle")
 (write-line ": edit_box {" fo)
 (setq keynum (strcat "key" (rtos y 2 0)))
 (write-line (strcat " key = " keynum " ;") fo)
 (write-line (strcat " label = " (chr 34) val (chr 34) " ;") fo)
 (write-line (strcat " edit_width = 5 ;") fo)
 (write-line (strcat " edit_limit = 4 ;") fo)
 (write-line " is_enabled = true ;" fo)
 (write-line " allow_accept=true ;" fo)
 (write-line " }" fo)
 (setq y (1+ y))
)
(write-line "spacer_1 ;" fo)
(setq x 0)
(repeat 3
(write-line " : row {" fo)
 (repeat 3 
  (write-line "	: radio_button	{" fo)
  (write-line  (strcat "key = "  (chr 34) "Rb" (rtos x 2 0)  (chr 34) " ;") fo)
  (write-line  (strcat "label = " (chr 34) (nth x  butlst) (chr 34) " ;") fo)
  (write-line "	}" fo)
  (setq x (1+ x))
 )
(write-line "	}" fo)
(write-line "spacer_1 ;" fo)
)
(write-line "spacer_1 ;" fo)
(write-line "	}" fo)
(write-line "spacer_1 ;" fo)
(write-line "	ok_cancel;" fo)
(write-line "	}" fo)
(close fo)

(setq dcl_id (load_dialog fname))
(if (not (new_dialog "RECTANGINSPT" dcl_id) )
 (exit)
)
(action_tile "accept" "(setq len (atof (get_tile \"key0\")))(setq ht (atof (get_tile \"key1\")))(setq ang (atof (get_tile \"key2\")))(butval)(done_dialog)")
(action_tile "cancel" "(done_dialog)(exit)")
(start_dialog)
(unload_dialog dcl_id)

(vl-file-delete fname)

(setq pt (getpoint "\nPick point for rectang "))
(if (< ang 0.0)
(setq ang  (/ (* (angle pt (getpoint pt "\nPick second point for angle ")) 180.0) pi))
)

(command "rectang" Pt (mapcar '+ pt (list len ht 0.0)))
(cond 
((= ans "TL")(command "move" (entlast) "" '(0 0 0) (list 0 ht 0)))
((= ans "ML")(command "move" (entlast) "" '(0 0 0) (list 0 (/ ht 2.) 0)))
((= ans "BL")(princ))

((= ans "TM")(command "move" (entlast) "" '(0 0 0) (list (/ len -2.) ht 0)))
((= ans "MC")(command "move" (entlast) "" '(0 0 0) (list (/ len -2.) (/ ht -2.) 0)))
((= ans "BM")(command "move" (entlast) "" '(0 0 0) (list (/ len 2.) 0. 0)))

((= ans "TR")(command "move" (entlast) "" '(0 0 0) (list len ht 0)))
((= ans "TM")(command "move" (entlast) "" '(0 0 0) (list len  (/ ht 2.) 0)))
((= ans "BR")(command "move" (entlast) "" '(0 0 0) (list len 0 0)))
)

(setvar 'angdir 0)
(setvar 'aunits 0)

(command "Rotate" (entlast) "" pt ang )
(princ)
)
(c:rectjust)

 

There is a bug in the code as its 3 rows not a 3x3 radio buttons. There is a function "radio_cluster" but if any body knows how to make it work would be appreciated. The only other way is to use a 3x3 image dcl. 

0 Likes