Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation since 08/13/2025 in all areas

  1. little background on how DWG drawings work or how I understand. When you create or modify anything in a drawing it puts it at the end of drawing list. that is why you can select the last thing with (entlast) The blocks you are inserting is a made up of entity's and when you explode the block its gone but it's entity's are left in the drawing. even if its only one item its now under a different entity name. Your join command is saying join block 1 2 3 4 but you exploded them. you have to build another selection set of those entity's to join. so you create a place holder in the Drawing list with LastEnt insert and explode your block. then with the while its basically saying anything after this point in the list add to selection set SS. then pass the SS to the join command. (setq SS (ssadd)) (setq LastEnt (entlast)) (command "-insert" "*Infil_HL" '(0.0 0.0 0.0) "" "" "") (command "-insert" "*blk2" '(0.0 0.0 0.0) "" "" "") ;ent2 (command "-insert" "*blk3" '(0.0 0.0 0.0) "" "" "") ;ent3 (command "-insert" "*blk4" '(0.0 0.0 0.0) "" "" "") ;ent4 (while (setq LastEnt (entnext LastEnt)) (ssadd LastEnt SS) ) (command "_join" SS) -edit adding * infront of the block name AutoCAD inserts and immediately explodes it in one step.
    3 points
  2. Added a few options since the first version for those who like to pimp things. Same restrictons as b4 , text display is very basic , keep them short or use wider buttons , background fill is fine for standard drawings sizes , but very large units can take some time so added option in setup dialog to tweak fill percentage. Very small drawings / zoom factor also impacts fill. But then if I have to live with these limits of lisp , so do you. Very satisfying I can tell you. App can be started with c:GrM (Graphic Menu) , you probably want to fill the app list with your favorite lisp routines and app still works by loading 'MyLisp' and then assumes it starts with (c:MyLisp). Haven't tested it on a virgin system yet so hope it runs on first use. App should display toolbar with default settings and enters a grread loop , there you can select button or press S for setup , O to change orientation (left / right / top / center / bottom) and also do some zooming, oh just read the freaking command prompt. One button(key) isn't listed , D , that was for debugging. Just left it there for those who get off pressing buttons. In setup dialog top left will show if debug mode is active. You probably use it once in you life but it could be a nice template for future apps. You also can directly go to setup dialog with (C:GrMS) Well I could go on but what be the fun in that. If I did my work app should explain itself. My reason for making this is that for every job I do I make my tools on the fly and having to edit / recompile my autocad toolbar every freaking time started to irritate me and now I just pimp my own toolbar / app-list (you can save multiple toolbar data files in the app-list dialog) Well , as you should know by now : hope you have fun or else bite me (or your mother in law) Oh , if you choose center orientation I would advise to use the fixed width / height option ... or not , I'm not your mommie ...daddy? ... maybe... 2025-09-07 : updated a couple of first use issues & added 'hotkey' [C]olor to cycle different colors GrM.lsp
    3 points
  3. Try this. Not sure what you want for attribute values. Can ask once then will be added correctly. Maybe 3 getstring after pick pline. ; https://www.cadtutor.net/forum/topic/98666-block-insert-lisp/ ; arrows by AlanH Aug 2025 (defun c:wow ( / plent co-ord isclosed x obj ang) ;; Set Dynamic Block Property Value - Lee Mac ;; Modifies the value of a Dynamic Block property (if present) ;; blk - [vla] VLA Dynamic Block Reference object ;; prp - [str] Dynamic Block property name (case-insensitive) ;; val - [any] New value for property ;; Returns: [any] New value if successful, else nil (defun LM:setdynpropvalue ( blk prp val ) (setq prp (strcase prp)) (vl-some '(lambda ( K ) (if (= prp (strcase (vla-get-propertyname k))) (progn (vla-put-value K (vlax-make-variant val (vlax-variant-type (vla-get-value K)))) (cond (val) (t)) ) ) ) (vlax-invoke blk 'getdynamicblockproperties) ) ) (setq plent (entsel "\nPick pline")) (setq co-ord (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget (car plent))))) (setq isclosed (cdr (assoc 70 (entget (car plent))))) (setq x 0) (command "-insert" "Stalb" (nth x co-ord) 1 1 0 "" "" "") (setq obj (vlax-ename->vla-object (entlast))) (setq ang (angle (nth x co-ord) (nth (+ x 1) co-ord))) (LM:setdynpropvalue obj "Angel_1" ang) (if (= isclosed 1) (progn (setq ang (angle (nth 0 co-ord) (last co-ord) )) (LM:setdynpropvalue obj "Angel_2" ang) ) ) (repeat (- (length co-ord) 2) (command "-insert" "Stalb" (nth (setq x (1+ x)) co-ord) 1 1 0 "" "" "") (setq obj (vlax-ename->vla-object (entlast))) (setq ang (angle (nth x co-ord) (nth (+ x 1) co-ord))) (LM:setdynpropvalue obj "Angel_1" ang) (setq ang (angle (nth x co-ord) (nth (- x 1) co-ord))) (LM:setdynpropvalue obj "Angel_2" ang) ) (command "-insert" "Stalb" (nth (setq x (1+ x)) co-ord) 1 1 0 "" "" "") (setq obj (vlax-ename->vla-object (entlast))) (setq ang (angle (nth x co-ord) (nth (- x 1) co-ord))) (LM:setdynpropvalue obj "Angel_2" ang) (if (= isclosed 1) (progn (setq ang (angle (nth x co-ord) (nth 0 co-ord) )) (LM:setdynpropvalue obj "Angel_1" ang) ) ) (princ) )
    3 points
  4. Notepad ++ can set the save mode it has numerous options including Ansi and UTF-8.
    3 points
  5. (vl-load-com) (defun c:FOO (/ *error* acDoc ss pt y item data blocks) (defun *error* (msg) (if ss (vla-delete ss)) (if acDoc (vla-endundomark acDoc)) (cond ((not msg)) ; Normal exit ((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit) ((princ (strcat "\n** Error: " msg " ** "))) ; Fatal error, display it ) (princ) ) (if (and (ssget "_:L" '((0 . "INSERT"))) (setq d (getreal "\nEnter Block distance: ")) ) (progn (vla-startundomark (setq acDoc (vla-get-activedocument (vlax-get-acad-object))) ) (vlax-for x (setq ss (vla-get-activeselectionset acDoc)) (setq pt (vlax-get x 'insertionpoint)) (if (setq item (assoc (setq y (cadr pt)) data)) (setq data (subst (cons (car item) (append (cdr item) (list x))) item data) ) (setq data (cons (cons y (list x)) data)) ) ) (if data (foreach item data (setq blocks (vl-sort (cdr item) (function (lambda (a b) (< (car (vlax-get a 'insertionpoint)) (car (vlax-get b 'insertionpoint)) ) ) ) ) ) (setq pt (vlax-get (car blocks) 'insertionpoint)) (foreach block (cdr blocks) (vla-move block (vlax-3d-point (vlax-get block 'insertionpoint)) (vlax-3d-point (setq pt (polar pt 0.0 d))) ) ) ) ) ) ) (*error* nil) ) This works for each group of Blocks at a given Y level, based on the lowest X position in a given row as starting point.
    2 points
  6. try this : (defun Fill_Toolbar_Background (x- y- x+ y+ c / y vws bgf-fac delta-y) (setq y y- vws (getvar "viewsize") bgf-fac (/ 0.1 (/ (atof GrM-Button-Background-Fill) 100.0))) (setq delta-y (/ vws 1000.0)) (while (<= y y+)(grdraw (list x- y)(list x+ y) c)(setq y (+ y (* delta-y bgf-fac (/ vws start-viewsize)))))) did very little testing though... oh , about the 'duplicated' background fill , although there are two and the first could (should) have been deleted, it doesn't matter because lisp only evaluates the last version. Every new definition overwites the previous one.
    2 points
  7. you're absolutely right GLAVCVS , took out too much when I cleaned out some obsolete code. Usually I forget the 'void' function but paid special attention I didn't this time. At the expense of rlx_sf this time so it seems. Have done a few changes , renamed orientation to justification (change with letter j / J while menu is displayed) , change (background) color with b (or B) and with keys c / C & r / R decrease / increase columns & rows. Hope all the bugs are dead now... ;;; GrM - Graphic Menu , Rlx sep '25 ;;; Known limitations : keep app names short , use fixed width & height not really useful, probably gonna remove that ;;; option was intended to be able to have like a 4x4 in center of screen and not fill entire screen... maybe later.. ;;; last update : 2025-09-04 - cleaned up & connected dialog with subroutines ;;; : 2025-09-05 - did some further t&c (tweaking & cleaning) ;;; : 2025-09-06 - time for fieldtesting ;;; : 2025-09-07 - fixed a couple of 1st use issues ;;; : 2025-09-10 - included rlx_sf (defun c:GrMS ( / ;;; globals regkey regvar reg-var-list old-err screen-width screen-height GrM-NoF-Columns GrM-NoF-Rows start-toolbar cell-height cell-width x y cell-number app-list corner start-viewsize app default-button-width default-button-height ;;; test variables so I can run program without dialog tst-NoF-Rows tst-NoF-Columns tst-cell-height tst-cell-width ;;; dimscreen : view x-/y-/x+/y+/height/width/center vx- vy- vx+ vy+ vh vw vc ;;; toolbar corner points tb-x- tb-x+ tb-y- tb-y+ tb-ll tb-ul tb-lr tb-ur tb-dX tb-dY ;;; setup dialog variables setup-dialog-fn setup-dialog-fp setup-dialog-dcl setup-dialog-tl setup-dialog-rd ;;; registry GrM-NoF-Rows ;;; Number of rows in menu , left-right (vertical) Justification GrM-NoF-Columns ;;; Number of columns in menu , left-right (vertical) Justification GrM-Button-Background-Fill ;;; 100(%) means 1 vector line per unit GrM-Button-Width-Height-Ratio ;;; width-ratio 2 means cell width is 2 x cell height GrM-Max-Button-Width-Height-Ratio ;;; set on 3 (width is max 3 times button height) GrM-Max-Button-Background-Fill ;;; 0-100 (%) in steps of 10 GrM-Use-Fixed-Cell-Height ;;; boole , "0" = nope , "1" = jip GrM-Cell-Height ;;; 10 means screen width / 10 GrM-Use-Fixed-Cell-Width ;;; boole , "0" = nope , "1" = jip GrM-Cell-Width ;;; 10 means screen height / 10 GrM-Frame-Color ;;; default is "7" (white) GrM-Text-Color ;;; default is "7" (white) GrM-Background-Color ;;; colors like "8" (gray) , "143" (dirty blue) ;;; options GrM-Max-Columns GrM-Max-Rows ;;; Limmits on number of columns & row GrM-Follow-Justification GrM-Sort-On-Load ;;; Swap #rows - #cols when switching Left/Right - Top/Center/Bottom GrM-Text-Size-Factor ;;; usually 9 or 10 GrM-Toolbar-Justification ;;; left/right/top/bottom/center GrM-App-List-File GrM-Debug-Mode ;;; if "1" function inspect displays variables & values ) ;;; initialyze environment (set_reg_var_list) (princ "\nstart GrM ... ") (GrM_Init) (princ "start setup dialog\n") ;;; (chk_reg_vars) ;;; debug on;y (GrM_Setup_Dialog_Start) (GrM_Exit) (princ) ) (defun c:GrM ( / regkey regvar reg-var-list old-err screen-width screen-height GrM-NoF-Columns GrM-NoF-Rows cell-height cell-width x y cell-number app-list corner vx- vy- vx+ vy+ vh vw vc tb-x- tb-x+ tb-y- tb-y+ tb-ll tb-ul tb-lr tb-ur tb-dX tb-dY setup-dialog-fn setup-dialog-fp setup-dialog-dcl setup-dialog-tl setup-dialog-rd app default-button-width default-button-height GrM-NoF-Rows GrM-NoF-Columns GrM-Button-Background-Fill GrM-Button-Width-Height-Ratio GrM-Max-Button-Width-Height-Ratio GrM-Max-Button-Background-Fill GrM-Use-Fixed-Cell-Height GrM-Cell-Height GrM-Use-Fixed-Cell-Width GrM-Cell-Width GrM-Frame-Color GrM-Text-Color GrM-Background-Color GrM-Max-Columns GrM-Max-Rows GrM-Follow-Justification GrM-Sort-On-Load GrM-Text-Size-Factor GrM-Toolbar-Justification GrM-App-List-File GrM-Debug-Mode) ;;; initialyze environment (set_reg_var_list) (princ "\nstart GrM ... ") (GrM_Init) (princ "start toolbar\n") ;;; (chk_reg_vars) ;;; debug only (GrM_Draw_Toolbar) (if (eq GrM-Debug-Mode "1") (inspect (list 'vh 'vw 'GrM-Toolbar-Justification 'GrM-NoF-Columns 'GrM-NoF-Rows 'GrM-Use-Fixed-Cell-Height 'GrM-Cell-Height 'cell-Height 'GrM-Use-Fixed-Cell-Width 'GrM-Cell-Width 'cell-width 'GrM-Frame-Color 'GrM-Text-Color 'GrM-Background-Color ) ) ) ;;; get user input (GrM_Start_GrRead) (GrM_Exit) ;;; launch app (if app (GrM_Start_App app)) ) (defun set_reg_var_list () (setq reg-var-list (list 'GrM-NoF-Rows 'GrM-NoF-Columns 'GrM-Button-Background-Fill 'GrM-Button-Width-Height-Ratio 'GrM-Max-Button-Width-Height-Ratio 'GrM-Max-Button-Background-Fill 'GrM-Use-Fixed-Cell-Height 'GrM-Cell-Height 'GrM-Use-Fixed-Cell-Width 'GrM-Cell-Width 'GrM-Frame-Color 'GrM-Text-Color 'GrM-Background-Color 'GrM-Max-Columns 'GrM-Max-Rows 'GrM-Follow-Justification 'GrM-Sort-On-Load 'GrM-Text-Size-Factor 'GrM-Toolbar-Justification 'GrM-App-List-File 'GrM-Debug-Mode ) ) ) (defun GrM_Init () ;;; error handler (setq old-err *error* *error* GrM_Err) ;;; setup default data list (unless it exists) (create_default_data_file "c:\\temp\\GrM-Rlx.dat") ;;; init registry variables (InitDefaultRegistrySettings)(ReadSettingsFromRegistry) ;;; record viewsize at session begin (setq start-viewsize (getvar "viewsize")) ;;; get app-list if any (GrM_Preload_App_List) ;;; fixed button height / width is viewsize / factor (default = 12) (setq default-button-height (/ (getvar "VIEWSIZE") 10) default-button-width (* default-button-height 2.0)) ) (defun GrM_Err ($s) (princ (strcat "\n\n\n" $s))(GrM_Exit)(setq *error* old-err)(gc)(princ)) (defun GrM_Exit () ;;; dialog (if (not (null setup-dialog-dcl))(unload_dialog setup-dialog-dcl)) (if (not (null setup-dialog-fp))(close setup-dialog-fp)) (if (and (not (null setup-dialog-fn))(findfile setup-dialog-fn))(vl-file-delete setup-dialog-fn)) ;;; flush cache (redraw)(gc)(terpri)(princ "\r\n")(princ) ) ;;; --- Registry Settings ------------------------------- Begin Registry Settings ------------------------------- Registry Settings --- ;;; (defun InitDefaultRegistrySettings () (record "InitDefaultRegistrySettings") (setq regkey "HKEY_CURRENT_USER\\SOFTWARE\\GrM\\") ;;; regkeys must be strings ;;; ("variable name" "default value") (setq regvar '( ("GrM-NoF-Rows" "10") ;;; Number of rows in menu , left-right (vertical) Justification ("GrM-NoF-Columns" "1") ;;; Number of columns in menu , left-right (vertical) Justification ("GrM-Button-Background-Fill" "100") ;;; 100(%) means 1 vector line per unit ("GrM-Max-Button-Background-Fill" "100") ;;; value between 10-100 (%) in steps of 10 ("GrM-Button-Width-Height-Ratio" "2") ;;; width-ratio 2 means cell width is 2 x cell height ("GrM-Max-Button-Width-Height-Ratio" "3") ;;; limit on how many times the height the width of the button can be. ("GrM-Use-Fixed-Cell-Height" "0") ;;; boole , "0" = nope , "1" = jip ("GrM-Cell-Height" "") ;;; 10 means screen width / 10 ("GrM-Use-Fixed-Cell-Width" "0") ;;; boole , "0" = nope , "1" = jip ("GrM-Cell-Width" "") ;;; 10 means screen height / 10 ("GrM-Frame-Color" "7") ;;; default is "7" (white) ("GrM-Text-Color" "7") ;;; default is "7" (white) ("GrM-Background-Color" "8") ;;; colors like "8" (gray) , "143" (dirty blue) ("GrM-Max-Columns" "10") ;;; Limmits on number of columns ("GrM-Max-Rows" "10") ;;; Limmits on number of rows ("GrM-Follow-Justification" "1") ;;; Swap #rows - #cols when swapping Left/Right - Top/Center/Bottom ("GrM-Sort-On-Load" "1") ;;; Sort app-list upon load ("GrM-Text-Size-Factor" "9") ("GrM-Toolbar-Justification" "left") ;;; left/right/top/bottom/center ("GrM-App-List-File" "c:\\temp\\GrM-Rlx.dat") ("GrM-Debug-Mode" "0") ;;; hidden image button &d toggles dubug ) ) (mapcar '(lambda (x)(set (read (car x)) (cadr x))) regVar) ) (defun ReadSettingsFromRegistry () (record "ReadSettingsFromRegistry") (mapcar '(lambda (x / n v) (if (setq v (vl-registry-read regkey (setq n (car x)))) (set (read n) v) (vl-registry-write regkey n (cadr x)))) regvar)) (defun WriteSettingsToRegistry () (record "WriteSettingsToRegistry") (mapcar '(lambda (x) (vl-registry-write regkey (car x) (eval (read (car x))))) regvar)) ;;; (setq a 1 b t c "") (vl-every 'boundp (list 'a 'b 'c)) -> T ;;; (setq a 1 b nil c "") (vl-every 'boundp (list 'a 'b 'c)) -> nil (defun chk_reg_vars () (if (not (vl-every 'boundp reg-var-list)) (progn (princ "\n * reg var err - attempting to reload *") (gc) (ReadSettingsFromRegistry))) (if (not (vl-every 'boundp l)) (progn (alert " * reg var err - please reload GrM *")(exit))) ) ;;; --- Registry Settings -------------------------------- End Registry Settings -------------------------------- Registry Settings --- ;;; ;;; --- dialog section ----------------------------------- begin dialog section ------------------------------------ dialog section --- ;;; ;;; --- dialog section ----------------------------------- begin dialog section ------------------------------------ dialog section --- ;;; ; SaveDialogData evaluates all vars from %tl and returns them as a list, reset does the opposite (defun Save_Setup_Dialog_Data (%tl) (mapcar '(lambda (x) (eval (car x))) %tl)) (defun Reset_Setup_Dialog_Data (%tl %rd) (mapcar '(lambda (x y) (set (car x) y)) %tl %rd)) (defun Set_Setup_Dialog_Tiles (%tl) (mapcar '(lambda (x / v) (if (eq 'str (type (setq v (eval (car x))))) (set_tile (cadr x) v))) %tl)) (defun Setup_Dialog_Cancel () (Reset_Setup_Dialog_Data setup-dialog-tl setup-dialog-rd) (WriteSettingsToRegistry)) ;;; --- dcl plus-minus block -------------------------------------------------- ;;; _____ ;;; No. Dragons | 1| [ + ] [ - ] ;;; ----- ;;; k = key (will be prexid with eb_ & bt_ / app-list = label / w = edit box width ;;; (dcl_plus_min "rlx" "No. Dragons" "3") ;;; --------------------------------------------------------------------------- (defun dcl_plus_min (k app-list w) (strcat ":row {children_fixed_width=true;" ":text {fixed_width=true;width=10;label=\"" app-list "\";}" ":edit_box {key=\"eb_" k "\";edit_width=" w ";}" ":button {key=\"bt_" k "_plus\";label=\"+\";}" ":button {key=\"bt_" k "_min\";label=\"-\";}spacer;}" ) ) (defun dcl_button_image1 (k app-list) (strcat ":button {fixed_width=true;width=18;key=\"bt_" k "\";label=\"" app-list "\";}" ":image {fixed_width=true;width=4;color=-2;key=\"im_" k "\";}")) (defun GrM_Setup_Dialog_Create ( / f ) (record "GrM_Setup_Dialog_Create") (if (and (setq setup-dialog-fn (vl-filename-mktemp "GrM.dcl")) (setq setup-dialog-fp (open setup-dialog-fn "w"))) (mapcar '(lambda (x)(write-line x setup-dialog-fp)) (list (strcat "GrM_Setup : dialog {label=\"GrM - Setup screen (Rlx " (now) ")\";") ":text_part {key=\"tp_debug_mode\";}" ":boxed_column {label=\"Dimensions\";" " :row {" " :column {" (dcl_plus_min "nof_rows" "Rows" "3") "spacer;"(dcl_plus_min "fill" "Fill (%)" "3") "}" " :column {" (dcl_plus_min "nof_columns" "Columns" "3") (dcl_plus_min "button_width_height_ratio" "Ratio W/H " "3") "}" " }" " :row {alignment=centered;" " :column {width=10;}" " :toggle {label=\"Use fixed cell width\";key=\"tg_use_fixed_width\";}" " :edit_box {edit_width=3;key=\"eb_fixed_width\";}" " :column {width=12;}" " :toggle {label=\"Use fixed cell height\";key=\"tg_use_fixed_height\";}" " :edit_box {edit_width=3;key=\"eb_fixed_height\";}" " :column {width=2;}" " }" "}" ":boxed_row {label=\"Colors\";" (dcl_button_image1 "frame_color" "Frame") (dcl_button_image1 "text_color" "Text") (dcl_button_image1 "background_color" "Background") "}" ":boxed_radio_row {label=\"Justification\";" " :radio_button {key=\"rb_left\";label=\"Left\";}" " :radio_button {key=\"rb_top\";label=\"Top\";}" " :radio_button {key=\"rb_center\";label=\"Center\";}" " :radio_button {key=\"rb_bottom\";label=\"Bottom\";}" " :radio_button {key=\"rb_right\";label=\"Right\";}" "}" "spacer;" ":boxed_column {" " :row {:edit_box {edit_width=3;label=\"Max Col\";key=\"eb_max_columns\";}" " :edit_box {edit_width=3;label=\"Max Row\";key=\"eb_max_rows\";}" " :edit_box {edit_width=3;label=\"Max Ratio\";key=\"eb_max_ratio\";}" " :edit_box {edit_width=3;label=\"Max Fill\";key=\"eb_max_fill\";}" " :edit_box {edit_width=3;label=\"Text size\";key=\"eb_text_size_factor\";}" " }" " spacer;spacer;" " :row {:toggle {label=\"Sort app-list on load\";key=\"tg_sort_on_load\";}" " :toggle {label=\"Follow Justification\";key=\"tg_follow_Justification\";}}" "}" "spacer;spacer;" ":column {:row {fixed_width=true;alignment=centered;" " :button{key=\"bt_app_list\";label=\"App list\";}" " :button{key=\"bt_preview\";label=\"Preview\";}" " :image_button {color=dialog_background;width=0.1;height=0.1;fixed_height=true;key=\"ib_debug_mode\";label=\"&d\";}" " ok_button;cancel_button;}}" "spacer;spacer;" "}" ) ) ) (if setup-dialog-fp (close setup-dialog-fp))(gc) ;(if (setq f (findfile setup-dialog-fn)) (startapp "notepad" f)(alert (strcat "huh? " (vl-princ-to-string f)))) ) (defun GrM_Setup_Dialog_Start ( / drv) (GrM_Setup_Dialog_Create) (if (and (setq setup-dialog-dcl (load_dialog setup-dialog-fn)) (new_dialog "GrM_Setup" setup-dialog-dcl)) (progn (GrM_Setup_Dialog_Update) (GrM_Setup_Dialog_Action) (setq drv (start_dialog)) (if setup-dialog-fn (vl-file-delete setup-dialog-fn)) (cond ((= drv 0)(Setup_Dialog_Cancel)) ((= drv 1)(WriteSettingsToRegistry)(GrM_Draw_Toolbar)) ((= drv 2)(WriteSettingsToRegistry)(Preview_Toolbar)) ) ) ) ) (defun Preview_Toolbar () (GrM_Draw_Toolbar) (princ "\rPress any key to return to dialog") (vl-catch-all-apply 'grread (list nil 8 0)) (redraw) (GrM_Setup_Dialog_Start) ) (defun cycle_Justification ( / co ol i) (setq co GrM-Toolbar-Justification ol '("left" "right" "top" "center" "bottom")) (if (setq i (vl-position co ol)) (progn (if (> i 3) (setq GrM-Toolbar-Justification (nth 0 ol)) (setq GrM-Toolbar-Justification (nth (1+ i) ol)) ) (GrM_Swappie)(WriteSettingsToRegistry)(GrM_Draw_Toolbar) ) ) ) (defun cycle_color ( / c cl i) ;;; grey1 (8), blue (144), green (72), red (12), pink (244), brown (24) (setq c GrM-Background-Color cl '("8" "144" "72" "12" "214" "24")) (if (setq i (vl-position c cl)) (progn (if (> i 4) (setq GrM-Background-Color (nth 0 cl)) (setq GrM-Background-Color (nth (1+ i) cl)) ) ) ;;; user can have selected color not in color list so start with list color numero uno (setq GrM-Background-Color (nth 0 cl)) ) (WriteSettingsToRegistry)(GrM_Draw_Toolbar) ) (defun GrM_Setup_Dialog_Update () (setq setup-dialog-tl '( (GrM-NoF-Rows "eb_nof_rows") (GrM-NoF-Columns "eb_nof_columns") (GrM-Button-Background-Fill "eb_fill") (GrM-Button-Width-Height-Ratio "eb_button_width_height_ratio") (GrM-Use-Fixed-Cell-Width "tg_use_fixed_width") (GrM-Use-Fixed-Cell-Height "tg_use_fixed_height") (GrM-Cell-Width "eb_fixed_width") (GrM-Cell-Height "eb_fixed_height") ;;; options (GrM-Max-Columns "eb_max_columns") (GrM-Max-Rows "eb_max_rows") (GrM-Max-Button-Width-Height-Ratio "eb_max_ratio") (GrM-Max-Button-Background-Fill "eb_max_fill") (GrM-Text-Size-Factor "eb_text_size_factor") (GrM-Follow-Justification "tg_follow_Justification") (GrM-Sort-On-Load "tg_sort_on_load") ;;; GrM-Max-Columns GrM-Max-Rows GrM-Follow-Justification GrM-Sort-On-Load GrM-Text-Size-Factor ) ) ;;; rd = reset data (val1 val2 ...) , in case of a cancel store original values before start of dialog (if (null setup-dialog-rd) (setq setup-dialog-rd (Save_Setup_Dialog_Data setup-dialog-tl))) ;;; set edit boxes and toggle values (Set_Setup_Dialog_Tiles setup-dialog-tl) ;;; update color images (Frame , Text & Background (GrM_Update_Color_Images) ;;; update radiobuttons (Justification top/left/bottom/right (GrM_Update_Radio_Buttons) ;;; Check & set debug mode (set_tile "tp_debug_mode" (if (and GrM-Debug-Mode (eq GrM-Debug-Mode "1")) " * debug mode *" "")) ) (defun GrM_Setup_Dialog_Action () (mapcar '(lambda (x)(action_tile (car x) (cadr x))) '(("cancel" "(done_dialog 0)") ("accept" "(done_dialog 1)") ("bt_preview" "(done_dialog 2)") ("ib_debug_mode" "(Toggle_Debug_Mode)") ("eb_nof_rows" "(setq GrM-NoF-Rows $value)") ;;; GrM_IncTile - just for testing ("bt_nof_rows_plus" "(GrM_IncTile $key 1)") ("bt_nof_rows_min" "(GrM_IncTile $key -1)") ("eb_nof_columns" "(setq GrM-NoF-Columns $value)") ("bt_nof_columns_plus" "(GrM_IncTile $key 1)") ("bt_nof_columns_min" "(GrM_IncTile $key -1)") ("eb_fill" "(setq GrM-Button-Background-Fill $value)") ("bt_fill_plus" "(GrM_IncTile $key 1)") ("bt_fill_min" "(GrM_IncTile $key -1)") ("eb_button_width_height_ratio" "(setq GrM-Button-Width-Height-Ratio $value)") ("bt_button_width_height_ratio_plus" "(GrM_IncTile $key 1)") ("bt_button_width_height_ratio_min" "(GrM_IncTile $key -1)") ;;; fixed width / height ("tg_use_fixed_width" "(setq GrM-Use-Fixed-Cell-Width $value)") ("tg_use_fixed_height" "(setq GrM-Use-Fixed-Cell-Height $value)") ("eb_fixed_width" "(setq GrM-Cell-Width $value)") ("eb_fixed_height" "(setq GrM-Cell-Height $value)") ;;; color handling ("bt_frame_color" "(get_frame_color)") ("bt_text_color" "(get_text_color)") ("bt_background_color" "(get_background_color)") ;;; options ("eb_max_columns" "(setq GrM-Max-Columns $value)") ("eb_max_rows" "(setq GrM-Max-Rows $value)") ("eb_text_size_factor" "(setq GrM-Text-Size-Factor $value)") ("tg_follow_Justification" "(setq GrM-Follow-Justification $value)") ("tg_sort_on_load" "(setq GrM-Sort-On-Load $value)") ;;; toolbar Justification / justification ("rb_left" "(GrM_Set_Justification $key)")("rb_right" "(GrM_Set_Justification $key)") ("rb_top" "(GrM_Set_Justification $key)")("rb_center" "(GrM_Set_Justification $key)") ("rb_bottom" "(GrM_Set_Justification $key)") ;;; ("bt_app_list" "(done_dialog 3)") (GrM_App_List_Dialog) ("bt_app_list" "(GrM_App_List_Dialog)") ) ) ) ;;; low tec but functional (defun Toggle_Debug_Mode () (cond ((eq GrM-Debug-Mode "1") (setq GrM-Debug-Mode "0")) ((eq GrM-Debug-Mode "0") (setq GrM-Debug-Mode "1")) (t (setq GrM-Debug-Mode "0"))) (set_tile "tp_debug_mode" (if (and GrM-Debug-Mode (eq GrM-Debug-Mode "1")) " * debug mode *" "")) ) (defun GrM_Update_Color_Images () (mapcar '(lambda (i c)(GrM_SetColorImage i c)) (list "im_frame_color" "im_text_color" "im_background_color") (list GrM-Frame-Color GrM-Text-Color GrM-Background-Color))) (defun GrM_Update_Radio_Buttons () (cond ((eq GrM-Toolbar-Justification "left")(set_tile "rb_left" "1")) ((eq GrM-Toolbar-Justification "right")(set_tile "rb_right" "1")) ((eq GrM-Toolbar-Justification "top")(set_tile "rb_top" "1")) ((eq GrM-Toolbar-Justification "bottom")(set_tile "rb_bottom" "1")) ((eq GrM-Toolbar-Justification "center")(set_tile "rb_center" "1")) ) ) ;;; when Justification changes from horizontal to vertical , swap nof columns & nof rows (defun GrM_Swappie ( / i1 i2) (setq i1 (atoi GrM-NoF-Columns) i2 (atoi GrM-NoF-Rows)) (cond ;;; horizontal ((member GrM-Toolbar-Justification '("top" "center" "bottom")) (setq GrM-NoF-Columns (itoa (max i1 i2)) GrM-NoF-Rows (itoa (min i1 i2)))) ;;; vertical ((member GrM-Toolbar-Justification '("left" "right" )) (setq GrM-NoF-Columns (itoa (min i1 i2)) GrM-NoF-Rows (itoa (max i1 i2)))) ) ) ;;; gonna assume that when Justification is left or right (vertical) , the number for rows is larger ;;; than the number for columns , this is handeld by setting GrM-Follow-Justification in dialog (defun GrM_Set_Justification (k) (setq GrM-Toolbar-Justification (substr k 4)) (if (eq GrM-Follow-Justification "1") (progn (GrM_Swappie)(set_tile "eb_nof_columns" GrM-NoF-Columns)(set_tile "eb_nof_rows" GrM-NoF-Rows)) ) ) ;;; for now fixed max number of rows / columns to 10 (i is not used anymore , uses tile name instead (defun GrM_IncTile ( tl i / v cmax rmax ratmax fmax) (if (isnum GrM-Max-Columns)(setq cmax (atoi GrM-Max-Columns))(setq cmax 12)) (if (isnum GrM-Max-Rows)(setq rmax (atoi GrM-Max-Rows))(setq rmax 12)) (if (isnum GrM-Max-Button-Width-Height-Ratio)(setq ratmax (atoi GrM-Max-Button-Width-Height-Ratio))(setq ratmax 3)) (if (isnum GrM-Max-Button-Background-Fill)(setq fmax (atoi GrM-Max-Button-Background-Fill))(setq fmax 100)) (cond ;;; columns ((eq tl "bt_nof_columns_plus") (setq GrM-NoF-Columns (itoa (1+ (atoi GrM-NoF-Columns)))) (if (> (atoi GrM-NoF-Columns) cmax) (setq GrM-NoF-Columns (itoa cmax))) (set_tile "eb_nof_columns" GrM-NoF-Columns)) ((eq tl "bt_nof_columns_min") (setq GrM-NoF-Columns (itoa (1- (atoi GrM-NoF-Columns)))) (if (< (atoi GrM-NoF-Columns) 1) (setq GrM-NoF-Columns "1")) (set_tile "eb_nof_columns" GrM-NoF-Columns)) ;;; rows ((eq tl "bt_nof_rows_plus") (setq GrM-NoF-Rows (itoa (1+ (atoi GrM-NoF-Rows)))) (if (> (atoi GrM-NoF-Rows) rmax) (setq GrM-NoF-Rows (itoa rmax))) (set_tile "eb_nof_rows" GrM-NoF-Rows)) ((eq tl "bt_nof_rows_min") (setq GrM-NoF-Rows (itoa (1- (atoi GrM-NoF-Rows)))) (if (< (atoi GrM-NoF-Rows) 1) (setq GrM-NoF-Rows "1")) (set_tile "eb_nof_rows" GrM-NoF-Rows)) ;;; width / height ratio ((eq tl "bt_button_width_height_ratio_plus") (setq GrM-Button-Width-Height-Ratio (itoa (1+ (atoi GrM-Button-Width-Height-Ratio)))) (if (> (atoi GrM-Button-Width-Height-Ratio) ratmax) (setq GrM-Button-Width-Height-Ratio (itoa ratmax))) (set_tile "eb_button_width_height_ratio" GrM-Button-Width-Height-Ratio)) ((eq tl "bt_button_width_height_ratio_min") (setq GrM-Button-Width-Height-Ratio (itoa (1- (atoi GrM-Button-Width-Height-Ratio)))) (if (< (atoi GrM-Button-Width-Height-Ratio) 1) (setq GrM-Button-Width-Height-Ratio "1")) (set_tile "eb_button_width_height_ratio" GrM-Button-Width-Height-Ratio)) ;;; button background fill ((eq tl "bt_fill_plus") (setq GrM-Button-Background-Fill (itoa (+ (atoi GrM-Button-Background-Fill) 10))) (if (> (atoi GrM-Button-Background-Fill) fmax) (setq GrM-Button-Background-Fill (itoa fmax))) (set_tile "eb_fill" GrM-Button-Background-Fill)) ((eq tl "bt_fill_min") (setq GrM-Button-Background-Fill (itoa (- (atoi GrM-Button-Background-Fill) 10))) (if (< (atoi GrM-Button-Background-Fill) 10) (setq GrM-Button-Background-Fill "10")) (set_tile "eb_fill" GrM-Button-Background-Fill)) ;;; overkill...really (t (alert (strcat "\nUnknown IncTile : " (vl-princ-to-string tl) " / " (vl-princ-to-string i)))) ) ) ;;; --- color handling -------------------------------------- color handling --------------------------------------- color handling --- ;;; (defun getcolor (d) (if (or (void d) (not (isnum d)))(setq d 7)) (acad_colordlg d nil)) ;;; check color , byblock/bylayer or nil are converted to color 7 (white) (defun checkcolor (c) (if (string-p c)(setq c (strcase c t))) (cond ((member c '(0 256 "0" "256" "byblock" "bylayer")) 7) ((numberp c) c) ((string-p c)(atoi c)) (t 7))) (defun GrM_SetColorImage (tilename color / col x y ) (if (isnum color) (cond ((= (type color) 'STR) (setq col (atoi color)))((= (type color) 'INT)(setq col color))(t (setq col 7)))) (if (and (string-p color) (member (strcase color T) '("bylayer" "byblock"))) (setq col 7)) (if col (progn (setq x (dimx_tile tilename) y (dimy_tile tilename)) (start_image tilename) (fill_image 0 0 x y col) (end_image))) ) (defun get_frame_color ( / c d ) (if (setq c (acad_colordlg (atoi GrM-Frame-Color) nil)) (progn (GrM_SetColorImage "im_frame_color" c)(setq GrM-Frame-Color (itoa c))))) (defun get_text_color ( / c d ) (if (setq c (acad_colordlg (atoi GrM-text-Color) nil)) (progn (GrM_SetColorImage "im_text_color" c)(setq GrM-text-Color (itoa c))))) (defun get_background_color ( / c d ) (if (setq c (acad_colordlg (atoi GrM-background-Color) nil)) (progn (GrM_SetColorImage "im_background_color" c)(setq GrM-background-Color (itoa c))))) ;;; --- dialog section ------------------------------------ end dialog section ------------------------------------- dialog section --- ;;; ;;; (re) calculate display parameters (dim_screen) ;;; screensize = (1840.0 685.0) (PC dependent / zoom independent) ;;; viewsize = height of current screen , varies with zoom ;;; viewctr = screen center point , varies with zoom ;;; recalculate after each zoom : dx dy / vx- vy- vx+ vy+ / vc vs ss dx dy vx- vy- vx+ vy+ vh vw) (defun dim_screen ( / dx dy) (setq vc (getvar "VIEWCTR") vs (getvar "VIEWSIZE") ss (getvar "SCREENSIZE")) ;;; view (half) width & view (half) height (assist for cornerpoints calculation) (setq dx (* vs (/ (car ss) (cadr ss)) 0.5) dy (* vs 0.5)) ;;; view corner points (setq vx- (- (car vc) dx) vy- (- (cadr vc) dy) vx+ (+ (car vc) dx) vy+ (+ (cadr vc) dy)) ;;; view height en view width (setq vh (- vy+ vy-) vw (- vx+ vx-)) ;;; inspect / debug ;(inspect (list 'vx- 'vy- 'vx+ 'vy+ 'vh 'vw 'vc)) ) ;;; cell width / height depends on viewsize / #rows / #colomns / Justification ;;; if Justification = horizontal then justification can be top / center / bottom ;;; if Justification = vertical then justification can be left / right ;;; - calculate cell width / cell height ;;; if Justification = horizontal : cell width = screen width / #cols , cell height = cell width / 2 ;;; if Justification = vertical ; cell height = screen height / #rows , cell width = cell height * 2 ;;; - calculate corner points , then start from center point ;;; replaces dim_cell with GrM_Draw_Toolbar which uses data from dialog / registry variables (defun GrM_Draw_Toolbar ( / tb-hw tb-hh) ;;; have no idea why sometimes GrM_Init is skipped , dirty fix (chk_reg_vars) ;;; get view data (dim_screen) ;;; first thing I need is cell height & cell width (if (member GrM-Toolbar-Justification '("top" "center" "bottom")) ;;; horizontal (progn (cond ;;; if use fixed cell width = true ;;; (X-to-N = anything to number , allow zero = 0 , fix numer = 0) ((= GrM-Use-Fixed-Cell-Width "1") (if (not (void GrM-Cell-Width)) (setq cell-width (X-to-N GrM-Cell-Width 0 0))(setq cell-width default-button-width))) ;;; divide screen-width by number of columns ((and (= GrM-Use-Fixed-Cell-Width "0") (setq i (X-to-N GrM-NoF-Columns 0 0))) (setq cell-width (/ vw i))) (t (setq cell-width (/ vw 10.0))) ) (cond ((eq GrM-Auto-Cell-Size-Ratio "1") (setq cell-Height (* cell-width 0.5))) ;;; if use fixed cell height = true ((= GrM-Use-Fixed-Cell-Height "1") (if (not (void GrM-Cell-Height)) (setq cell-height (X-to-N GrM-Cell-Height 0 0))(setq cell-height default-button-height))) (t (setq cell-height (* cell-width 0.5))) ) (setq tb-height (* cell-height (atoi GrM-NoF-Rows))) (cond ((eq GrM-Toolbar-Justification "top") (setq tb-x- vx- tb-y- (- vy+ tb-height) tb-x+ vx+ tb-y+ vy+)) ;;; tb-hw = toolbar half width , tb-hh = toolbar half height ((eq GrM-Toolbar-Justification "center") (setq tb-hw (* (atoi GrM-NoF-Columns) cell-width 0.5) tb-hh (* (atoi GrM-NoF-Rows) cell-height 0.5)) (setq tb-x- (- (car vc) tb-hw) tb-x+ (+ (car vc) tb-hw)) (setq tb-y- (- (cadr vc) tb-hh) tb-y+ (+ (cadr vc) tb-hh)) ) ((eq GrM-Toolbar-Justification "bottom") (setq tb-x- vx- tb-y- vy- tb-x+ vx+ tb-y+ (+ tb-y- tb-height))) ) ) ;;; "vertical" (progn ;;; calculate cell-height first (cond ;;;height is width / 2 ((and (eq GrM-Auto-Cell-Size-Ratio "1") (setq i (X-to-N GrM-NoF-Rows 0 0))) (setq cell-height (/ vh i))) ;;; if use fixed cell height = true (1 "1" T) check height (zero not allowed, dont fix result ((and (= GrM-Use-Fixed-Cell-Height "1") (setq i (X-to-N GrM-Cell-Height 0 0))) (setq cell-Height i)) ;;; divide screen-height by number of rows (zero not allowed , intergers only (fix result) ((and (= GrM-Use-Fixed-Cell-Height "0") (setq i (X-to-N GrM-NoF-Rows 0 0))) (setq cell-height (/ vh i))) ;;; set default for column of 10 rows (t (setq cell-height (/ vh 10.0))) ) ;;; calclate cell-width (cond ((eq GrM-Auto-Cell-Size-Ratio "1") (setq cell-width (* cell-height 2.0))) ;;; if use fixed cell width = true (1 "1" T) check width (zero not allowed, dont fix result ((and (= GrM-Use-Fixed-Cell-Width "1") (setq i (X-to-N GrM-Cell-Width 0 0))) (setq cell-width i)) (t (setq cell-width (* cell-height 2.0))) ) ;;; find toolbar alignment point ;;; for vertical these are left / center / right ;;; calculate width of toolbar for number of columns (setq tb-width (* cell-width (atoi GrM-NoF-Columns))) (cond ((eq GrM-Toolbar-Justification "left") (setq tb-x- vx- tb-y- vy- tb-x+ (+ tb-x- tb-width) tb-y+ vy+)) ((eq GrM-Toolbar-Justification "center") (setq tb-x- (- (car vc) (* tb-width 0.5)) tb-x+ (+ (car vc) (* tb-width 0.5)) tb-y- vy- tb-y+ vy+)) ((eq GrM-Toolbar-Justification "right") (setq tb-x- (- vx+ tb-width) tb-x+ vx+ tb-y- vy- tb-y+ vy+)) ) ) ) (if (eq GrM-Debug-Mode "1") (inspect (list 'vh 'vw 'GrM-Toolbar-Justification 'GrM-NoF-Columns 'GrM-NoF-Rows 'GrM-Use-Fixed-Cell-Height 'GrM-Cell-Height 'cell-Height 'GrM-Use-Fixed-Cell-Width 'GrM-Cell-Width 'cell-width 'GrM-Frame-Color 'GrM-Text-Color 'GrM-Background-Color ) ) ) (setq cell-text-height (/ cell-height 2.0)) ;(setq tst-cell-height cell-height tst-cell-width cell-width) ;;; some more testing (x- y- x+ y+ r c co / xl yl) (Draw_Frame tb-x- tb-y- tb-x+ tb-y+ (atoi GrM-NoF-Rows) (atoi GrM-NoF-Columns) 2) ) ;;; x-=xmin, x+=ymax etc, r=rows, c=columns, co=color ;;; (setq e- (getvar "EXTMIN") e+ (getvar "EXTMAX")) ;;; (Draw_Frame (car e-)(cadr e-)(car e+)(cadr e+) 5 5 1) (defun Draw_Frame (x- y- x+ y+ r c co / xl yl pl text-size bcol fcol tcol justy ) (record "Draw_Frame") (if (and (not (void GrM-background-Color))(isnum GrM-background-Color)) (setq bcol (atoi GrM-background-Color))(setq col 142)) (if (and (not (void GrM-Frame-Color))(isnum GrM-Frame-Color)) (setq fcol (atoi GrM-Frame-Color))(setq fcol 7)) (if (and (not (void GrM-Text-Color))(isnum GrM-Text-Color)) (setq tcol (atoi GrM-Text-Color))(setq tcol 7)) (redraw)(Fill_Toolbar_Background x- y- x+ y+ bcol) ;;; create x & y list for all grid coordinates (setq xl (gnl+ x- (1+ c) (/ (abs (- x+ x-)) c)) yl (gnl- y+ (1+ r) (/ (abs (- y+ y-)) r))) ;;; draw all horizontal lines (foreach y yl (grdraw (list x- y) (list x+ y) fcol)) ;;; draw all vertical lines (foreach x xl (grdraw (list x y+) (list x y-) fcol)) ;;; draw the texts (setq pl (gmpl xl yl)) ;;; cell-text-height is cell-height / 2 (if (and (not (void GrM-Text-Size-Factor))(isnum GrM-Text-Size-Factor)) (setq text-size (/ cell-text-height (atoi GrM-Text-Size-Factor))) (setq text-size (/ cell-text-height 9)) ) ;;; bad idea : grtxt routine has its limitations so I'll adjust text justification along with toolbar Justification ;;; all text insertion points are calculated based on middle algnment so lets keep it that way for now ;(cond ((eq GrM-Toolbar-Justification "left")(setq justy "L"))((eq GrM-Toolbar-Justification "right")(setq justy "R"))(t (setq justy "M"))) (setq justy "M") (mapcar '(lambda (p s) (grtxt (strcase s) p tcol 0 justy text-size)) pl (if (vl-consp app-list) (mapcar 'vl-filename-base app-list) '("Empty"))) (princ) ) ;;; fill toolbar background (defun Fill_Toolbar_Background (x- y- x+ y+ c / y vws bgf-fac delta-y) (setq y y- vws (getvar "viewsize") bgf-fac (/ 0.1 (/ (atof GrM-Button-Background-Fill) 100.0))) (setq delta-y (/ vws 1000.0)) (while (<= y y+)(grdraw (list x- y)(list x+ y) c)(setq y (+ y (* delta-y bgf-fac (/ vws start-viewsize)))))) ;;; (setq cel-id (GrM_GetCellNumber x y)) (defun GrM_GetCellNumber (x y / id ) ;;; cell number from dialog , without accouting for page number ;(setq id (+ (* (atoi GrM-NoF-Columns) (fix (/ y cell-height))) (fix (1+ (/ x cell-width))))) (if (eq tst-Justification "horizontal") (setq id (+ (* (atoi tst-NoF-Columns) (fix (/ y tst-cell-height))) (fix (1+ (/ x tst-cell-width))))) (setq id (+ (* (atoi tst-NoF-Rows) (fix (/ y tst-cell-height))) (fix (1+ (/ x tst-cell-width))))) ) ) ;;; (GrM_GetCell-ID (list 100.0 100.0) (list 130.0 70.0) 3 3 (list 122.0 79.0)) ;;; get cell-id from point selection to use as nth for app-list (defun GrM_GetCell-ID (ul lr c r p / dy dy x y)(setq x (car p) y (cadr p)) (setq dx (/ (abs (- (car lr) (car ul))) c) dy (/ (abs (- (cadr ul) (cadr lr))) r)) (+ (/ (fix (abs (- x (car ul))))(fix dx))(* (1- (- r (/ (fix (abs (- y (cadr lr))))(fix dy)))) c)) ) ;;; (show_grid) (defun show_grid ( / x dx y dy i) (setq x (fix screen-width) y (fix screen-height)) (setq dy (/ y (atoi GrM-NoF-Rows)) dx (/ x (atoi GrM-NoF-Columns))) (setq i 0)(while (< i x)(grdraw (list i 0) (list i y) 3)(setq i (fix (+ i dx)))) (setq i 0)(while (< i y)(grdraw (list 0 i) (list x i) 3)(setq i (fix (+ i dy))))) ;;; (setq corner (GrM_GetCellCorner 5)) (defun GrM_GetCellCorner ( cell / col row) (if (= (rem cell (atoi GrM-NoF-Columns)) 0) (setq col (atoi GrM-NoF-Columns) row (1- (/ cell (atoi GrM-NoF-Columns)))) (setq col (rem cell (atoi GrM-NoF-Columns)) row (/ cell (atoi GrM-NoF-Columns)))) (list (* cell-width (1- col)) (* cell-height row))) ;;; (Dim_Box (list 400 75) cell-width cell-height) ;;; arg top left point , width , height , return list cornerpoints (defun Dim_Box (p w h) (list p (polar p 0 w) (polar p (atan h w) (sqrt (+ (expt w 2)(expt h 2)))) (polar p (/ pi 2) h))) ;;; --- GrTxt ---------------------------------------------------- GrTxt ---------------------------------------------------- GrTxt --- ;;; ;;; found this old lisp (grtxt.lsp) , don't know author but all credits are for this human from earth ;;; text string / coordinate point / color / angle / justification/ z for text height ;;; *** UPPER CASE ONLY *** (grtxt (STRCASE "Rob") (getvar "viewctr") 1 0 "M") ;;; 2025-07-29 added z for text height as parameter (defun grtxt (ts cp cl a j z / vp ltb i xp c p1 p2 lp ld n al) ;;; vertex points (setq vp '(( 1 ( 0.50 0.25))( 2 ( 0.50 0.55))( 3 ( 0.50 0.85))( 4 ( 0.50 1.00))( 5 ( 0.25 1.00)) ( 6 ( 0.00 1.00))( 7 (-0.25 1.00))( 8 (-0.50 1.00))( 9 (-0.50 0.85))(10 (-0.50 0.55)) (11 (-0.50 0.25))(12 (-0.50 0.10))(13 (-0.25 0.10))(14 ( 0.00 0.10))(15 ( 0.25 0.10)) (16 ( 0.50 0.10))(17 ( 0.50 -0.05))(18 ( 0.50 -0.45))(19 ( 0.50 -0.85))(20 ( 0.50 -1.00)) (21 ( 0.25 -1.00))(22 ( 0.00 -1.00))(23 (-0.25 -1.00))(24 (-0.50 -1.00))(25 (-0.50 -0.85)) (26 (-0.50 -0.40))(27 (-0.50 -0.05))(30 ( 0.35 0.85))(31 (-0.35 0.85))(32 (-0.35 -0.85)) (33 ( 0.35 -0.85))(40 ( 0.25 0.35))(41 (-0.25 0.35))(42 ( 0.25 -0.15))(43 (-0.25 -0.15)) (44 ( 0.00 0.45))(45 ( 0.00 -0.25))(50 ( 0.30 0.20))(51 ( 0.30 0.35))(52 ( 0.20 0.35)) (53 ( 0.20 0.20))(54 ( 0.30 0.10))(55 ( 0.30 -0.10))(56 ( 0.20 -0.10))(57 ( 0.20 0.10)) (60 (-0.30 0.20))(61 (-0.30 0.35))(62 (-0.20 0.35))(63 (-0.20 0.20))(64 (-0.30 0.10)) (65 (-0.30 -0.10))(66 (-0.20 -0.10))(67 (-0.20 0.10)))) ;;; letter table (setq ltb '(("A" 24 9 7 5 3 20 16 12) ("B" 12 15 1 3 5 8 24 21 19 17 15) ("C" 3 5 7 9 25 23 21 19) ("D" 3 5 8 24 21 19 3) ("E" 4 8 12 15 12 24 20) ("F" 4 8 12 15 12 24) ("G" 3 5 7 9 25 23 21 19 16 14) ("H" 20 -4 8 -24 16 12) ("I" 7 5 6 22 23 21) ("J" 4 19 21 23 25) ("K" 8 24 12 13 4 13 20) ("L" 8 24 20) ("M" 24 8 14 4 20) ("N" 24 8 20 4) ("O" 3 5 7 9 25 23 21 19 3) ("P" 12 15 1 3 5 8 24) ("Q" 3 5 7 9 25 23 21 19 3 -19 20 45) ("R" 20 14 12 15 1 3 5 8 24) ("S" 3 5 7 9 11 13 15 17 19 21 23 25) ("T" 4 8 6 22) ("U" 8 25 23 21 19 4 20) ("V" 8 22 4) ("W" 8 23 14 21 4) ("X" 4 -24 8 20) ("Y" 8 14 22 14 4) ("Z" 8 4 24 20) ("0" 3 5 7 9 25 23 21 19 -3 4 24) ("1" 31 7 6 22 21 23) ("2" 9 7 5 3 1 15 13 27 24 20) ("3" 9 7 5 3 1 15 13 15 17 19 21 23 25) ("4" 8 12 16 15 5 21) ("5" 4 8 12 15 17 19 21 23 25) ("6" 3 5 7 9 25 23 21 19 17 15 12) ("7" 8 4 22) ("8" 3 5 7 9 11 13 27 25 23 21 19 17 15 13 15 1 3) ("9" 25 23 21 19 3 5 7 9 11 13 16) ("<" 4 12 20) (">" 8 16 24) ("," 33 21) ("." 19 20 21 33 19) ("\'" 4 30) ("\"" 4 -30 7 31) (";" 50 51 52 53 -50 54 55 56 57 55 45) (":" 50 51 52 53 -50 54 55 56 57 55) ("\\" 8 20) ("/" 4 24) ("?" 11 10 7 5 2 1 45 22) ("|" 6 -44 45 22) ("+" 44 -45 13 15) ("=" 40 -41 43 42) ("-" 13 15) ("_" 20 24) (")" 6 2 18 22) ("(" 6 10 26 22) ("*" 40 -43 41 -42 45 44) ("&" 21 31 7 6 26 25 23 16) ("^" 10 6 2) ("%" 57 54 55 56 -57 63 60 61 62 -63 5 24) ("$" 3 5 7 9 11 13 15 17 19 21 23 25 -26 22 6) ("#" 24 -6 22 -4 1 -11 17 27) ("@" 42 15 40 44 41 13 43 45 42 17 3 5 7 9 25 23 21 19) ("!" 6 -45 22 22) ("~" 9 31 44 40 2) ("`" 8 31) ("[" 6 8 24 22) ("]" 6 4 20 22) ("{" 6 7 41 12 43 23 22) ("}" 6 5 40 16 42 21 22) (""))) ;;; text height - use z as parameter ;;;(setq z (/ (getvar "VIEWSIZE") (cadr (getvar "SCREENSIZE")) 0.1)) ;;;(setq z (/ (getvar "VIEWSIZE") 10)) (cond ;;; left justification ((eq (strcase (substr j 1 1)) "L") (setq xp (list (+ (car cp) z) (cadr cp)) i 1)) ;;; middle justification ((eq (strcase (substr j 1 1)) "M") (setq xp (list (- (car cp) (* z (strlen ts) 0.5)) (cadr cp)) i 1)) ;;; right justification ((eq (strcase (substr j 1 1)) "R") (setq xp (list (- (car cp) (* z (strlen ts) 1.5)) (cadr cp)) i 1)) ) (repeat (strlen ts) ;;; each charachter / line point list / letter point def (setq c (substr ts i 1) lp '() ld (cdr (assoc c ltb))) (while (> (length ld) 1) (setq p1 (cadr (assoc (abs (nth 0 ld)) vp)) p2 (cadr (assoc (abs (nth 1 ld)) vp)) p1 (mapcar '* (list z z) p1) p2 (mapcar '* (list z z) p2) p1 (mapcar '+ xp p1) p2 (mapcar '+ xp p2) lp (append lp (list (if (minusp (nth 0 ld)) 0 cl) p1 p2)) ld (cdr ld)) ) ;;; add rotation angle (setq n 0 al nil) (repeat (/ (length lp) 3) (setq al (cons (nth n lp) al) al (cons (polar cp (+ a (angle cp (nth (+ n 1) lp))) (distance cp (nth (+ n 1) lp))) al) al (cons (polar cp (+ a (angle cp (nth (+ n 2) lp))) (distance cp (nth (+ n 2) lp))) al)) (setq n (+ n 3)) ) (and al (grvecs (reverse al))) (setq xp (list (+ (car xp) (* z 1.5)) (cadr xp)) i (1+ i)) ) (prin1) ) ;;; --- GrTxt ---------------------------------------------------- GrTxt ---------------------------------------------------- GrTxt --- ;;; ;;; --- App list dialog ------------------------------------- App list dialog ------------------------------------- App list dialog --- ;;; ;;; Simple File Dialog ;;; f = dialog file name , p = pointer , d = dialog , app-list = list , i = input , idx = listbox index (defun GrM_App_List_Dialog ( / f p d app-list i idx regkey regvar Filli-Dat-File return-to-setup-dialog) (setq idx 0) ;;; (InitDefaultRegistrySettings)(ReadSettingsFromRegistry) ;;; first use (if (or (null GrM-App-List-File)(not (eq (type GrM-App-List-File) 'STR))) (progn (setq GrM-App-List-File (vl-filename-mktemp "app-list.dat") p (open GrM-App-List-File "w")) (close p)(gc) ) ) ;;; read data file (if (and (findfile GrM-App-List-File)(setq p (open GrM-App-List-File "r"))) (progn (while (setq i (read-line p))(setq app-list (cons i app-list)))(close p))) ;;; check data list (if (vl-consp app-list)(setq app-list (acad_strlsort app-list)) (setq app-list (list "Empty"))) ;;; create dialog (if (and (setq f (vl-filename-mktemp "filli.dcl") p (open f "w"))) (mapcar '(lambda (x)(write-line x p)) (list (strcat "app_list : dialog {label=\"App list dialog (Rlx " (now) ")\";") "spacer;:text_part {key=\"tp\";}spacer;" ":boxed_row {label=\"File list\";:column {:list_box {key=\"lb\";width=64;}}spacer;" ":column {:button {key=\"add\";label=\"Add\";}:button {key=\"del\";label=\"Del\";}" ":button {key=\"up\";label=\"Up\";}:button {key=\"down\";label=\"Down\";}:button {key=\"sort\";label=\"Sort\";}}}" ":text_part {key=\"tp_file_info\";}" "spacer; :column {:row {fixed_width=true;alignment=centered;:button{key=\"load\";label=\"Load\";}" ":button{key=\"save\";label=\"Save\";}:button{key=\"saveas\";label=\"Saveas\";}" ":button{key=\"edit\";label=\"Edit\";} ok_button;cancel_button;}}spacer;spacer;}" ) ) (princ "\nComputer says no : unable to create dialog") ) ;;; clean desk policy (if p (progn (close p)(gc))) ;;; start dialog (if (and (setq d (load_dialog f)) (new_dialog "app_list" d)) (progn ;;; fill list box (setq idx 0)(lb_upd) ;;; activate buttons (action_tile "cancel" "(done_dialog 0)")(action_tile "accept" "(done_dialog 1)") (action_tile "lb" "(setq idx (atoi $value))(lb_upd_info)") (mapcar '(lambda (x)(action_tile x "(action_key $key)")) '("add" "del" "up" "down" "sort" "load" "save" "saveas" "edit")) (setq drv (start_dialog)) (if (and f (setq f (findfile f))) (vl-file-delete f)) (cond ((= drv 0)) ((= drv 1)(WriteSettingsToRegistry)) ) ) ) ) ;;; just to have a little less code in main loop (defun action_key (k) (cond ((= k "add")(_add))((= k "del")(_del))((= k "up")(lb_mod "up"))((= k "down")(lb_mod "down")) ((= k "sort")(lb_sort))((= k "load")(_load))((= k "save")(_save))((= k "saveas")(_saveas)) ((= k "edit")(_edit_dat_file)) ) ) ;;; lb_upd = update list box (init / redraw / refresh) (defun lb_upd () (set_tile "tp" (strcat " Data file : " (vl-princ-to-string GrM-App-List-File))) (start_list "lb")(mapcar 'add_list (mapcar 'vl-filename-base app-list))(end_list) (set_tile "lb" (itoa idx)) (lb_upd_info) ) ;;; update the text part below listbox to show complete path & filename (defun lb_upd_info () (if (vl-consp app-list) (set_tile "tp_file_info" (strcat " File : " (vl-princ-to-string (nth idx app-list)))) (set_tile "tp_file_info" " File : - ") ) ) ;;; lb_sort = sort list box (defun lb_sort () (setq app-list (acad_strlsort app-list)) (start_list "lb")(mapcar 'add_list app-list)(end_list)(set_tile "lb" (itoa idx))) ;;; lb_mod = modify list box ;;; m = mode up or down ("u" or "d") , app-list = app list (global) , xl = temp list (local) ;;; idx = index (global) , i = index (local) , i1 / i2 = scrap lists (local) (defun lb_mod (m / i xl i1 i2) (setq i idx xl (vl-remove-if '(lambda (x)(= x "")) app-list)) (cond ((void i))((or (null xl)(< (length xl) 2)))((and (= i 0) (= m "up")))((and (>= i (1- (length xl)))(= m "down"))) (t (setq i1 (nth i xl)) (if (= m "up") (setq i (1- i) i2 (nth i xl)) (setq i (1+ i) i2 (nth i xl) )) (setq xl (subst "i1" i1 xl) xl (subst "i2" i2 xl) xl (subst i2 "i1" xl) xl (subst i1 "i2" xl) idx i))) (cond ((< idx 0)(setq idx 0)) ((>= idx (length xl))(setq idx (1- (length xl))))) (setq app-list xl) (lb_upd) ) ;;; --- Tiny lisp section --------------------------------- Tiny lisp section ----------------------------------- Tiny lisp section --- ;;; (defun void (x) (or (eq x nil)(and (listp x)(not (vl-consp x)))(and (eq 'STR (type x))(eq "" (vl-string-trim " \t\r\n" x))))) (defun isnum (n)(if (or (numberp n) (and (= (type n) 'STR) (distof n))) t nil)) (defun string-p (s) (if (= (type s) 'str) t nil)) (defun uc (s) (alert (strcat "Under construction : " s))) (defun now ( / s l ) (setq s (rtos (getvar "CDATE")) l '("Jan""Feb""Mar""Apr""May""Jun""Jul""Aug""Sep""Oct""Nov""Dec")) (strcat (substr s 7 2) "-" (nth (1- (atoi (substr s 5 2))) l) "-'" (substr s 3 2))) ;;; remove from list (defun rfl (e app-list) (apply 'append (subst nil (list e) (mapcar 'list app-list)))) ;;; anything to number : n = number in any format (INT/REAL/STR) , z = allow 0 (zero) , f = fix result ;;; (X-to-N "0.0" 0 0) = nil , (X-to-N "0.0" 1 0) = 0.0 , (X-to-N "0.0" 1 1) = 0 , (X-to-N "rlx" 1 1) = nil (defun X-to-N (n z f / r ) (cond ((eq (type n) 'INT )(setq r n))((eq (type n) 'REAL)(setq r n))((distof n)(setq r (distof n)))(t (setq r nil))) (cond ((not r))((and (zerop r) (member z '(0 "0" nil)))(setq r nil)))(cond ((not r) nil)((member f '(1 "1" T))(fix r))(t (float r)))) ;;; for debugging , sort of trace list (defun record (s)(setq rec-list (cons s rec-list))) ;;; (setq rec-list nil) ;;; (setq a 1 b nil) (inspect (list 'a 'b)) (defun inspect (lst / _f) (defun _f (l) (apply 'strcat (cdr (apply 'append (mapcar (function (lambda (x) (list "\n" x))) l))))) (alert (_f (mapcar '(lambda (x) (strcat (vl-symbol-name x) " = " (vl-princ-to-string (vl-symbol-value x)))) lst)))) ;; tiny lisps ;;; generate number (gnum 1 5) -> '(1 2 3 4 5) (defun gnum (s e / i l) (and (numberp s)(numberp e)(setq i s)(while (<= i e)(setq l (cons i l) i (1+ i)))) (reverse l)) ;;; i = startnumber n = number of numbers , d = difference (gnl- 100 6 12) -> (100 88 76 64 52 40) ;;; generate all x-coordinates between xmin=322.5 & xmax =347.5 , 5 columns ;;; (gnl- xmax col+1 (- xmax xmin)) ;;; (gnl- 347.5 (1+ 5) (/ (- 347.5 322.5) 5)) -> (347.5 342.5 337.5 332.5 327.5 322.5) (defun gnl- (i n d / l)(setq l (list i))(repeat (1- n)(setq l (cons (setq i (- i d)) l)))(reverse l)) ;;; same but incremental ;;; (gnl- xmin (1+ col) (- xmax xmin)) (gnl- -10 6 (- -10 10)) ;;; (gnl+ 322.5 (1+ 5) (/ (- 347.5 322.5) 5)) -> (322.5 327.5 332.5 337.5 342.5 347.5) (defun gnl+ (i n d / l)(setq l (list i))(repeat (1- n)(setq l (cons (setq i (+ i d)) l)))(reverse l)) ;;; generate midpoint list ;;; (gmpl '(10 20 30 40 ) '(100 90 80)) -> '((15 95) (25 95) (35 95) (15 85) (25 85) (35 85)) (defun gmpl (xl yl / f x y) (defun f (l)(mapcar '(lambda (a b) (+ a (/ (- b a) 2.0))) l (cdr l))) (setq x (f '(10 20 30 40))) ;;; -> '(15.0 25.0 35.0) (setq y (f '(100 90 80))) ;;; -> '(95.0 85.0) (mapcar '(lambda (yy) (mapcar '(lambda (xx)(cons xx yy)) (f '(10 20 30 40)))) (f '(100 90 80))) ;;; -> (((15.0 . 95.0) (25.0 . 95.0) (35.0 . 95.0)) ((15.0 . 85.0) (25.0 . 85.0) (35.0 . 85.0))) ) ;;; (gmpl '(10 20 30 40 ) '(100 90 80)) (defun gmpl (xl yl / f) (defun f (l)(mapcar '(lambda (a b)(+ a (/ (- (float b) (float a)) 2.0))) l (cdr l))) (apply 'append (mapcar '(lambda (y)(mapcar '(lambda (x)(list x y 0.0))(f xl)))(f yl)))) ;;; rlx_sf - sub folders : c:/temp/test -> ("c:" "temp" "test") (defun rlx_sf ( fol / i) (if (setq i (vl-string-search "\\" fol)) (cons (substr fol 1 i) (rlx_sf (substr fol (+ i 1 (strlen "\\"))))) (list fol))) ;;; rlx_mf - make folder (defun rlx_mf ( fol / sf) (defun MF (rt sf) (if sf ((lambda (fol)(vl-mkdir fol)(MF fol (cdr sf)))(strcat rt "\\" (car sf))))) (if (setq sf (rlx_sf (vl-string-translate "/" "\\" fol))) (MF (car sf) (cdr sf))) (vl-file-directory-p fol)) ;;; --- Tiny lisp section --------------------------------- Tiny lisp section ----------------------------------- Tiny lisp section --- ;;; ;;; --- File operations ------------------------------------ File operations -------------------------------------- File operations --- ;;; ;;; load / save (data) file ;;; app-list = global list for list box , app-list is global name for data file (defun _load ( / fn fp i lst def) (if (or (void GrM-App-List-File) (not (setq def (car (fnsplitl GrM-App-List-File)))) (not (vl-file-directory-p def)))(setq def "")) (if (and (setq fn (getfiled "Select a data file" def "dat" 0))(setq fp (open fn "r"))) (while (setq i (read-line fp))(setq lst (cons i lst)))) (if fp (close fp)) (if (vl-consp lst) (progn (if (and (> (length lst) 1)(member "Empty" lst)) (setq lst (vl-remove "Empty" lst))) (setq GrM-App-List-File fn) (if (eq GrM-Sort-On-Load "1") (setq app-list (acad_strlsort lst)) (setq app-list (reverse lst)) ) (lb_upd) (WriteSettingsToRegistry) ) ) ) ;;; (create_default_data_file "c:\\temp\\rlx\\rlx\\xxx.xxx") (defun create_default_data_file ( fn / split) (cond ((or (null fn) (not (eq (type fn) 'STR)) (eq fn "")) (alert (strcat "unable to create file : " (vl-princ-to-string fn)))) ((findfile fn)) (t (setq split (fnsplitl fn)) (if (not (vl-file-directory-p (car split))) (rlx_mf (car split))) (if (setq fp (open fn "w")) (progn (close fp)(gc)) (alert (strcat "unable to create file : " (vl-princ-to-string fn))) ) ) ) ) (defun GrM_Preload_App_List ( / fn fp lst) (if (and (not (void (setq fn GrM-App-List-File)))(findfile fn)(setq fp (open fn "r"))) (while (setq i (read-line fp))(setq lst (cons i lst)))) (if fp (close fp)) ;(if (vl-consp lst)(setq app-list lst)(setq app-list '("Empty"))) (if (vl-consp lst)(setq app-list (reverse lst))(setq app-list '("Empty"))) ) (defun _save ( / fn fp def ) (if (and (not (void (setq fn GrM-App-List-File)))(findfile fn)(vl-consp app-list)(setq fp (open fn "w"))) (progn ;;; remove "Empty" from list if items have been added (if (and (> (length app-list) 1)(member "Empty" app-list)) (setq app-list (vl-remove "Empty" app-list))) (foreach x app-list (write-line x fp)) (close fp) (gc) ) ) ) (defun _saveas ( / fn fp def ) (if (or (void GrM-App-List-File) (not (setq def (car (fnsplitl GrM-App-List-File)))) (not (vl-file-directory-p def)))(setq def "")) (if (and (vl-consp app-list)(setq fn (getfiled "Select a data file" def "dat" 1))(setq fp (open fn "w"))) (progn (foreach x app-list (write-line x fp))(close fp)(gc) (setq GrM-App-List-File fn)(WriteSettingsToRegistry) ) ) ) ;;; add / del to / from list ;;; update : add full path instead of filename only (defun _add ( / f d e) (setq e "lsp") (if (or (void GrM-App-List-File)(not (setq d (car (fnsplitl GrM-App-List-File))))(not (vl-file-directory-p d)))(setq d "")) (if (setq f (getfiled "Select a lisp file" d e 0)) (progn (if (or (not (vl-consp app-list)) (equal app-list (list "Empty"))) (setq app-list (list f)) (setq app-list (append app-list (list f))) ) (lb_upd) ) ) ) (defun _del () (setq app-list (rfl (nth idx app-list) app-list)) (lb_upd)) (defun _edit_dat_file ( / fn) (if (and (not (void (setq fn GrM-App-List-File)))(findfile fn)) (progn (done_dialog) (startapp "notepad" fn)(alert "Press ok when done")(GrM_App_List_Dialog)))) ;;; --- File operations ------------------------------------ File operations -------------------------------------- File operations --- ;;; (defun GrM_Start_GrRead ( / done inp) (setq done nil) (while (not done) (princ "\rSelect button or [B]ackground color,[CcRr] (+/- col/row),[J]ustification,[S]etup,[Z]oom (E/+/-),[Q]uit (Space/Enter/Esc/RM) :") (setq inp (vl-catch-all-apply 'grread (list nil 8 0))) (cond ((vl-catch-all-error-p inp)(setq done T)) ;;; point selection ((= (car inp) 3) (setq pt (cadr inp)) (setq id (GrM_GetCell-ID (list tb-x- tb-y+) (list tb-x+ tb-y-) (atoi GrM-NoF-Columns) (atoi GrM-NoF-Rows) pt)) (setq app (nth id app-list) done T)) ;;; nah, just for fun...j/J key cycles Justification ((or (equal inp '(2 106))(equal inp '(2 74)))(cycle_Justification)) ;;; also lots of fun...B key cycles background color ((or (equal inp '(2 66))(equal inp '(2 98)))(cycle_color)) ;;; s or S (setup) ((or (equal inp '(2 115))(equal inp '(2 83)))(GrM_Setup_Dialog_Start)) ; user pressed E of e ((member inp '((2 69)(2 101))) (command "zoom" "e")(GrM_Draw_Toolbar)) ; user pressed + ((equal inp '(2 43)) (vl-cmdf "zoom" "2x")(GrM_Draw_Toolbar)) ; user pressed - ((equal inp '(2 45)) (vl-cmdf "zoom" ".5x")(GrM_Draw_Toolbar)) ; user pressed z or Z ((member inp '((2 122)(2 90))) (vl-cmdf "'zoom" "")(GrM_Draw_Toolbar)) ;;; Enter Space or q/Q key or R-mouse button ((or (equal inp '(2 13)) (equal inp '(2 32)) (equal inp '(2 113)) (equal inp '(2 81)) (equal (car inp) 25)) (setq done T)) ; user pressed D of d - Toggle Debug Mode ((member inp '((2 68)(2 100)))(Toggle_Debug_Mode)) ;;; c (column) smaller (2 99) (GrM_IncTile "bt_nof_columns_min" 0) ((equal inp '(2 99)) (GrM_IncTile "bt_nof_columns_min" 0)(GrM_Draw_Toolbar)) ;;; K (Kolom = column) bigger (2 67) (GrM_IncTile "bt_nof_columns_plus" 0) ((equal inp '(2 67)) (GrM_IncTile "bt_nof_columns_plus" 0)(GrM_Draw_Toolbar)) ;;; r (row) smaller (2 114) (GrM_IncTile "bt_nof_rows_min" 0) ((equal inp '(2 114)) (GrM_IncTile "bt_nof_rows_min" 0)(GrM_Draw_Toolbar)) ;;; R (row) bigger (2 82) (GrM_IncTile "bt_nof_rows_plus" 0) ((equal inp '(2 82)) (GrM_IncTile "bt_nof_rows_plus" 0)(GrM_Draw_Toolbar)) ) ) (redraw) ) ;;; program assumes no self starting routines and start command is "C:" + app name (defun GrM_Start_App (app / fn) (cond ((setq fn (findfile app)) (redraw)(load fn)(eval (read (strcat "(C:" (vl-filename-base app) ")")))) (t (redraw)(princ (strcat "\nUnable to load " (vl-princ-to-string app) " ...bye"))) ) (princ) ) (vl-load-com) (princ "\nGrM - Graphic Menu - Rlx - last update 2025/09/10 (added rlx_sf)") (princ) ;;; (c:GrMs) ;;; Setup Dialog ;;; (C:GrM) ;;; Display Toolbar
    2 points
  8. It was more of a qualifier... While I'm sure they exist, I've never personally met anyone who used Python and couldn't compile .NET Haha
    2 points
  9. you're welcome. The 'secret' when going MDI is using vla commands only.
    2 points
  10. Hola de nuevo, Offsetea.mp4 Dejé una tarea pendiente en este hilo que intentaré cerrar. Adjunto una nueva versión de Offsetea . A continuación, explico el comportamiento y las opciones del comando. Partimos de una lógica de trabajo basada en el enfoque del código de Evgeny Elpanov. De hecho, esta lógica es más fácil de explicar en código que con palabras: proyectar un segmento entre dos vectores guía (definidos por los extremos del segmento y el punto que precede a cada uno de ellos) que se intersecan en un punto, que se convierte en el foco de la proyección. Al proyectar segmentos rectos, el resultado solo puede ser uno. Sin embargo, en el caso de segmentos de arco, ¿qué ocurre si reemplazamos el foco de proyección? En base a esto, se me ocurrieron dos opciones adicionales: el centro y el polo del arco. También consideré la posibilidad de añadir una tercera opción que permitiera al usuario especificar la ubicación del foco en pantalla. Sinceramente, no creo que esto sea útil (espero que al menos una de las otras dos lo sea ). Así, la funcionalidad del comando es la siguiente: - Selección del segmento de polilínea a proyectar: el comando solo funcionará si la polilínea está compuesta por 2 o más segmentos. Si el segmento seleccionado es recto , los vectores guía se definirán por sus extremos y el punto anterior de cada uno (es decir, los segmentos adyacentes). Si uno de los extremos del segmento es también un extremo de la polilínea, el vector guía para ese extremo será la normal a él. Si el segmento es un arco , los vectores guía predeterminados serán los mismos que para los segmentos rectos (propuesta de Evgeny). Sin embargo, aquí es posible cambiar el enfoque del enfoque secante de Evgeny (tecla '2') al enfoque radial (tecla '1') o al enfoque tangente (tecla '3'). En cuanto a las herramientas de control del segmento a proyectar, he implementado un ajuste al estilo GLAVCVS , limitado a los casos posibles para este comando: _end, _mid, _int, _cen, _nod, _ins, _nea. Este ajuste se puede activar o desactivar con F3. La relación entre la posición del cursor y el segmento a proyectar siempre será de seguimiento de segmento en los segmentos rectos. Sin embargo, en los segmentos de arco, puede ser de seguimiento de arco o de cuerda. Para alternar entre ambos, simplemente pulse TAB. El seguimiento de arco está activo mientras el cursor permanece entre los dos vectores de proyección. De lo contrario, cambia automáticamente al seguimiento de cuerda. La diferencia entre ambos radica, por lo tanto, en el comportamiento cuando el cursor se encuentra entre los vectores guía. Estos vectores guía se muestran en pantalla como dos líneas discontinuas rojas. Junto al cursor se muestra texto informativo en tiempo real: Para segmentos rectos (de arriba a abajo): la distancia de desplazamiento desde la ubicación inicial y la longitud del segmento. Para segmentos de arco: distancia de desplazamiento desde la ubicación inicial, radio del arco, longitud del arco y longitud de la cuerda. La visibilidad de esta información se puede activar o desactivar con la tecla "i" . Por último, puedes aumentar o disminuir el tamaño de los indicadores junto al cursor presionando las teclas '+' o '-'. En cuanto al rendimiento del comando, mientras escribía el código, descubrí una mayor variedad de casos de los que inicialmente había pensado. Si el objetivo principal era lograr el seguimiento del segmento de arco según la posición del cursor, creo que este código cubrirá aproximadamente el 90 % de los casos posibles. En los casos donde no sea posible el seguimiento del arco, se realizará a nivel de la cuerda. Espero que a alguien le resulte útil. Offsetea_v2.lsp
    2 points
  11. There was a thread a few days ago about speeding up a LISP to do the same, have look at that for ideas. I think the thread got as far as arcs are tricky to do with LISPs. You could use the flatten command for small drawings. This snippet will filter a selection set to lines or LWPolylines to anything not 0 Z (setq MySS (ssget (list (cons 0 "*TEXT,INSERT,LINE,LWPOLYLINE") '(-4 . "<OR") '(-4 . "*,*,<>") (list 10 0.0 0.0 0.0) '(-4 . "*,*,<>") (list 11 0.0 0.0 0.0) '(-4 . "<>") (cons 38 0) '(-4 . "OR>") )) ; end list, end ssget ) Can be added to the other solutions herein the case that your drawing has a lot of lines / polylines / blocks it speeds it up a bit Link to other thread:
    2 points
  12. As a spline gives two answers the points answer and another with nodes. So any way if you explode the Mleader then you can get at the spline using this. Just need to check that the spline is last entity, tested in Bricscad. A disclaimer not sure if length is correct. I think it is short by length of arrow. Will try to find arrow length. Yep found it. (defun c:wow ( / plent pt len lenar) (setq plent (entsel "\nPick mleader ")) (setq lenar (cdr (assoc 140 (entget (car plent))))) (command "undo" "M") (command "explode" (car plent)) (setq ent (ssname (ssget "L") 0)) (setq len (getpropertyvalue ent "length")) (command "undo" "B") (alert (strcat "Total length is " (rtos (+ lenar len) 2 3))) (princ) ) (c:wow) I think you could do a "I want a length of 100 by drawing something close then move say arrow point till you get approx 100. Via lisp. It would be a two step process explode and move then undo and reset arrow head point.
    2 points
  13. Try an another version (vl-load-com) (defun c:BLOCKINSERT ( / ss blkname acadObj doc mspace n dxf_ent vlaobj pr nb_e scl_blk pt lst_pt nbs ang1 ang2 blk lst itm) (setq ss (ssget '((0 . "*POLYLINE") (-4 . "<NOT") (-4 . "&") (70 . 112) (-4 . "NOT>"))) blkname "Stalb" ) (cond ((and ss (tblsearch "BLOCK" blkname)) (setq acadObj (vlax-get-acad-object) doc (vla-get-activedocument acadObj) mspace (vla-get-modelspace doc) ) (if (null (tblsearch "LAYER" "EL_стълб_НН")) (vlax-put (vla-add (vla-get-layers doc) "EL_стълб_НН") 'color 1) ) (repeat (setq n (sslength ss)) (setq dxf_ent (entget (setq ent (ssname ss (setq n (1- n))))) dxf_210 (cdr (assoc 210 dxf_ent)) lst_pt nil) (setq vlaobj (vlax-ename->vla-object ent) pr -1 ) (repeat (setq nb_e (if (zerop (vlax-get vlaobj 'Closed)) (1+ (fix (vlax-curve-getEndParam vlaobj))) (fix (vlax-curve-getEndParam vlaobj)))) (if (not scl_blk) (progn (initget 6) (setq scl_blk (getreal "\nBlock scale?<1>: ")))) (if (not scl_blk) (setq scl_blk 1.0)) (setq pt (vlax-curve-GetPointAtParam vlaobj (setq pr (1+ pr))) lst_pt (cons pt lst_pt) ) (setq nbs (1- (length lst_pt))) ) (foreach pto lst_pt (if (and (not (zerop nbs)) (not (eq (1+ nbs) (length lst_pt)))) (setq ang1 (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv vlaobj nbs)) ang2 (+ pi (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv vlaobj (1- nbs)))) ) (setq ang1 (if (not (zerop nbs)) (+ pi (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv vlaobj (1- nbs)))) (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv vlaobj nbs)) ) ang2 ang1 ) ) (if (and (zerop nbs) (not (zerop (vlax-get vlaobj 'Closed)))) (setq ang1 (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv vlaobj nbs)) ang2 (+ pi (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv vlaobj (length lst_pt)))) ) ) (if (and (eq (1+ nbs) (length lst_pt)) (not (zerop (vlax-get vlaobj 'Closed)))) (setq ang1 (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv vlaobj nbs)) ) ) (setq nbs (1- nbs) blk (vla-InsertBlock mspace (vlax-3d-point pto) blkname scl_blk scl_blk scl_blk 0.0) ) (vlax-put blk 'Layer "EL_стълб_НН") (vlax-put blk 'Color 3) (setq lst (list (cons "Angel_1" ang1) (cons "Angel_2" ang2))) (foreach x (vlax-invoke blk 'getdynamicblockproperties) (if (setq itm (assoc (vla-get-propertyname x) lst)) (vla-put-value x (vlax-make-variant (cdr itm) (vlax-variant-type (vla-get-value x)))) ) ) ) ) ) ) (prin1) )
    2 points
  14. Agree with @GLAVCVS, with cadr you're getting the X coordinate, not Y coordinate.
    2 points
  15. Is the coordinate order set to Y, X, Z? This could be the error. Try changing cadr to caddr in the line '(setq yval (cadr (assoc 10 edata)))'
    2 points
  16. If its part of your language and not some type of random ascii your using. with a fresh install of windows the language probably needs to be updated in the settings.
    2 points
  17. Hi Start by checking which ANSI setting you have on your new OS. Control Panel → Region → Administrative tab → Change system locale button. The system locale should appear in Spanish and the option 'Version beta: Use UTF-8...' should be unchecked.
    2 points
  18. You could potentially use my Import Block application, which is specifically targeting blocks.
    2 points
  19. You haven't defined "arrowAng" variable and you are using it in (polar) function... Sorry, my mistake - you defined it firstly... [EDIT : You should changle variable "angle" to something different like "ang" as (angle) is AutoLISP function and then you should localize "ang" in main (defun) instead of "angle"...]
    2 points
  20. Change elevation only works if all points are on the same Z elevation. this might be why also flatten isn't working for you. Two things you can do to speed up. Combine all the commands into one call like you did below Command has some type of "lag" but for example lets just call it 100ms this would remove 500ms for each loop. Not to mention all the command line spam. (setvar cmdecho 0) when you sent LastEnt anything created or modified is "behind" LastEnt in the drawing and can be added to a selection set with a simple loop. rather then selecting everything in the drawing and checking against the before selection set to find the new items. (setq zList '()) ;(setq before (ssget "_X")) ;not needed anymore (command "regen" "_.copy" obj "" '(0 0 0) '(0 0 0)) (setq LastEnt (entlast)) ;set right before you create/modify objects. you want to either add to a selection (command "_.explode" newent) (while (setq LastEnt (entnext LastEnt)) ;after entities are created this will add them to a selection set. (ssadd LastEnt newents) ) (foreach e newents -edit typo in code
    2 points
  21. Just to amuse myself, here is a snippet that will flatten simple entities, not sure if that helps you along the way - you can use what code works for 3d polylines, hatches, regions and blocks - might be a bit quicker Command: NewFlatten An edit for later... (defun FlattenLines ( Pt1 Pt2 / MySS MyEnt acount ed) ;;For arcs, attdef, circle, (dimension N/A), Insert, Line, LWPolyline, Mtext, Point, text, ;;Does lines, circles, arcs, ellipses, texts, LWPolylines (if (< (car pt1)(car pt2)) (setq MySS (ssget "_W" pt1 pt2 (list '(-4 . "<OR") '(-4 . "*,*,<>") (list 10 0.0 0.0 0.0) '(-4 . "*,*,<>") (list 11 0.0 0.0 0.0) '(-4 . "<>") (cons 38 0) '(-4 . "OR>") ))) ; end list, ssget, setq (setq MySS (ssget "_C" pt1 pt2 (list '(-4 . "<OR") '(-4 . "*,*,<>") (list 10 0.0 0.0 0.0) '(-4 . "*,*,<>") (list 11 0.0 0.0 0.0) '(-4 . "<>") (cons 38 0) '(-4 . "OR>") ))) ; end list, ssget, setq ) ; end f ; (setq MySS (ssget "_X" (list ; '(-4 . "<OR") ; '(-4 . "*,*,<>") (list 10 0.0 0.0 0.0) ; '(-4 . "*,*,<>") (list 11 0.0 0.0 0.0) ; '(-4 . "<>") (cons 38 0) ; '(-4 . "OR>") ; ))) ; end list, ssget, setq (setq acount 0) (while (< acount (sslength MySS)) (setq MyEnt (ssname MySS acount)) (setq ed (entget MyEnt)) (if (equal (assoc 0 ed) (cons 0 "LWPOLYLINE")) (progn (entmod (setq ed (subst (cons 38 0) (assoc 38 ed) ed) )) ;; Elevation to 0 ) ; end progn (progn (entmod (setq ed (subst (cons 10 (mapcar '* '(1 1 0) (cdr (assoc 10 ed)))) (assoc 10 ed) ed)) ) (entmod (setq ed (subst (cons 11 (mapcar '* '(1 1 0) (cdr (assoc 11 ed)))) (assoc 11 ed) ed)) ) ) ; end progn ) ; end if (setq acount (+ acount 1)) ) ; end while ) (defun SSMouseOrder ( / MyList MySS pt1 pt2 MyEnt SelSS MySS MyDuir acount) ;; Enttypelist: wildcards are OK but not for single selection. ;; Enttypelist in CAPITALS for single entity selection to work. (princ " (Crossing selection, not single picks please). ") ;;Set up LISP (setq MySS (ssadd)) ;; Blank Selelection Set (if (= EntTypeList nil)(setq EntTypeList (list "LINE" "ARC" "CIRCLE")) ) ;; default entity filter (setq MyList (list (cons -4 "<OR") )) ;; Create filter to use with ssget (foreach n EntTypeList (setq MyList (append MyList (list (cons 0 n)) ) ) ) ; end foreach (setq MyList (append MyList (list (cons -4 "OR>")) ) ) (while (setq pt1 (getpoint "Select Objects:"));; Loop to select entities (setq pta pt1) ; record pt1 selected (if (setq MyEnt (car (nentselp pt1))) ;; If 1st point selected was on an entity: Single entity selected (progn (if (ssdel MyEnt MySS) ;; If entity is in selected selection set, delete it (progn (redraw MyEnt 4) ;; Take away highlight ) (progn ;; Else add single entity to selection set (If (member (cdr (assoc 0 (entget MyEnt))) EntTypeList) ;;Check entity type is desired (progn (setq MySS (ssadd MyEnt MySS)) ;; Add to selection set (princ (strcat " 1 Found, ")) ;; Report selection found (redraw MyEnt 3) ;; highlight entity ) ; end progn ) ; end if member ) ; end progn ) ; end if ssdel ) ; end progn (progn ;; Else if clicked point not an entity (setq pt2 (getcorner pt1 " Specify Opposite Corner")) ;;get 2nd point (if (< (car pt1)(car pt2)) ;; Left to right, right to left to determine window or crossing filter (setq SelSS (ssget "_W" pt1 pt2 MyList) ) ;; Get selected entities (setq SelSS (ssget "_C" pt1 pt2 MyList) ) ) (setq acount 0) (if SelSS ;; If anything was selected (progn (princ (strcat " " (rtos (sslength SelSS) 2 0) " Found, ")) ;; report how many entities selected (while (< acount (sslength SelSS)) ;; add entities to selection set (setq MySS (ssadd (ssname SelSS acount) MySS)) (redraw (ssname SelSS acount) 3) ;; Highlight each entity (setq acount (+ acount 1)) ;; Loop counter ) ; end while ) ; end progn ) ; end if SelSS ) ; end progn ) ; end if MyEnt (setq MyDir 0) ;; Work out mouse click directions. Note single selection direction is LL->UR (if (< (cadr pt1)(cadr pt2)) ;; Horizontal (setq MyDir 0) (setq MyDir 1) ) (if (< (car pt1)(car pt2)) ;; Vertical (setq MyDir (+ MyDir 0)) (setq MyDir (+ MyDir 2)) ) ) ; end while (setq acount 0) ;; clear highlights (while (< acount (sslength MySS)) (redraw (ssname MySS acount) 4) (setq acount (+ acount 1)) ) (if (= (sslength MySS) 0) ;; report the selection set and direction or nil if no selection nil (list MySS MyDir) ;; MyDir: 0 BL->TR (or point selection), 1 TL->BR, 2 BR->TL, 3 TR->BL ) (list pta pt2 MyDir) ; MyDir 0, 1-> L to R, 2, 3 -> R to L ) (defun c:NewFlatten ( / Pts) (princ "Selection: ") (setq Pts (SSMouseOrder)) ;;Mouse order returns Selection set points. Used later. (FlattenLines (car Pts) (cadr Pts) ) ;; flatten simple entities ) ; end defun
    2 points
  22. Depends what you are using for obj, if it is an entity name this is a bit quicker: (command "_.copy") (command obj) (command "") (command '(0 0 0) '(0 0 0)) (setq newent (entlast)) (command "_.explode" newent) becomes (command "_.Explode" (setq NewEnt (entmakex (entget obj)) ) ) where obj might be from (car (entsel)) or (ssname MySS number) Might want to look at the number of loops in the snippet you posted
    2 points
  23. Can't really tell you how to optimize code you didn't post, but when people first get into lisp the rely heavily on command because its follows what you would type into the command line. It become apparent in a loop processing 1000's of entity's that its quite inefficient. rather then using entmod or some other way to update model. If flatten doesn' work also try the command Change > elevation > 0
    2 points
  24. (supriFMT (vla-get-TextString obj) T) becomes (supriFMT (vla-get-TextString obj) )
    2 points
  25. I've modified the code so that it also analyzes the files loaded from the profile. ;******************* p o r d e s í a r g o ******************** ;************************ G L A V C V S ************************* ;************************** F E C I T *************************** (defun c:buscaDefunsRepets (/ lstLsps arch nmarch linea lst as nbref separa<->palabras lstDefuns lstRepets tit i dale path escrutArch) (defun separa<->palabras (tx lstCtrs / c p l) (foreach c (vl-string->list tx) (if (member (setq c (chr c)) lstCtrs) (if p (setq l (cons (strcase p T) l) p nil)) (setq p (if p (strcat p c) c)) ) ) (reverse (if p (cons (strcase p T) l) l)) ) (defun escrutArch (nmarch / arch linea lst as nbref dale mirExtens) (defun mirExtens (nmarch) (if (not (wcmatch nmarch "*[.]@@@")) (strcat nmarch ".lsp") nmarch ) ) (if (and (setq nmarch (findfile (mirExtens nmarch))) (setq arch (open nmarch "r"))) (while (setq linea (read-line arch)) (cond ((and (wcmatch linea "*(defun *") (not (wcmatch linea "*\"(defun *,*\"*(defun [*] *,*\"*(defun [*]\"*"))) (setq lst (separa<->palabras linea '(" " "(" "\"")) pos (vl-position "defun" lst) nbref (nth (1+ pos) lst) ) (if lstDefuns (if (not (vl-some ; comprobamos cada defun acumulada '(lambda (v) (if (and (= (car v) nbref) (/= nbref "defun")); si la defun recien leída coincide con alguna de las encontradas anteriormente (if (setq lr (assoc nbref lstRepets)) (setq lstRepets (subst (append lr (list nmarch)) lr lstRepets)) (setq lstRepets (append lstRepets (list (append v (list nmarch))))) ) ) ) lstDefuns ) ) (setq lstDefuns (append lstDefuns (list (list nbref nmarch)))) ) (setq lstDefuns (append lstDefuns (list (list nbref nmarch)))) ) ) ((wcmatch linea "*(load *\")*") (setq lst (separa<->palabras linea '(" " "(" "\""))) (foreach v lst (if dale (setq dale (if (and (not (member (strcase v T) (list "acad2021.lsp" "acad2021doc.lsp"))) (or (= (length (setq lst1 (separa<->palabras v '(".")))) 1) (member (strcase (cadr lst1) T) extens) ) ) (escrutArch v) ) dale nil ) (if (= (strcase v T) "load") (setq dale T) ) ) ) ) ) ) ) (if arch (close arch)) ) (setq lstLsps (list "acad2021.lsp" "acad2021doc.lsp" "acadddd.lsp") extens '("lsp")) (foreach lsp lstLsps (if (and (findfile lsp) (setq arch (open (setq nmarch (findfile lsp)) "r"))) (escrutArch nmarch) ) ) (if arch (close arch)) (setq i 0) (while (setq nmarch (vl-registry-read (strcat "HKEY_CURRENT_USER\\" (vlax-product-key) "\\Profiles\\" (getvar "CPROFILE") "\\Dialogs\\Appload\\Startup") (strcat (itoa (setq i (1+ i))) "StartUp"))) (escrutArch nmarch) ) (if lstRepets (if (setq arch (open (setq nmarch (strcat (VL-REGISTRY-READ "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders" "Personal") "\\informe.txt")) "w")) (foreach lr lstRepets (princ (strcat (if (not tit) (setq tit "FUNCTIONS DEFINED MULTIPLE TIMES:\n") "") "\n Function NAME \'" (car lr) "\' in:\n") arch) (foreach path (cdr lr) (princ (strcat "\t" path "\n") arch) ) ) ) ) (if arch (progn (close arch) (startapp "notepad" nmarch))) (princ) ) If after trying this nothing different comes out, then the problem isn't due to overlapping code. In that case, I would look at the system variables and any reactors your LISPs generate when loading.
    2 points
  26. ((= otyp "MTEXT")(print (vla-get-TextString obj))(vla-put-TextString obj (supriFMT (vla-get-TextString obj)))) ; AcDbMText It looks like it worked! Thank you all! I'll test it again.
    1 point
  27. I'll put this one here for later. I have a suspicion that the text is still there, just not visible - very small perhaps. This will show all the mtext values (first 256 characters anyway) in the drawing. Run it after your unformat just to confirm that the texts have been deleted or are just not visible. (defun c:GrabTexts ( / MySS acount MyEnt) (setq myss (ssget "_X" '((0 . "mtext")))) (setq acount 0) (while (< acount (sslength myss)) (setq Myent (ssname Myss acount)) (princ "\n")(princ (assoc 1 (entget MyEnt))) (setq acount (+ acount 1)) ) ; end while )
    1 point
  28. The 'T' argument in the call to 'supriFMT' is unnecessary. That's why it returns 'too many arguments'. You should delete it. Find the line where you replaced LM:UnFormat with SupriFMT and notice there's a 'T': you should delete it.
    1 point
  29. PS: You should also remove the T argument from the call to 'supriFMT'.
    1 point
  30. Paste this function into your code. (defun supriFMT (tx / rtx separa<->palabras) (defun separa<->palabras (tx lstCtrs / c p l) (foreach c (vl-string->list tx) (if (member (setq c (chr c)) lstCtrs) (if p (setq l (cons p l) p nil)) (setq p (if p (strcat p c) c)) ) ) (reverse (if p (cons p l) l)) ) (foreach v (separa<->palabras tx '(";" "{" "}" )) (if (not (wcmatch v "\\*")) (setq rtx (strcat (if rtx rtx "") (car (separa<->palabras v '("\\" ))))) ) ) ) Then replace 'LM:UnFormat' with 'supriFMT' inside the '((= otyp "MTEXT")' clause.
    1 point
  31. So we can force the height to be something like this - just as an example for your sample drawings above, see if it makes your text visible again (defun c:UNFORMAT ( / ss ssl cnt en xxobj otyp txr ntx MyText) ;;;;;;;;;;;;; mAssoc;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun mAssoc ( key lst / result ) ;; Lee Mac (foreach x lst (if (= key (car x)) (setq result (cons (cdr x) result)) ) ) (reverse result) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; UnFormat MText, MLeader, Table - strip formatting contol codes from texts ; ; based on Lee Mac's UnFormat string - www.lee-mac.com/unformatstring.html ; CAD Studio, 2018, www.cadstudio.cz www.cadforum.cz ; ; (vl-load-com) ;;-------------------=={ UnFormat String }==------------------;; ;; ;; ;; Returns a string with all MText formatting codes removed. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; str - String to Process ;; ;; mtx - MText Flag (T if string is for use in MText) ;; ;;------------------------------------------------------------;; ;; Returns: String with formatting codes removed ;; ;;------------------------------------------------------------;; ;;SP ASSUMING LEE MAC PART WORKS. IT USUALLY DOES. (defun LM:UnFormat ( str mtx / _replace rx ) (defun _replace ( new old str ) (vlax-put-property rx 'pattern old) (vlax-invoke rx 'replace str new) ) (if (setq rx (vlax-get-or-create-object "VBScript.RegExp")) (progn (setq str (vl-catch-all-apply (function (lambda ( ) (vlax-put-property rx 'global actrue) (vlax-put-property rx 'multiline actrue) (vlax-put-property rx 'ignorecase acfalse) (foreach pair '( ("\032" . "\\\\\\\\") (" " . "\\\\P|\\n|\\t") ("$1" . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]") ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);") ("$1$2" . "\\\\(\\\\S)|[\\\\](})|}") ("$1" . "[\\\\]({)|{") ) (setq str (_replace (car pair) (cdr pair) str)) ) (if mtx (_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str)) (_replace "\\" "\032" str) ) ) ) ) ) (vlax-release-object rx) (if (null (vl-catch-all-error-p str)) str ) ) ) ) ;; End LM:Unformat ;----------------- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun doUnformatTable (table / rowCounter colCounter) (setq rowCounter (vla-Get-Rows table)) (repeat rowCounter (setq rowCounter (1- rowCounter)) (setq colCounter (vla-Get-Columns table)) (repeat colCounter (setq colCounter (1- colCounter)) (setq cellType (vla-GetCellType table rowCounter colCounter)) (if (= cellType acTextCell)(progn (setq cellText (vla-GetText table rowCounter colCounter)) (if (/= cellText "") (vla-SetText table rowCounter colCounter (LM:UnFormat cellText T))) )) ; end if, end if ) ; rep ) ; rep ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; End Sub routines (princ "\nSelect MTEXTs/DIMENSIONs/MLEADERs/TABLEs: ") (setq ss (ssget '((0 . "MTEXT,DIMENSION,MULTILEADER,ACAD_TABLE")))) (if ss (progn (setq acount 0) (while (< acount (sslength ss)) (setq ed (ssname ss acount)) (if (or (equal (assoc 0 (entget ed)) '(0 . "MTEXT")) (equal (assoc 0 (entget ed)) '(0 . "DIMENSION")) (equal (assoc 0 (entget ed)) '(0 . "MULTILEADER")) ) ; endor (progn (setq Mytexts (mAssoc 1 (entget ed))) (foreach n Mytexts (entmod (subst (cons 1 (lm:Unformat n T)) (cons 1 n) (entget ed)) ) ) (setq Mytexts (mAssoc 3 (entget ed))) ;; extend mtexts (foreach n Mytexts (entmod (subst (cons 3 (lm:Unformat n T)) (cons 3 n) (entget ed)) ) ) (setq Mytexts (mAssoc 40 (entget ed))) ;; extend mtexts (foreach n Mytexts (entmod (subst (cons 40 25) (cons 40 n) (entget ed)) ) ) ) ; end progn mtext (progn ; tables ((= otyp "ACAD_TABLE")(doUnformatTable (vlax-ename->vla-object ed))) ; AcDbTable ) ) (setq acount (+ acount 1)) ) ; end while ) ; end progn, ss ) ; end if ss )
    1 point
  32. Did you reset AutoCAD to defaults as I suggested a long time ago?
    1 point
  33. Try this, taking away the text modification part: It should put the original text + format codes one one command line, and the next unformatted, see if it gets that far. It won't change any of the drawing. (defun c:UNFORMAT ( / ss ssl cnt en xxobj otyp txr ntx MyText) ;;;;;;;;;;;;; mAssoc;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun mAssoc ( key lst / result ) ;; Lee Mac (foreach x lst (if (= key (car x)) (setq result (cons (cdr x) result)) ) ) (reverse result) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; UnFormat MText, MLeader, Table - strip formatting contol codes from texts ; ; based on Lee Mac's UnFormat string - www.lee-mac.com/unformatstring.html ; CAD Studio, 2018, www.cadstudio.cz www.cadforum.cz ; ; (vl-load-com) ;;-------------------=={ UnFormat String }==------------------;; ;; ;; ;; Returns a string with all MText formatting codes removed. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; str - String to Process ;; ;; mtx - MText Flag (T if string is for use in MText) ;; ;;------------------------------------------------------------;; ;; Returns: String with formatting codes removed ;; ;;------------------------------------------------------------;; ;;SP ASSUMING LEE MAC PART WORKS. IT USUALLY DOES. (defun LM:UnFormat ( str mtx / _replace rx ) (defun _replace ( new old str ) (vlax-put-property rx 'pattern old) (vlax-invoke rx 'replace str new) ) (if (setq rx (vlax-get-or-create-object "VBScript.RegExp")) (progn (setq str (vl-catch-all-apply (function (lambda ( ) (vlax-put-property rx 'global actrue) (vlax-put-property rx 'multiline actrue) (vlax-put-property rx 'ignorecase acfalse) (foreach pair '( ("\032" . "\\\\\\\\") (" " . "\\\\P|\\n|\\t") ("$1" . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]") ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);") ("$1$2" . "\\\\(\\\\S)|[\\\\](})|}") ("$1" . "[\\\\]({)|{") ) (setq str (_replace (car pair) (cdr pair) str)) ) (if mtx (_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str)) (_replace "\\" "\032" str) ) ) ) ) ) (vlax-release-object rx) (if (null (vl-catch-all-error-p str)) str ) ) ) ) ;; End LM:Unformat ;----------------- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun doUnformatTable (table / rowCounter colCounter) (setq rowCounter (vla-Get-Rows table)) (repeat rowCounter (setq rowCounter (1- rowCounter)) (setq colCounter (vla-Get-Columns table)) (repeat colCounter (setq colCounter (1- colCounter)) (setq cellType (vla-GetCellType table rowCounter colCounter)) (if (= cellType acTextCell)(progn (setq cellText (vla-GetText table rowCounter colCounter)) (if (/= cellText "") (vla-SetText table rowCounter colCounter (LM:UnFormat cellText T))) )) ; end if, end if ) ; rep ) ; rep ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; End Sub routines (princ "\nSelect MTEXTs/DIMENSIONs/MLEADERs/TABLEs: ") (setq ss (ssget '((0 . "MTEXT,DIMENSION,MULTILEADER,ACAD_TABLE")))) (if ss (progn (setq acount 0) (while (< acount (sslength ss)) (setq ed (ssname ss acount)) (if (or (equal (assoc 0 (entget ed)) '(0 . "MTEXT")) (equal (assoc 0 (entget ed)) '(0 . "DIMENSION")) (equal (assoc 0 (entget ed)) '(0 . "MULTILEADER")) ) ; endor (progn (setq Mytexts (mAssoc 1 (entget ed))) (foreach n Mytexts ;; (entmod (subst (cons 1 (lm:Unformat n T)) (cons 1 n) (entget ed)) ) (princ "\n")(princ "\n")(princ n)(princ "\n")(princ (lm:Unformat n T)) ) ;; (setq Mytexts (mAssoc 3 (entget ed))) ;; extend mtexts ;; (foreach n Mytexts ;; (entmod (subst (cons 3 (lm:Unformat n T)) (cons 3 n) (entget ed)) ) ;; ) ) ; end progn mtext (progn ; tables ((= otyp "ACAD_TABLE")(doUnformatTable (vlax-ename->vla-object ed))) ; AcDbTable ) ) (setq acount (+ acount 1)) ) ; end while ) ; end progn, ss ) ; end if ss )
    1 point
  34. This is an interesting topic. I edited my code to recursively search any file loaded with 'load' at all nesting levels. Try it. However, reviewing your explanation of the problem, I checked the MTEXT entity lists and saw that it forces the font to change to ISOCTEUR or SIMPLEX. I don't think these fonts support Cyrillic. Perhaps for this reason, when trying to replace the codes, it returns an empty string, which AutoCAD interprets as deleting the MTEXT.
    1 point
  35. Edited: See if this works. I have put the other routines as sub routines (LM:Unformat and DoUnformatTable). Changed the text modifying about so it uses entmod instead of vla (personal preference) Try it and see if it works - if it does then the unformat part (Lee Macs) is working as expected (it usually does) and there is something you'll be wanting to look at in the code you added. (defun c:UNFORMAT ( / ss ssl cnt en xxobj otyp txr ntx MyText) ;;;;;;;;;;;;; mAssoc;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun mAssoc ( key lst / result ) ;; Lee Mac (foreach x lst (if (= key (car x)) (setq result (cons (cdr x) result)) ) ) (reverse result) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; UnFormat MText, MLeader, Table - strip formatting contol codes from texts ; ; based on Lee Mac's UnFormat string - www.lee-mac.com/unformatstring.html ; CAD Studio, 2018, www.cadstudio.cz www.cadforum.cz ; ; (vl-load-com) ;;-------------------=={ UnFormat String }==------------------;; ;; ;; ;; Returns a string with all MText formatting codes removed. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; str - String to Process ;; ;; mtx - MText Flag (T if string is for use in MText) ;; ;;------------------------------------------------------------;; ;; Returns: String with formatting codes removed ;; ;;------------------------------------------------------------;; ;;SP ASSUMING LEE MAC PART WORKS. IT USUALLY DOES. (defun LM:UnFormat ( str mtx / _replace rx ) (defun _replace ( new old str ) (vlax-put-property rx 'pattern old) (vlax-invoke rx 'replace str new) ) (if (setq rx (vlax-get-or-create-object "VBScript.RegExp")) (progn (setq str (vl-catch-all-apply (function (lambda ( ) (vlax-put-property rx 'global actrue) (vlax-put-property rx 'multiline actrue) (vlax-put-property rx 'ignorecase acfalse) (foreach pair '( ("\032" . "\\\\\\\\") (" " . "\\\\P|\\n|\\t") ("$1" . "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]") ("$1$2/$3" . "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);") ("$1$2" . "\\\\(\\\\S)|[\\\\](})|}") ("$1" . "[\\\\]({)|{") ) (setq str (_replace (car pair) (cdr pair) str)) ) (if mtx (_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str)) (_replace "\\" "\032" str) ) ) ) ) ) (vlax-release-object rx) (if (null (vl-catch-all-error-p str)) str ) ) ) ) ;; End LM:Unformat ;----------------- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun doUnformatTable (table / rowCounter colCounter) (setq rowCounter (vla-Get-Rows table)) (repeat rowCounter (setq rowCounter (1- rowCounter)) (setq colCounter (vla-Get-Columns table)) (repeat colCounter (setq colCounter (1- colCounter)) (setq cellType (vla-GetCellType table rowCounter colCounter)) (if (= cellType acTextCell)(progn (setq cellText (vla-GetText table rowCounter colCounter)) (if (/= cellText "") (vla-SetText table rowCounter colCounter (LM:UnFormat cellText T))) )) ; end if, end if ) ; rep ) ; rep ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; End Sub routines (princ "\nSelect MTEXTs/DIMENSIONs/MLEADERs/TABLEs: ") (setq ss (ssget '((0 . "MTEXT,DIMENSION,MULTILEADER,ACAD_TABLE")))) (if ss (progn (setq acount 0) (while (< acount (sslength ss)) (setq ed (ssname ss acount)) (if (or (equal (assoc 0 (entget ed)) '(0 . "MTEXT")) (equal (assoc 0 (entget ed)) '(0 . "DIMENSION")) (equal (assoc 0 (entget ed)) '(0 . "MULTILEADER")) ) ; endor (progn (setq Mytexts (mAssoc 1 (entget ed))) (foreach n Mytexts (entmod (subst (cons 1 (lm:Unformat n T)) (cons 1 n) (entget ed)) ) ) (setq Mytexts (mAssoc 3 (entget ed))) ;; extend mtexts (foreach n Mytexts (entmod (subst (cons 3 (lm:Unformat n T)) (cons 3 n) (entget ed)) ) ) ) ; end progn mtext (progn ; tables ((= otyp "ACAD_TABLE")(doUnformatTable (vlax-ename->vla-object ed))) ; AcDbTable ) ) (setq acount (+ acount 1)) ) ; end while ) ; end progn, ss ) ; end if ss )
    1 point
  36. PS: The command will analyze the code in the files in the 'lstLsps' list and any files loaded from them. However, it will not analyze any files loaded from the latter. That is, it will not analyze code loaded beyond the second level of nesting. But I think that should be enough.
    1 point
  37. Try this as an experiment: (Defun C:LMUnF ( / ) (Load " -NIKON LISP FILEPATH- \\LM-Unformat.lsp") (c:UNFORMAT)(princ) ) Where -Nikon Lisp Filepath is where the file is saved, LM-Unformat.lsp is the file name. It should load this file when you run 'LMUnf' - and since it is the latest loaded will take precedence over anything loaded previously, Second option is to modify the text using entmod perhaps
    1 point
  38. I agree with StevenP. I've tested Lee Mac's code in the 2021 version, and it works fine in your drawing. It's probably some interference between your loaded Lisp code.
    1 point
  39. A couple of suggestions. ; (prompt “\nSelect the SET TEXT or MTEXT: “) (setq set (car (entsel “\nSelect the SET TEXT or MTEXT: “))) If you want to force a selection of a certain type use SSGET as you have done in your code further down. (setq set (ssname (ssget ‘((0 . “TEXT,MTEXT”))) 0)) Better still have a look at this link. https://www.lee-mac.com/ssget.html Don't use "set", it is a reserved word and is used in lisp to do just that "set a value" rather than setq. Will try to make some time to look at your code.
    1 point
  40. If you haven't solved it yet, there's another possibility: Replace '(setq en (ssname ss cnt))' with '(setq en (ssname ss cnt)) ex en)' Load the code and run it again. Then, type '(entget ex)' on the command line. If it returns the entity list, see if '(60 . 1)' appears anywhere.
    1 point
  41. Works in AutoCAD 2026. Try restarting AutoCAD, then a reset to defaults if that doesn't work.
    1 point
  42. It was working OK for me in your sample drawing - I am using 2022 though but would expect any changes in 2021 to be carried through to that. Looking at the LISP, there is nothing in there to delete any texts, try loading it last in case there is another LISP loaded with the same name as some of the sub routines and try again maybe
    1 point
  43. @mhy3sx it calculate a2 as a trapezoid , because it is not a rectangle , short side are not parallel to be or no tobe a trapezoid.dwg
    1 point
  44. One of the others ways to do this is to use a lisp and break the string into individual bits. As you have a "-" as a common item in the string you can blow it apart and rejoin. Thanks to Lee-mac parse lsp. Something like this. ; Parse string to a list ny Lee-mac (defun csv->lst (str ans / pos ) (if (setq pos (vl-string-position ans str)) (cons (substr str 1 pos) (csv->lst (substr str (+ pos 2)) ans)) (list str) ) ) (setq str "XXX-ZINC-XX-XX-DR-C-01000_S278 Sections") ; use (getvar 'dwgname) (setq newstr "" x 0) (setq ans (csv->lst str 45)) (repeat (- (length ans) 2) (setq newstr (strcat newstr (nth x ans) "-")) (setq x (1+ x)) ) (setq newstr (strcat newstr (nth x ans))) Ps ; tab 9 space 32 (chr 32) comma 44 semicolon 59 slash / 47 - 45
    1 point
  45. Maybe something in my post or the one of Lee Mac's I linked...
    1 point
  46. @maahee It is not clear what you want to calculate. Please respond to the following questions. Should the program be able to handle lines? ... lwpolylines without arc segments? ... lwpolylinese with arc segments? arc objects? circle objects? If the open/close property of a polyline is "open" sould the polyline be considered a closed shape defined by a line segment from the last vertex to the first vertex? The code in your last post dows nothing if the object is not a line. If it is a line it adds a dim line but does not identify the "center".
    1 point
  47. If you make a Text menu item then can have sub menu in a pop up and set the text height and style to use then call text, so could have multiple Text select.
    1 point
  48. You can have lisp in a CUI I have set a variable then load a lisp using that variable. Simple answer ^c^C^p(setvar 'textsize (getreal "\nEnter text height "))(load "mylisp") There is a textbox input trying to remember it someone else will post. It is a built in function. Or can do something like this, another DCL example is at Afralisp. ^c^c^p(if (not AH:getvalsm)(load "Multi Getvals.lsp"))(setq ans (AH:getvalsm (list "Enter text height " "height" 5 4 "2.5")))(load "mylisp") Multi GETVALS.lsp
    1 point
  49. I just started to do some VB in SolidWorks. So this is my first try: Option Explicit Dim swModel As SldWorks.ModelDoc2 Sub main() Dim aLine As SldWorks.SketchSegment Dim line As Object Set swModel = Application.SldWorks.ActiveDoc swModel.SketchManager.Insert3DSketch True 'tetrahedron side length Dim L As Double 'doh... number of segments Dim segs As Integer L = 10 segs = 22 Dim Xa, Ya, Za As Double 'point A is in the origin Xa = 0 Ya = 0 Za = 0 Dim Xb, Yb, Zb As Double 'point B is along Ox Xb = L Yb = 0 Zb = 0 Dim Xc, Yc, Zc As Double 'point C is in xOy plane Xc = L / 2# Yc = L * Sqrt(3) / 2# Zc = 0 Dim Xv, Yv, Zv As Double ' point V is right above the centroid of ABC Xv = L / 2# Yv = L * Sqrt(3) / 6 Zv = L * Sqrt(6) / 3# Dim i As Integer 'point1 walks along AV Dim Dx1, Dy1, Dz1, Dx2, Dy2, Dz2 As Double Dx1 = (Xv - Xa) / segs Dy1 = (Yv - Ya) / segs Dz1 = (Zv - Za) / segs 'point2 walks along BC Dx2 = (Xc - Xb) / segs Dy2 = (Yc - Yb) / segs Dz2 = (Zc - Zb) / segs 'point3 walks along BV Dim Dx3, Dy3, Dz3, Dx4, Dy4, Dz4 As Double Dx3 = (Xv - Xb) / segs Dy3 = (Yv - Yb) / segs Dz3 = (Zv - Zb) / segs 'point4 walks along CA Dx4 = (Xa - Xc) / segs Dy4 = (Ya - Yc) / segs Dz4 = (Za - Zc) / segs 'point5 walks along CV Dim Dx5, Dy5, Dz5, Dx6, Dy6, Dz6 As Double Dx5 = (Xv - Xc) / segs Dy5 = (Yv - Yc) / segs Dz5 = (Zv - Zc) / segs 'point6 walks along AB Dx6 = (Xb - Xa) / segs Dy6 = (Yb - Ya) / segs Dz6 = (Zb - Za) / segs 'draw those lines: For i = 0 To segs 'lines between point1 and point2: Set aLine = Draw(Xa + Dx1 * i, Ya + Dy1 * i, Za + Dz1 * i, Xb + Dx2 * i, Yb + Dy2 * i, Zb + Dz2 * i) 'the lines between point3 and point4: Set aLine = Draw(Xb + Dx3 * i, Yb + Dy3 * i, Zb + Dz3 * i, Xc + Dx4 * i, Yc + Dy4 * i, Zc + Dz4 * i) 'the segments between point5 and point6 Set aLine = Draw(Xc + Dx5 * i, Yc + Dy5 * i, Zc + Dz5 * i, Xa + Dx6 * i, Ya + Dy6 * i, Za + Dz6 * i) Next i ' Close sketch swModel.SketchManager.InsertSketch True 'swModel.ClearSelection2 True End Sub Function Draw(X1, Y1, Z1, X2, Y2, Z2 As Double) As SldWorks.SketchSegment Set Draw = swModel.SketchManager.CreateLine(X1, Y1, Z1, X2, Y2, Z2) End Function
    1 point
  50. Wow - I'm truly flattered by this thread! Many thanks guys, I appreciate your kind compliments & commendations Ha! I'm nowhere near in the league of the late & great John McCarthy! Where programming is concerned, I have approximately 4 years experience in writing AutoLISP & Visual LISP applications (including DCL & ObjectDBX based programs); I also have experience in relatively basic web design (HTML/CSS - I coded my own site from the ground up), and have minimal experience in C/C++/C#/Python - just enough to write console programs! As far as my background, I studied a mathematics degree which forced me to develop a strictly logical mindset and consequently my learning of the various customisation programming languages progressed relatively quickly.
    1 point
×
×
  • Create New...