Creat rectangel and insert with defrent insertion point

Creat rectangel and insert with defrent insertion point

abdulellah.alattab
Advocate Advocate
475 Views
19 Replies
Message 1 of 20

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)
476 Views
19 Replies
Replies (19)
Message 2 of 20

Kent1Cooper
Consultant
Consultant

That looked like a potentially useful function [I have had a command for a while to draw a Rectangle about a specified mid-point, but the other justification options seemed worthwhile], so I came up with the attached RectJust.lsp with its eponymous command name.  See the comments at the top.

Note that it does one thing a little differently than in your description.  It doesn't ask for an "insertion point" in isolation, but it draws a rectangle in mid-screen based on the specified dimensions and justification, and then you MOVE it with the "insertion point" as the base point, so you see it drawn as you drag it into position.

Kent Cooper, AIA
0 Likes
Message 3 of 20

abdulellah.alattab
Advocate
Advocate

Thank you, sir, but is it possible to modify it to achieve the task i requested? I believe that it is important to have an auto-lisp to do the task ,civil enginers use it every day to draw  ( columns and footings ) , 

0 Likes
Message 4 of 20

Moshe-A
Mentor
Mentor
Accepted solution

@abdulellah.alattab 

 

check my version 😀

 

enjoy

Moshe

 

Message 5 of 20

abdulellah.alattab
Advocate
Advocate

Flawless ✌️

0 Likes
Message 6 of 20

abdulellah.alattab
Advocate
Advocate

I modified it a bit, by adding horizontal and vertical displacement for the rectangle after insertion and adding the option to fill or leave it empty.

0 Likes
Message 7 of 20

abdulellah.alattab
Advocate
Advocate

Excuse me, I'm not that skilled at Autodesk. I hope you review the sent file. I also want the selection of the capture position before the angle to be a mental matter, nothing more.

0 Likes
Message 8 of 20

Moshe-A
Mentor
Mentor
Accepted solution

@abdulellah.alattabhi,

 

mmmm...i do not understand something, you have a Flawless lisp that insert a rectangle at [TL/TC/TL/ML/MC/MR/BL/BC/BR]

and after that you still need moving it? why not use standard RECTANGLE command instead than move it than hatch it?

 

Moshe

 

0 Likes
Message 9 of 20

abdulellah.alattab
Advocate
Advocate

Yes, but I would like to add an option to move the rectangle away from the insertion point after drawing it at a horizontal and vertical distance specified by the user, also adding an option as to whether the user wants to fill the rectangle with a solid hatch or wants to leave it empty , can you correct lisp

0 Likes
Message 10 of 20

Sea-Haven
Mentor
Mentor

