Jump to content

trying to UNBOLD mtext of particular layer


LispLearner

Recommended Posts

Hi All, 

      i m a new learner in Autolisp, i m trying to UNBOLD the mtext in particular layer (LAYER12)

I got this code from online, where i changed |b1| to |b0|

but it is not happening, i did mistake somewhere , could you please help me to fix it 

attaching the code...

 

Thanks in Advance

 

code here:

(defun c:UNBOLD ()
  (sssetfirst nil (ssget "_x" '((0 . "TEXT,MTEXT"))))
  (defun _ps->ss (ps)
    (if    (= 'pickset (type ps))
      (vl-remove-if 'listp (mapcar 'cadr (ssnamex ps)))
    )
  )
  (if (setq ss (_ps->ss (ssget (list (cons 0 "mtext") (cons 8 "LAYER12")))))
    (foreach mtext ss
      (setq o (vlax-ename->vla-object mtext))
      (vla-put-textstring o (strcat "{\\fArial|b0|i0|c256|p34;" (vla-get-textstring o)))
    )
  )
  (princ)
)

 

Link to comment
Share on other sites

Always include a link to where you got the code, if you ever have an issue with it that should be the best place to get support from whoever the code belongs to and provides better information about the code making it easier for others to help you. As the code there worked modifying it rather than fixing code that doesn't work would be easier as well.

 

Attaching a small drawing with the bold mtext in it would allow anyone trying to help you to debug the code using it. 

 

As there are many easy ways to select all the mtext on a certain layer I'd recommend a lisp to turn bold off on selected mtext in case you ever needed to use it on a different layer.

 

Link to comment
Share on other sites

Hi Tombu, 

        Thanks for you for guidance on this forum & Quick reply....

here i have attached a sample file as requested & i m using this code for long time to pick the simillar text & making it BOLD.

now i m looking to modify the code to make it UNBOLD...

and i m sorry i am unable to get the link of that code now.

Please Help.

 

Thanks in Advance.

SAMPLE.dwg

Link to comment
Share on other sites

test attached lisp

 

;;;;;-*******************************************************************************************************************************
;;Copyright � http://autolisp.mapcar.net/strtok.html
(DEFUN STR-DIV  (STR C / I L) ;_01
  (SETQ I 1)
  (SETQ L (STRLEN STR))
  (WHILE (AND (<= I L) (/= (SUBSTR STR I 1) C))
    (SETQ I (1+ I))
    )
  (LIST (SUBSTR STR 1 (1- I)) (SUBSTR STR (1+ I)))
  )
;;;
;;;(str-div "Schraube;M12;1,5;36;367.4;252.6;0.0" ";")
;;;("Schraube" "M12;1,5;36;367.4;252.6;0.0")
;;;(str-div "1,234,567.89" ",")

;;;("M12" "1,5;36;367.4;252.6;0.0") 
;;;;;-*******************************************************************************************************************************

;;separa por un separador 

(DEFUN STR-TOK  (STR C / TMP) ;_01
  (IF (/= STR "")
    (PROGN
      (SETQ TMP (STR-DIV STR C))
      (APPEND (LIST (CAR TMP)) (STR-TOK (CADR TMP) C))
      )
    )
  )
;;;"M12,1.5,36,367.4,252.6,0.0" )
;;;(str-tok "Schraube;M12;1,5;36;367.4;252.6;0.0" ";")
;;;
;;;("Schraube" "M12" "1,5" "36" "367.4" "252.6" "0.0") 
;;;
;;;;;-*******************************************************************************************************************************



(defun c:UNBOLD ()
;;;  (sssetfirst nil (ssget "_x" '((0 . "TEXT,MTEXT"))))
  (defun _ps->ss (ps)
    (if    (= 'pickset (type ps))
      (vl-remove-if 'listp (mapcar 'cadr (ssnamex ps)))
    )
  )
  (if (setq ss (_ps->ss (ssget  "_x" (list  (cons 0 "mtext") (cons 8 "LAYER12")))))

    (foreach mtext ss
      (setq o (vlax-ename->vla-object mtext))
      (setq o-string (vla-get-textstring o))
       (setq new-o-string (strcat (car(cdr ( str-tok   o-string ";"))) ";"(last(cdr ( str-tok   o-string ";")))))
      
      (vla-put-textstring o new-o-string)
    )
  )
  (princ)
)

 

unbold.lsp

Link to comment
Share on other sites

4 minutes ago, tombu said:

Missing one defun, ; error: no function definition: STR-TOK



;;;;;-*******************************************************************************************************************************
;;Copyright � http://autolisp.mapcar.net/strtok.html
(DEFUN STR-DIV  (STR C / I L) ;_01
  (SETQ I 1)
  (SETQ L (STRLEN STR))
  (WHILE (AND (<= I L) (/= (SUBSTR STR I 1) C))
    (SETQ I (1+ I))
    )
  (LIST (SUBSTR STR 1 (1- I)) (SUBSTR STR (1+ I)))
  )
;;;
;;;(str-div "Schraube;M12;1,5;36;367.4;252.6;0.0" ";")
;;;("Schraube" "M12;1,5;36;367.4;252.6;0.0")
;;;(str-div "1,234,567.89" ",")

;;;("M12" "1,5;36;367.4;252.6;0.0") 
;;;;;-*******************************************************************************************************************************

;;separa por un separador 

(DEFUN STR-TOK  (STR C / TMP) ;_01
  (IF (/= STR "")
    (PROGN
      (SETQ TMP (STR-DIV STR C))
      (APPEND (LIST (CAR TMP)) (STR-TOK (CADR TMP) C))
      )
    )
  )
;;;"M12,1.5,36,367.4,252.6,0.0" )
;;;(str-tok "Schraube;M12;1,5;36;367.4;252.6;0.0" ";")
;;;
;;;("Schraube" "M12" "1,5" "36" "367.4" "252.6" "0.0") 
;;;
;;;;;-*******************************************************************************************************************************



(DEFUN C:UNBOLD  ()
;;;  (sssetfirst nil (ssget "_x" '((0 . "TEXT,MTEXT"))))
  (DEFUN _PS->SS  (PS)
    (IF (= 'PICKSET (TYPE PS))
      (VL-REMOVE-IF 'LISTP (MAPCAR 'CADR (SSNAMEX PS)))
      )
    )
  (IF (SETQ SS (_PS->SS (SSGET "_x" (LIST (CONS 0 "mtext") (CONS 8 "LAYER12")))))

    (FOREACH MTEXT  SS
      (SETQ O (VLAX-ENAME->VLA-OBJECT MTEXT))
      (SETQ O-STRING (VLA-GET-TEXTSTRING O))
      (SETQ NEW-O-STRING (STRCAT (CAR (CDR (STR-TOK O-STRING ";"))) ";" (LAST (CDR (STR-TOK O-STRING ";")))))

      (VLA-PUT-TEXTSTRING O NEW-O-STRING)
      )
    )
  (PRINC)
  )

;|«Visual LISP© Format Options»
(180 2 1 0 nil "end of " 100 20 2 2 nil nil T nil T)
;*** DO NOT add text below the comment! ***|;

Please try it . 

 

from the vlide 

 

VISUAL LISP CONSOLE 

 

STR-DIV 
STR-TOK 
C:UNBOLD 
; 3 forms loaded from #<editor "H:/!!!drawings/lisp learner cadtutor/unbold-01.lsp">
 

 

 

 

 

unbold-01.lsp

Link to comment
Share on other sites

24 minutes ago, devitg said:
;;;;;-*******************************************************************************************************************************
;;Copyright � http://autolisp.mapcar.net/strtok.html
(DEFUN STR-DIV  (STR C / I L) ;_01
  (SETQ I 1)
  (SETQ L (STRLEN STR))
  (WHILE (AND (<= I L) (/= (SUBSTR STR I 1) C))
    (SETQ I (1+ I))
    )
  (LIST (SUBSTR STR 1 (1- I)) (SUBSTR STR (1+ I)))
  )
;;;
;;;(str-div "Schraube;M12;1,5;36;367.4;252.6;0.0" ";")
;;;("Schraube" "M12;1,5;36;367.4;252.6;0.0")
;;;(str-div "1,234,567.89" ",")

;;;("M12" "1,5;36;367.4;252.6;0.0") 
;;;;;-*******************************************************************************************************************************

;;separa por un separador 

(DEFUN STR-TOK  (STR C / TMP) ;_01
  (IF (/= STR "")
    (PROGN
      (SETQ TMP (STR-DIV STR C))
      (APPEND (LIST (CAR TMP)) (STR-TOK (CADR TMP) C))
      )
    )
  )
;;;"M12,1.5,36,367.4,252.6,0.0" )
;;;(str-tok "Schraube;M12;1,5;36;367.4;252.6;0.0" ";")
;;;
;;;("Schraube" "M12" "1,5" "36" "367.4" "252.6" "0.0") 
;;;
;;;;;-*******************************************************************************************************************************



(DEFUN C:UNBOLD  ()
;;;  (sssetfirst nil (ssget "_x" '((0 . "TEXT,MTEXT"))))
  (DEFUN _PS->SS  (PS)
    (IF (= 'PICKSET (TYPE PS))
      (VL-REMOVE-IF 'LISTP (MAPCAR 'CADR (SSNAMEX PS)))
      )
    )
  (IF (SETQ SS (_PS->SS (SSGET "_x" (LIST (CONS 0 "mtext") (CONS 8 "LAYER12")))))

    (FOREACH MTEXT  SS
      (SETQ O (VLAX-ENAME->VLA-OBJECT MTEXT))
      (SETQ O-STRING (VLA-GET-TEXTSTRING O))
      (SETQ NEW-O-STRING (STRCAT (CAR (CDR (STR-TOK O-STRING ";"))) ";" (LAST (CDR (STR-TOK O-STRING ";")))))

      (VLA-PUT-TEXTSTRING O NEW-O-STRING)
      )
    )
  (PRINC)
  )

;|«Visual LISP© Format Options»
(180 2 1 0 nil "end of " 100 20 2 2 nil nil T nil T)
;*** DO NOT add text below the comment! ***|;

Please try it . 

 

from the vlide 

 

VISUAL LISP CONSOLE 

 

STR-DIV 
STR-TOK 
C:UNBOLD 
; 3 forms loaded from #<editor "H:/!!!drawings/lisp learner cadtutor/unbold-01.lsp">
 

 

 

 

 

unbold-01.lsp 1.92 kB · 0 downloads

Sorry I didn't copy the top code, only the part that displayed in your post.

Got to remember to scroll up!

Link to comment
Share on other sites

Hi @devitg @tombu

   while running this code in sample2.dwg, i m facing following issue...

MTEXT in BOLD condition are getting changed properly but

MTEXT is getting duplicated which is already in UNBOLD condition, please check the below screenshot,

also attaching sample file.

image.png.a6886a63730e2fd454f926983f691365.png

 

 

 

 

SAMPLE2.dwg

Link to comment
Share on other sites

1 hour ago, LispLearner said:

Hi @devitg @tombu

   while running this code in sample2.dwg, i m facing following issue...

MTEXT in BOLD condition are getting changed properly but

MTEXT is getting duplicated which is already in UNBOLD condition, please check the below screenshot,

also attaching sample file.

image.png.a6886a63730e2fd454f926983f691365.png

 

 

 

 

SAMPLE2.dwg 57.28 kB · 1 download

I did to suit your sample, I will add some feature so to not unbold the unbolded text. 

 

 

 

 

  • Like 1
Link to comment
Share on other sites

2 hours ago, LispLearner said:

Hi @devitg @tombu

   while running this code in sample2.dwg, i m facing following issue...

MTEXT in BOLD condition are getting changed properly but

MTEXT is getting duplicated which is already in UNBOLD condition, please check the below screenshot,

also attaching sample file.

image.png.a6886a63730e2fd454f926983f691365.png

 

 

 

 

SAMPLE2.dwg 57.28 kB · 1 download

Find attached lisp file 

unbold-02.lsp

Link to comment
Share on other sites

hi @devitg

   sorry for troubling you again, its might be again my mistake, i missed to explain you properly..

here I tested with you recent code in SAMPLE2.dwg, its considering only yellow coloured BOLD Text & making it UNBOLD.

actually it should not consider colour (just for the showing difference of BOLD Text, i changed it to Yellow on sample2.dwg)

 

another issue is if we run the command for the second time on the same dwg, it again starts to duplicate text as shown in previous screenshot.

 

attaching another sample3.dwg...... kindly check it.

SAMPLE3.dwg

Edited by LispLearner
attachment missed
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...