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