Author Topic: How to continue routine  (Read 955 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 327
How to continue routine
« on: March 01, 2022, 03:37:35 PM »
I want the larger routine to continue if there aren't any color 191 Mtext objects.

Code - Auto/Visual Lisp: [Select]
  1.  (if (setq sel (ssget))
  2.    (repeat (setq int (sslength sel))
  3.      (setq obj (vlax-ename->vla-object (ssname sel (setq int (1- int)))))
  4.       (progn (setq txt (vla-get-textstring obj))
  5.            (while (vl-string-search "\\C191;" txt) (setq txt (vl-string-subst "\\C256;" "\\C191;" txt)))
  6.            (vla-put-textstring obj txt)
  7.       )
  8.     )
  9.   )
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

JohnK

  • Administrator
  • Seagull
  • Posts: 10651
Re: How to continue routine
« Reply #1 on: March 01, 2022, 03:49:51 PM »
Showing my Lisp (in)abilities but I think we need more context.
Also do you not just grab all MTEXT items that are color 191 with those SSGET codes.
Like: (ssget "x" '((-4 . "=") (62 . 191)))))
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

jlogan02

  • Bull Frog
  • Posts: 327
Re: How to continue routine
« Reply #2 on: March 01, 2022, 05:38:28 PM »
Here's the other piece of the code.


Code - Auto/Visual Lisp: [Select]
  1. (if (setq col191 (ssget "X" '((0 . "MultiLeader,Hatch,*Line,text,dimension") (62 . 191))))
  2.     (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex col191)))
  3.       (if (= (strcase (cdr (assoc 0 (setq lst (entget x))))) "DIMENSION")
  4.         (command "_.dimoverride" "dimclrd" 2 "dimclre" 2 "dimclrt" 3 "" (ssadd x) "")
  5.         (entmod (append lst '((62 . 256))))
  6.         )
  7.       )
  8.    )

Then the code in question

Code - Auto/Visual Lisp: [Select]
  1. (if (setq sel (ssget))
  2.    (repeat (setq int (sslength sel))
  3.      (setq obj (vlax-ename->vla-object (ssname sel (setq int (1- int)))))
  4.       (progn (setq txt (vla-get-textstring obj))
  5.            (while (vl-string-search "\\C191;" txt) (setq txt (vl-string-subst "\\C256;" "\\C191;" txt)))
  6.            (vla-put-textstring obj txt)
  7.       )
  8.     )
  9.   )
  10.  
  11. (command "chprop" col191 "" "color" "bylayer" "")

There are instances where we need to select all of col191 filtered objects and single characters within an Mtext entity to change their color. Unless I'm missing something (very possible) this is how I'm approaching it. So if the first part finds color 191 for Mleaders, lines and dimensions finds something it changes it, then the user selects the visible 191 mtext entities to change. Here, I want to move on to complete the color change the col191 selection set if there isn't any color 191 present in Mtext.

I get what you're saying though. My code doesn't allow for moving on because I'm not using
Code - Auto/Visual Lisp: [Select]
  1. (ssget "x" '((-4 . "=") (62 . 191)))))
. My code can only move on after the user has picked something or escaped I guess.

To be fair I haven't used your specific ssget suggestion. So I'll start there.
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

jlogan02

  • Bull Frog
  • Posts: 327
Re: How to continue routine
« Reply #3 on: March 01, 2022, 07:02:19 PM »
Here's an example.

The Mtext entity all red, will get changed with the first portion of code if I add an asterisk in front of Text in the list.

The second mtext entity with green and red is an instance where I need to change the red entity back to bylayer. Or carry on if none exist.

So, these red entities get changed to color 191 and then back at construction issue.
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

JohnK

  • Administrator
  • Seagull
  • Posts: 10651
Re: How to continue routine
« Reply #4 on: March 01, 2022, 07:21:10 PM »
Oh! I was thinking something along these lines but I can see now that I was missing a portion of the puzzle.
Code - Auto/Visual Lisp: [Select]
  1. (defun colorByLayer (/ ss i elist)
  2.   (setq i -1)
  3.   (repeat
  4.     (sslength (setq ss (ssget "x" '((-4 . "/=") (62 . 256)))))
  5.      (entmod
  6.        (subst '(62 . 256) (assoc 62 (setq elist (entget (ssname ss (setq i (1+ i)))))) elist))
  7.   )
  8.   (princ)
  9. )
  10.  
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org