Jump to content

replace prompt with select all (mtext)


jt6572

Recommended Posts

hi all,

i have compiled 5 separate lisps (from sources such as here) into one so that i can change text to how it needs to be presented.

 

it is a compilation of

1. change all text in layer "x" to layer "y" and make annotative

2. change all text to mtext

3. make mtext width = 0

4. give all mtext a mask

5. purge all.

 

(this is needed for exporting road chainages from 12d).

 

it all works great given my limited lisp knowledge, but when it is run i still need to enter manually in the sequence enter, all, enter, enter, all, enter... you get the drift...

 

because i have such limited ability with lisp, i am unable to replace the prompts with a ssget "X" (or...something!) to select all objects (or even just the mtext - either is fine).

 

could someone please have a look at all the prompts and show me what i need to do so that everything just runs without input?

i dont mind requiring input for the mask (would be cool if it was set to eg background, offset 1.25) but that is likely too far in depth for now.

 

thank you!! :)

 

ps: i am also rubbish with scripts (for some reason... havent spent time on them) and using:

 

CTRL

 

A

 

A

 

A

 

 

 

... didnt work. thought a new line was equivalent to "enter"...

 

 

(defun c:CTRL ()



(c:CHN)
(c:T2M)
(c:mtwidth)
(c:bmask)
(c:PURR)
)



;=====================================================================
;; 12D CONTROL LINE TEXT


(defun c:CHN () ;; SELECTS ALL TEXT ON LAYER "MRR_UNKNOWN" AND CHANGES IT TO MR_TXT_050
(command "CHPROP" (ssget "X" (list (cons 8 "MRR_UNKNOWN"))) "" "LA" "MR_TXT_050" "")
(command "CHPROP" "all" "" "A" "Y" "" ""))