I tried your code a couple of suggestions, add a osnap off (setvar 'osmode 0) if osnap is set and your at a zoomed out scale it will draw what appears to be a line as the ends will snap together. It also failed to run a second time after I turned off osnap. so something not resetting correctly. I think its your use of def repeatedly you need to set the def to say def1 def2 def3 etc you are mixing strings and reals in your code.

: (LOAD "C:/Users/seaha/Downloads/crec-extra.lsp")C:CREC
: CREC
Rectangle length: <20>: 
Rectangle width: <10>: 

; ----- LISP : Call Stack -----
; [0]...C:CREC
; [1].....ASKJUSTIFY <<--
;
; ----- Error around expression -----
; (STRCAT "
Justify options [TL/TC/TL/ML/MC/MR/BL/BC/BR] <" DEF ">: ")
;
; error : bad argument type <0.0> ; expected <STRING> at [strcat]

 

Re input I would look at a dcl, you can have edit boxes for values and say radio buttons for the justification. A good task to learn about custom dcl's. I have something for the 9 radio buttons to find which one has been ticked on.

SeaHaven_0-1758585696234.png

 

0 Likes
Message 11 of 20

abdulellah.alattab
Advocate
Advocate

Thank you for all , The problem with Mr. Kent's version is that it is mentally annoying to have a rubber line in the middle of the screen and I was comfortable with the idea of ​​rotating with the mouse movement, and the problem with Mr. sae-haven's version is that it is always related to pop-up windows (an additional file to the program file), the idea of ​​merging with the vlax file is always comfortable, all I want now is for Mr. Moshe to kindly add the possibility of adding displacement values ​​and also the possibility of filling the shape with a solid color, I submitted a crec-extra proposal but it has problems

0 Likes
Message 12 of 20

Sea-Haven
Mentor
Mentor

"(an additional file to the program file)" No you can write a dcl on the fly from within a lisp file. I actually recommend doing just that so you don't have a separate DCl file.

 

In simple terms you use something like this.

(setq fo (open (setq fname (vl-filename-mktemp "" "" ".dcl")) "w"))
(write-line "ddgetvalAH2col : dialog {" fo)
(write-line (strcat "	label =" (chr 34) heading (chr 34) " ;") fo)
(write-line "	: row	{" fo)
(write-line " : boxed_column {" fo)
...... rest of dcl
(write-line "spacer_1 ;" fo)
(write-line "ok_cancel;}" fo)
(close fo)
(setq dcl_id (load_dialog fname))
(if (not (new_dialog "ddgetvalAH2col" dcl_id))
(exit)
)

 There is also a DCL 2 lisp by RLX that converts an existing dcl into Lisp code.

 

I will try to do the write dcl code for you.

0 Likes
Message 13 of 20

paullimapa
Mentor
Mentor
Accepted solution

I made the following changes to make your crec-extra.lsp work:

Added askdist0 function to accommodate for Xdist & Ydist move values that accepts 0 which askdist function does not:

; accepts 0 value as distance
 (defun askdist0 (msg def / ask)
  (if (not (setq ask (getdist (strcat "\n" msg ": <" (rtos def) ">: "))))
   (setq ask def)
   (setq def ask)
  ); if
 ); askdist0

Need to use @Moshe-A original code with the same positioning of user variables and add the new ones:

; use the original line of code which positions rotation before justify and add Xdist, Ydist, strdcdef
;                      0                 1               2                  3                  4                5              6
 (setq MA:DATAPROP '(("xlength" . 1.0) ("ywidth" . 0.4) ("rotation" . 0.0) ("justify" . "BL") ("Xdist" . 0.1) ("Ydist" . 0.1) ("strdcdef" . "with.Fill")))
; below line of code incorrectly positions justfy before rotation
; (setq MA:DATAPROP '(("xlength" . 1.0) ("ywidth" . 0.4) ("justify" . "BL") ("rotation" . 0.0)))
 (if (and
       (setq xlength  (askdist  "Rectangle length" (vlax-ldata-get MA:DICTAPPNAME (car (nth 0 MA:DATAPROP)))))
       (setq ywidth   (askdist  "Rectangle width"  (vlax-ldata-get MA:DICTAPPNAME (car (nth 1 MA:DATAPROP)))))
; order of request can be switched but the nth # needs to remain the same as the original code
;       (setq justify  (askjustify                  (vlax-ldata-get MA:DICTAPPNAME (car (nth 2 MA:DATAPROP)))))
;       (setq rotation (askangle "Rotation angle"   (vlax-ldata-get MA:DICTAPPNAME (car (nth 3 MA:DATAPROP)))))
       (setq justify  (askjustify                  (vlax-ldata-get MA:DICTAPPNAME (car (nth 3 MA:DATAPROP)))))
       (setq rotation (askangle "Rotation angle"   (vlax-ldata-get MA:DICTAPPNAME (car (nth 2 MA:DATAPROP)))))
       (setq p0 (getpoint "\nSpecify insertion point: "))
     )

After Pline is drawn then run the askdist0 function instead of repeating similar code for X & Y distance:

   (command "._pline" p1 "_width" 0 0 p2 p3 p4 "_close")
; get the added saved input as default
       (setq Xdist (askdist0  "Enter distance to move in X" (vlax-ldata-get MA:DICTAPPNAME (car (nth 4 MA:DATAPROP)))))
       (setq Ydist (askdist0  "Enter distance to move in Y" (vlax-ldata-get MA:DICTAPPNAME (car (nth 5 MA:DATAPROP)))))
       (setq strdcdef (vlax-ldata-get MA:DICTAPPNAME (car (nth 6 MA:DATAPROP))))
;
;==============================; Prompt user for X distance ;==============================
;   (if (null Xdist*)
;       (setq Xdist* 0.1)
;   )
;   (initget 64)
;   (if (setq _tmp (getdist (strcat "\nEnter distance to move in X: ? : <" (rtos Xdist* 2 4) ">: ")))
;       (setq Xdist* _tmp)
;   )
;==============================; Prompt user for Y distance ;==============================
;   (if (null Ydist*)
;       (setq Ydist* 0.1)
;   )
;   (initget 64)
;   (if (setq __tmp (getdist (strcat "\nEnter distance to move in Y: ? : <" (rtos Ydist* 2 4) ">: ")))
;       (setq Ydist* __tmp)
;   )

Only do a move if last object ss & Xdist & Ydist (avoid using asterisk character * because has problems with saving as user data dictionary):

   (setq ss (ssget "L")) ; Selects the last object created
   (if (and ss Xdist Ydist) ; there's a last object and default Xdist & Ydist
     ; ss
     (progn
       (setq obj (vlax-ename->vla-object (ssname ss 0))) ; Get the VLA object
       (setq pt1 p1) ; Get the insertion point
;       (setq pt2 (list (+ (car pt1) Xdist*) (+ (cadr pt1) Ydist*) (caddr pt1))) ; Calculate new point
;      use variables without asterisk
       (setq pt2 (list (+ (car pt1) Xdist) (+ (cadr pt1) Ydist) (caddr pt1))) ; Calculate new point
       (command "._MOVE" ss "" pt1 pt2) ; Execute the MOVE command
     )
   )

Modified to accommodate for default on hatch fill:

    (initget "with.Fill Without.Fill") 
;   (setq strdc(getkword "\nSolid Fill [with.Fill/Without.Fill]? : ")) 
; include default in prompt
   (setq strdc (getkword (strcat "\nSolid Fill [with.Fill/Without.Fill]? <" strdcdef ">: "))
   )
; if enter then use default else set default
   (if (not strdc)(setq strdc strdcdef)(setq strdcdef strdc))
;

Save user variable with added inputs:

   ; save user input
   (vl-every
     (function
       (lambda (prop var)
        (vlax-ldata-put MA:DICTAPPNAME (car prop) var)
       ); lambda
     ); function
;     MA:DATAPROP (list xlength ywidth rotation justify) 
; include the added inputs 
     MA:DATAPROP (list xlength ywidth rotation justify Xdist Ydist strdcdef) 
   ); vl-every

PS: 

I added function (ma:dictapp_delete) at the beginning of the file in case you want to remove the saved user data from the dwg:

; (ma:dictapp_delete) deletes previously saved user data dictionary 
(defun ma:dictapp_delete (/ MA:DICTAPPNAME MA:DATAPROP)
 (setq MA:DICTAPPNAME "crec.lsp-by-Moshe-A-SEP2025")
 (setq MA:DATAPROP '(("xlength" . 1.0) ("ywidth" . 0.4) ("rotation" . 0.0) ("justify" . "BL") ("Xdist" . 0.1) ("Ydist" . 0.1) ("strdcdef" . "with.Fill")))
; (setq MA:DATAPROP '(("xlength" . 1.0) ("ywidth" . 0.4) ("rotation" . 0.0) ("justify" . "BL")))
 (if (vlax-ldata-list MA:DICTAPPNAME)
  (progn
   (foreach prop MA:DATAPROP
    (vlax-ldata-delete MA:DICTAPPNAME (car prop))
   )
  (princ (strcat "\nRemoved Data Set with Dictionary Named: [" MA:DICTAPPNAME "]"))
  ) 
  (princ (strcat "\nNo Data Set with Dictionary Named: [" MA:DICTAPPNAME "]"))
 )
 (princ)
) ; defun

 


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

Sea-Haven
Mentor
Mentor

A front end.

SeaHaven_0-1758611655089.png

Has one bug fixing but am image of lisp code for dcl.

SeaHaven_1-1758611708363.png

 

0 Likes
Message 15 of 20

Moshe-A
Mentor
Mentor

@abdulellah.alattab ,

 

ok check the fix

 

 

0 Likes
Message 16 of 20

Kent1Cooper
Consultant
Consultant

@abdulellah.alattab wrote:

.... The problem with Mr. Kent's version is that it is mentally annoying to have a rubber line in the middle of the screen ....


For that aspect of it, attached is RectJust2.lsp, which does not have the annoying rubber-band line or source location showing, but still lets you see the rectangle drawn at the specified size and justification as you go to place its "insertion point" where you want it.

If you like that part of it, I can add the post-insertion Move option and the fill option.

[DRAGMODE must be set to AUTO.  If you don't always have it that way, it can be built into the command.]

Kent Cooper, AIA
0 Likes
Message 17 of 20

Kent1Cooper
Consultant
Consultant

@abdulellah.alattab wrote:

... I was comfortable with the idea of ​​rotating with the mouse movement, .... add the possibility of adding displacement values ​​.....


For that part, should the displacement values be asked for before or after the rotation?  I expect if the rotation is anything other than orthogonal, subsequent raw X and Y displacement values will be meaningless, but they should be relative to the angle of the rotation, not to the X and Y axes.  But maybe you only ever do things orthogonally.

Kent Cooper, AIA
0 Likes
Message 18 of 20

komondormrex
Mentor
Mentor

hey,

try this different one.

komondormrex_0-1758653329768.png

 

 

0 Likes
Message 19 of 20

abdulellah.alattab
Advocate
Advocate

Thank you very much to everyone, you are all creative and I don't think anyone can find anyone like you; you all succeeded in achieving the main goal; but to be honest I am more satisfied with Mr. Moshe's program, and to be honest with every task I find him standing by my side and he is not selective in who he can get his help

0 Likes
Message 20 of 20

Sea-Haven
Mentor
Mentor

Just a comment about using the front end DCL, and using @Kent1Cooper idea of setting an angle by using a mouse. In the DCl you could just say use a -ve angle to imply use mouse. The other thing in the DCL which I did not do is preset the values for length, Height and Angle, then next time its ran it will use the last values entered as defaults. So just click OK if same wanted again.

0 Likes