dexus Posted December 6, 2023 Posted December 6, 2023 (edited) Here is an updated/latest version, which resets the cmlscale and resets the linetype after exploding. (defun c:slot ( / cmd dict ent lastent obj pl prev ss vals vars *error*) ;; ----------------------------------------------------------- ;; ;; Draw Slot 29-11-2023 by dexus ;; ;; ----------------------------------------------------------- ;; ;; https://www.theswamp.org/index.php?topic=58809 ;; ;; ----------------------------------------------------------- ;; ;; Draw a slot with preview ;; ;; Prompts user for radius, startpoint and endpoint ;; ;; Global variable 'slot:rad' for last radius ;; ;; ----------------------------------------------------------- ;; ;; Version 1.0 - Initial release ;; ;; Version 1.1 - Set cmlscale temporarily, thanks Ingpro ;; ;; Version 1.2 - Reset cmlstyle after function is finished ;; ;; ----------------------------------------------------------- ;; (defun *error* (msg) (and vals (mapcar (function setvar) vars vals)) (or (wcmatch (strcase msg t) "*break,*cancel*,*exit*") (princ (strcat "\n* Error: " msg))) (princ) ) (setq vars '("cmdecho" "peditaccept" "qaflags" "cmlscale" "cmlstyle") vals (mapcar (function getvar) vars) dict (cdar (dictsearch (namedobjdict) "acad_mlinestyle"))) (mapcar (function setvar) vars '(0 1 0 1)) (initget 6) (if (cond ((not (setq slot:rad (cond ((getdist (if (numberp slot:rad) (strcat "\nSpecify slot radius <" (rtos slot:rad 2 3) ">: ") "\nSpecify slot radius: "))) (slot:rad) ) )) (princ "\nNo slot radius chosen.") nil ) ((not (setq ent ; Create MLineStyle (list '(0 . "MLINESTYLE") '(100 . "AcDbMlineStyle") '(2 . "SLOT") '(70 . 1088) '(3 . "") '(51 . 1.5708) '(52 . 1.5708) '(71 . 2) (cons 49 slot:rad) '(62 . 256) '(6 . "BYLAYER") (cons 49 (- slot:rad)) '(62 . 256) '(6 . "BYLAYER") ) ))) ((setq prev (dictsearch dict "slot")) ; If Slot exists, entmod (entmod (cons (assoc -1 prev) ent)) t ) ((dictadd dict "SLOT" (entmakex ent)) ; Otherwise create Slot t ) ((princ "\nCreation of mline failed...") nil) ) (progn (setq lastent (entlast) cmd (getvar 'cmdecho)) (setvar 'cmdecho 0) (princ "\nChoose first point: ") (command "_mline" "_j" "_z" "_st" "SLOT" "\\") ; Create Mline (princ "\nChoose end point: ") (command "\\" "") ; Get endpoint of Mline (if (not (equal lastent (setq obj (entlast)))) (progn (setq lastent (entlast) ss (ssadd)) (command "_explode" obj) ; Explode Mline (while (> (getvar "cmdactive") 0) (command "")) (while (setq lastent (entnext lastent)) (ssadd lastent ss)) (setq lastent (entlast)) (vl-cmdf "_.pedit" "_m" ss "" "_j" "0.0" "") ; Convert to polyline (while (setq lastent (entnext lastent)) (and (setq pl (entget lastent)) (entmod (subst '(6 . "BYLAYER") (assoc 6 pl) pl)) ) ) (setq ss nil) ) ) (setvar 'cmdecho cmd) ) ) (mapcar (function setvar) vars vals) (princ) ) Edited December 6, 2023 by dexus Quote
Nikon Posted December 6, 2023 Posted December 6, 2023 Code returns the value cmlscale 20, but the subsequent MLINE call creates a MLINE with the slot style... Quote
dexus Posted December 6, 2023 Posted December 6, 2023 31 minutes ago, Nikon said: Code returns the value cmlscale 20, but the subsequent MLINE call creates a MLINE with the slot style... That's a good point, I've changed the code on theswamp to reset the MLine style after the code is finished. You can find it here: https://www.theswamp.org/index.php?topic=58809.0 Thanks for the input! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.