;=====================================================================
(defun C:T2M ; = Text or Attribute Definition to 1-line Mtext, retaining Justification
 (/ *error* cmde doc tss inc tent tobj tins tjust)

 (defun *error* (errmsg)
   (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
     (princ (strcat "\nError: " errmsg))
   ); if
   (vla-endundomark doc)
   (setvar 'cmdecho cmde)
   (princ)
 ); defun - *error*

 (setq
   cmde (getvar 'cmdecho)
   doc (vla-get-activedocument (vlax-get-acad-object))
 ); setq
 (vla-startundomark doc)
 (setvar 'cmdecho 0)
 (ssget "_X")
;;  (prompt "\nTo change Text/Attribute to 1-line Mtext, preserving Justification,")
 (if (setq tss (ssget "_:L" '((0 . "TEXT,ATTDEF"))))
   (repeat (setq inc (sslength tss))
     (setq
       tent (ssname tss (setq inc (1- inc)))
       tobj (vlax-ename->vla-object tent)
       tins (vlax-get tobj 'TextAlignmentPoint)
       tjust (vla-get-Alignment tobj)
     ); setq
     (cond
       ((= tjust 0) (setq tjust 7 tins (vlax-get tobj 'InsertionPoint))); Left
       ((< tjust 3) (setq tjust (+ tjust 7))); 1/2 [Center/Right] to 8/9
       ((= tjust 4) (setq tjust 5)); Middle to Middle-Center
       ((member tjust '(3 5)); Aligned/Fit
         (setq
           tjust 8 ; to Bottom-Center
           tins (mapcar '/ (mapcar '+ (vlax-get tobj 'InsertionPoint) tins) '(2 2 2))
             ; with new insertion point
         ); setq
       ); Aligned/Fit
       ((setq tjust (- tjust 5))); all vertical-horizontal pair justifications
     ); cond
     (if (= (vla-get-TextString tobj) "") (vla-put-TextString tobj (vla-get-TagString tobj)))
       ;; if no default content, disappears after TXT2MTXT: impose Tag value for it
       ;; [to use Prompt value instead, change end to (vla-get-PromptString tobj).]
     (command "_.txt2mtxt" tent ""); convert, then
     (setq tobj (vlax-ename->vla-object (entlast))); replace Text as object with new Mtext
     (vla-put-AttachmentPoint tobj tjust); original Text's justification [or equiv.]
     (vlax-put tobj 'InsertionPoint tins); original Text's insertion
   ); repeat
 ); if
 (setvar 'cmdecho cmde)
 (vla-endundomark doc)
 (princ)
); defun -- T2M
(vl-load-com)
(prompt "\nType T2M to change Text/Attribute-Definitions to 1-line Mtext, preserving Justification.")

(defun c:mtwidth (/ ss i sn)
 (vl-load-com)
 (if (setq ss (ssget "_:L" '((0 . "MTEXT"))))
   (repeat (setq i (sslength ss))
     (vla-put-width (vlax-ename->vla-object (ssname ss (setq i (1- i))))
       0. ))
   (princ)
 )
 (princ)
)








;;------------------------------=={ Mask }==----------------------------;;
;;                                                                      ;;
;;  This program allows the user to manipulate all available properties ;;
;;  of the background mask for a selection of Multiline Text (MText),   ;;
;;  Multileader (MLeader), and Dimension objects.                       ;;
;;                                                                      ;;
;;  Upon calling the program with the syntax 'bmask', the user is       ;;
;;  prompted to make a selection of MText, MLeaders and/or Dimensions   ;;
;;  for which to alter the background mask settings.                    ;;
;;                                                                      ;;
;;  Following a valid selection, the user is presented with a dialog    ;;
;;  interface, enabling the user to toggle the use of a background      ;;
;;  mask, change the mask offset (not applicable to dimensions), and    ;;
;;  change the mask colour for all objects in the selection             ;;
;;  simultaneously.                                                     ;;
;;                                                                      ;;
;;  The background mask for dimensions will be applied as a dimension   ;;
;;  style override unless the settings held by the dimension style      ;;
;;  associated with the dimension match those selected by the user.     ;;
;;                                                                      ;;
;;  The background mask offset is only applicable to MText & MLeader    ;;
;;  objects and will therefore have no effect on selected Dimensions.   ;;
;;                                                                      ;;
;;----------------------------------------------------------------------;;
;;  Author:  Lee Mac, Copyright © 2012  -  www.lee-mac.com              ;;
;;----------------------------------------------------------------------;;
;;  Version 1.0    -    2012-04-16                                      ;;
;;                                                                      ;;
;;  - First release.                                                    ;;
;;----------------------------------------------------------------------;;
;;  Version 1.1    -    2013-02-06                                      ;;
;;                                                                      ;;
;;  - Changed command syntax to 'bmask' since 'mask' is an existing     ;;
;;    command in AutoCAD Civil 3D.                                      ;;
;;----------------------------------------------------------------------;;
;;  Version 1.2    -    2016-05-22                                      ;;
;;                                                                      ;;
;;  - Program restructured to enable dialog bypass.                     ;;
;;  - Added ability to mask dimensions.                                 ;;
;;----------------------------------------------------------------------;;
;;  Version 1.3    -    2016-05-23                                      ;;
;;                                                                      ;;
;;  - Defined dedicated mask:selection function to facilitate the       ;;
;;    creation of custom programs which bypass the program dialog.      ;;
;;----------------------------------------------------------------------;;

(defun c:bmask ( / *error* key sel tmp )
   
   (defun *error* ( msg )
       (if (< 0 dch)
           (setq dch (unload_dialog dch))
       )
       (if (= 'file (type des))
           (close des)
       )
       (if (and (= 'str (type dcl)) (findfile dcl))
           (vl-file-delete dcl)
       )
       (mask:endundo (mask:acdoc))
       (if (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*"))
           (princ (strcat "\nError: " msg))
       )
       (princ)
   )

   (setq key "LMac\\mask")
   (if (and (setq sel (mask:selection "\nSelect mtext, mleaders or dimensions: "))
            (setq tmp (mask:settings (mask:getdefaults key)))
       )
       (progn
           (mask:setdefaults key tmp)
           (apply 'mask:main (cons sel tmp))
       )
   )
   (princ)
)

;;----------------------------------------------------------------------;;

(defun mask:getdefaults ( key / tmp )
   (if
       (not
           (and
               (setq tmp (getenv key))
               (= 'list (type (setq tmp (read tmp))))
               (= 4 (length tmp))
           )
       )
       (mask:setdefaults key '("0" 1.5 "0" ((62 . 1))))
       tmp
   )
)

;;----------------------------------------------------------------------;;

(defun mask:setdefaults ( key val )
   (if (apply 'and val)
       (setenv key (vl-prin1-to-string val))
   )
   val
)

;;----------------------------------------------------------------------;;

(defun mask:settings ( arg / col dcf dch dcl des dis fn1 fn2 fn3 img msk off rtn trn )
   (mapcar 'set '(msk off trn col) arg)
   (cond
       (   (not
               (and
                   (setq dcl (vl-filename-mktemp nil nil ".dcl"))
                   (setq des (open dcl "w"))
                   (progn
                       (foreach str
                          '(
                               "imgbox : image_button"
                               "{"
                               "    alignment = centered;"
                               "    height = 1.5;"
                               "    aspect_ratio = 1;"
                               "    fixed_width = true;"
                               "    fixed_height = true;"
                               "    color = 1;"
                               "}"
                               "mask : dialog"
                               "{"
                               "    label = \"Background Mask\";"
                               "    spacer;"
                               "    : toggle"
                               "    {"
                               "        label = \"Use Background Mask\";"
                               "        key = \"msk\";"
                               "    }"
                               "    spacer;"
                               "    : boxed_column"
                               "    {"
                               "        label = \"Mask Offset\";"
                               "        : row"
                               "        {"
                               "            alignment = centered;"
                               "            : edit_box"
                               "            {"
                               "                key = \"off\";"
                               "            }"
                               "            : button"
                               "            {"
                               "                label = \">>\";"
                               "                key = \"pik\";"
                               "                fixed_width = true;"
                               "            }"
                               "        }"
                               "        spacer;"
                               "    }"
                               "    spacer;"
                               "    : boxed_column"
                               "    {"
                               "        label = \"Fill Color\";"
                               "        : row"
                               "        {"
                               "            alignment = centered;"
                               "            fixed_width = true;"
                               "            : toggle"
                               "            {"
                               "                key = \"trn\";"
                               "                label = \"Transparent\";"
                               "            }"
                               "            : imgbox"
                               "            {"
                               "                key = \"col\";"
                               "            }"
                               "        }"
                               "        spacer;"
                               "    }"
                               "    spacer;"
                               "    ok_cancel;"
                               "}"
                           )
                           (write-line str des)
                       )
                       (setq des (close des))
                       (< 0 (setq dch (load_dialog dcl)))
                   )
               )
           )
           (prompt "\nUnable to write and/or load Mask dialog.")
       )
       (   (progn
               (while (not (member dcf '(0 1)))
                   (cond
                       (   (null (new_dialog "mask" dch))
                           (princ "\nMask dialog not defined.")
                           (setq dcf 0)
                       )
                       (   t
                           (setq img
                               (lambda ( key aci )
                                   (start_image key)
                                   (fill_image 0 0 (dimx_tile key) (dimy_tile key) aci)
                                   (end_image)
                               )
                           )
                           (   (setq fn1
                                   (lambda ( )
                                       (img "col"
                                           (cond
                                               (   (= "0" msk) -15)
                                               (   (= "1" trn)   0)
                                               (   (cdr (assoc 62 col)))
                                               (   -15   )
                                           )
                                       )
                                   )
                               )
                           )
                           (   (setq fn2
                                   (lambda ( val )
                                       (fn1) (mode_tile "col" (atoi val))
                                   )
                               )
                               (set_tile "trn" trn)
                           )
                           (   (setq fn3
                                   (lambda ( val )
                                       (setq val (- 1 (atoi val)))
                                       (foreach key  '("off" "pik" "trn" "col")
                                           (mode_tile key val)
                                       )
                                       (fn2 (if (= "0" msk) "1" trn))
                                   )
                               )
                               (set_tile "msk" msk)
                           )
                           (action_tile "trn" "(fn2 (setq trn $value))")
                           (action_tile "msk" "(fn3 (setq msk $value))")
                       
                           (set_tile "off" (rtos off 2))
                           (action_tile "off"
                               (vl-prin1-to-string
                                  '(if
                                       (or
                                           (null (setq dis (distof $value)))
                                           (< 5.0 dis)
                                           (< dis 1.0)
                                       )
                                       (progn
                                           (alert "Please provide a value between 1 and 5.")
                                           (set_tile "off" (rtos off 2))
                                           (mode_tile "off" 2)
                                       )
                                       (set_tile "off" (rtos (setq off dis) 2))
                                   )
                               )
                           )

                           (action_tile "col"
                               (vl-prin1-to-string
                                  '(if (setq tmp (acad_truecolordlg (vl-some '(lambda ( x ) (assoc x col)) '(430 420 62)) nil))
                                       (img "col" (cdr (assoc 62 (setq col tmp))))
                                   )
                               )
                           )

                           (action_tile "pik" "(done_dialog 2)")
                        
                           (setq dcf (start_dialog))
                       )
                   )
                   (if
                       (and (= 2 dcf)
                           (progn
                               (while
                                   (not
                                       (or (null (setq dis (getdist (strcat "\nPick Mask Offset Factor <" (rtos off 2) ">: "))))
                                           (<= 1.0 dis 5.0)
                                       )
                                   )
                                   (princ "\nOffset must be between 1 and 5.")
                               )
                               dis
                           )
                       )
                       (setq off dis)
                   )
               )
               (zerop dcf)
           )
           (prompt "\n*Cancel*")
       )
       (   (setq rtn (list msk off trn col)))
   )
   (if (< 0 dch)
       (setq dch (unload_dialog dch))
   )
   (if (and dcl (findfile dcl))
       (vl-file-delete dcl)
   )
   rtn
)

;;----------------------------------------------------------------------;;

(defun mask:selection ( msg )
   (mask:ssget msg
      '("_:L" ((0 . "*DIMENSION,MTEXT,MULTILEADER")))
   )
)

;;----------------------------------------------------------------------;;

(defun mask:main ( sel msk off trn col )
   (mask:maskselection sel (= "1" msk) off (= "1" trn) col)
)

;;----------------------------------------------------------------------;;

(defun mask:maskselection ( sel msk off trn col / idx )
   (if (= 'pickset (type sel))
       (repeat (setq idx (sslength sel))
           (mask:maskentity (ssname sel (setq idx (1- idx))) msk off trn col)
       )
   )
)

;;----------------------------------------------------------------------;;

(defun mask:maskentity ( ent msk off trn col / enx typ )
   (setq enx (entget ent)
         typ (cdr (assoc 0 enx))
   )
   (cond
       (   (= "MTEXT" typ)
           (if msk
               (entmod
                   (append (vl-remove-if '(lambda ( x ) (member (car x) '(45 63 90 421 431 441))) enx)
                       (if trn
                          '((90 . 3) (63 . 256))
                           (cons '(90 . 1) (mapcar '(lambda ( x ) (cons (1+ (car x)) (cdr x))) col))
                       )
                       (list (cons 45 off) '(441 . 0))
                   )
               )
               (vla-put-backgroundfill (vlax-ename->vla-object (cdr (assoc -1 enx))) :vlax-false)
           )
       )
       (   (= "MULTILEADER" typ)
           (entmod
               (mask:substonce enx
                   (if msk
                       (list
                           (cons 091 (mask:color->mleadercolor (if trn '((62 . 256)) col)))
                           (cons 141 off)
                           (if trn '(291 . 1) '(291 . 0))
                          '(292 . 1)
                       )
                      '((292 . 0))
                   )
               )
           )
       )
       (   (wcmatch typ "*DIMENSION")
           (setq sty (mask:dimstylefill (cdr (assoc 3 enx)))
                 ovr (vl-remove-if '(lambda ( x ) (< 68 (car x) 71)) (mask:getdimxdata ent))
           )
           (cond
               (   (not msk)
                   (if (assoc 69 sty)
                       (mask:setdimxdata ent (append ovr '((70 0) (69 0))))
                       (mask:setdimxdata ent ovr)
                   )
               )
               (   trn
                   (if (= 1 (cdr (assoc 69 sty)))
                       (mask:setdimxdata ent ovr)
                       (mask:setdimxdata ent (append ovr '((69 1))))
                   )
               )
               (   (and (= 2 (cdr (assoc 69 sty)))
                        (=   (cdr (assoc 62 col)) (cdr (assoc 70 sty)))
                   )
                   (mask:setdimxdata ent ovr)
               )
               (   (mask:setdimxdata ent (append ovr (list (list 70 (cdr (assoc 62 col))) '(69 2)))))
           )
       )
   )
)

;;----------------------------------------------------------------------;;

(defun mask:dimstylefill ( sty / tmp )
   (if
       (and
           (setq sty (tblobjname "dimstyle" sty))
           (setq sty (entget sty))
           (setq tmp (assoc 69 sty))
       )
       (list tmp (assoc 70 (member tmp sty)))
   )
)

;;----------------------------------------------------------------------;;

(defun mask:getdimxdata ( dim / lst ovr )
   (setq lst (cddr (member '(1000 . "DSTYLE") (cdadr (assoc -3 (entget dim '("acad")))))))
   (while (and lst (not (equal '(1002 . "}") (car lst))))
       (setq ovr (cons (list (cdar lst) (cdadr lst)) ovr)
             lst (cddr lst)
       )
   )
   (reverse ovr)
)

;;----------------------------------------------------------------------;;

(defun mask:setdimxdata ( dim ovr / lst tmp )
   (if ovr
       (setq ovr
          (append
              '(
                   (1000 . "DSTYLE")
                   (1002 . "{")
               )
               (apply 'append (mapcar '(lambda ( x ) (mapcar 'cons '(1070 1070) x)) ovr))
              '(
                   (1002 . "}")
               )
           )
       )
   )
   (cond
       (   (not (setq lst (cdadr (assoc -3 (entget dim '("acad"))))))
           (regapp "acad")
           (entmod (append (entget dim) (list (list -3 (cons "acad" ovr)))))
       )
       (   (setq tmp (member '(1000 . "DSTYLE") lst))
           (entmod
               (append (entget dim)
                   (list
                       (list -3
                           (cons "acad"
                               (append
                                   (reverse (cdr (member '(1000 . "DSTYLE") (reverse lst))))
                                   ovr
                                   (cdr (member '(1002 . "}") tmp))
                               )
                           )
                       )
                   )
               )
           )
       )
       (   (entmod (append (entget dim) (list (list -3 (cons "acad" (append lst ovr)))))))
   )
)

;;----------------------------------------------------------------------;;

(defun mask:ssget ( msg arg / sel )
   (princ msg)
   (setvar 'nomutt 1)
   (setq sel (vl-catch-all-apply 'ssget arg))
   (setvar 'nomutt 0)
   (if (not (vl-catch-all-error-p sel)) sel)
)

;;----------------------------------------------------------------------;;

(defun mask:substonce ( enx lst )
   (mapcar
      '(lambda ( dxf / itm )
           (cond
               (   (setq itm (assoc (car dxf) lst))
                   (setq lst (vl-remove itm lst))
                   itm
               )
               (   dxf   )
           )
       )
       enx
   )
)

;;----------------------------------------------------------------------;;

(defun mask:color->mleadercolor ( c / x )
   (cond
       (   (setq x (cdr (assoc 420 c))) (+ -1040187392 x))
       (   (zerop (setq x (cdr (assoc 62 c)))) -1056964608)
       (   (= 256 x) -1073741824)
       (   (< 0 x 256) (+ -1023410176 x))
   )
)

;;----------------------------------------------------------------------;;

(defun mask:startundo ( doc )
   (mask:endundo doc)
   (vla-startundomark doc)
)

;;----------------------------------------------------------------------;;

(defun mask:endundo ( doc )
   (while (= 8 (logand 8 (getvar 'undoctl)))
       (vla-endundomark doc)
   )
)

;;----------------------------------------------------------------------;;

(defun mask:acdoc nil
   (eval (list 'defun 'mask:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
   (mask:acdoc)
)

;;----------------------------------------------------------------------;;

(vl-load-com)
(princ
   (strcat
       "\n:: Mask.lsp | Version 1.3 | © Lee Mac "
       (menucmd "m=$(edtime,0,yyyy)")
       " www.lee-mac.com ::"
       "\n:: Type \"bmask\" to Invoke ::"
   )
)
(princ)

;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;




(defun C:PURR	()
 (command "PURGE" "A" "*" "N")
 (prompt "\nMEOW!!!.")
 (princ)
 
 

Edited by jt6572
Link to comment
Share on other sites

Why not use "x" in your selection sets rather than "_:L"

 

because i dont know what i am doing?!! :lol:

(only one i actually wrote is the purge all one!)

 

thanks big al - i will make that my first step.

Link to comment
Share on other sites

Hi there. If I understood correctly, you added that part (i removed the extra lines)

(defun c:CTRL ()
(c:CHN)
(c:T2M)
(c:mtwidth)
(c:bmask)
(c:PURR)
)

That is not a script file, so adding lines wont do anything in that part.

 

As for your script, I don't see why you added the 3 "A". basically what the script does is literally typing in the command line everything it contains.

it types ctrl

it hits "enter" (so far so good)

after that it enters the letter A (why?)

after that it hits "enter". basically it your alias are like mine, it launches the "arc" command then input "A" to the arc command 2 more times, ending up with something like that

Specify start point of arc or
:

Specify end point of arc (hold Ctrl to switch direction): a

Invalid 2D point.

Specify end point of arc (hold Ctrl to switch direction):

Invalid 2D point.

Specify end point of arc (hold Ctrl to switch direction): a

Invalid 2D point.

Specify end point of arc (hold Ctrl to switch direction):

 

The only thing you want is launch CTRL which takes care of everything. Your script file should only contain (with a space after or with a line return... dont include the quotation marks.)

"CTRL "

or

"CTRL

"

Link to comment
Share on other sites

Hi Jef!

(cool name btw.... 8))

thanks for your reply.

 

what the lisps do requires input, so the "A" is what i have for "All" as the input option. hang on, will just run the lisp...

it needs input at stages (that i would like to eliminate, as the options are always "all") and the A in the script was my attempt at having All selected automatically and thereby automating the lisp... if that makes sense?!

 

i had thought that formatting the script with a blank line after CTRL and then putting in an A (because after i run the CTRL command, ENTER needs to be pressed, then ALL needs to be selected) and blank lines would do it.

 

thank you

Jeff

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...