Author Topic: multi-leader style change ?  (Read 287 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Newt
  • Posts: 178
multi-leader style change ?
« on: November 23, 2020, 04:14:37 PM »
I'm clearly missing something here.

When I use these two routines as separate lisp routines, they work fine.

But if I place them together in the same lisp, both "RED" LDR's get changed to LDR_LS100.

Code - Auto/Visual Lisp: [Select]
  1.  (if (setq sel1 (ssget "_X" '((0 . "MULTILEADER"))));;multi-leader
  2.    (repeat (setq int1 (sslength sel1))
  3.     (setq obj1 (vlax-ename->vla-object (ssname sel1 (setq int1 (1- int1)))))
  4.     (progn (eq (vla-get-stylename obj1) "LDR_L100_RED")
  5.        (vla-put-stylename obj1 "LDR_L100")
  6.        )
  7.      )
  8.    )
  9.  
  10.   (if (setq sel2 (ssget "_X" '((0 . "MULTILEADER"))));;multi-leader
  11.    (repeat (setq int2 (sslength sel2))
  12.     (setq obj2 (vlax-ename->vla-object (ssname sel2 (setq int2 (1- int2)))))
  13.     (progn (eq (vla-get-stylename obj2) "LDR_LS100_RED")
  14.        (vla-put-stylename obj2 "LDR_LS100")
  15.        )
  16.      )
  17.    )


What am I missing?
J. Logan
ACAD 2018

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

jlogan02

  • Newt
  • Posts: 178
Re: multi-leader style change ?
« Reply #1 on: November 23, 2020, 04:51:15 PM »
And once again...never mind, I found the error of my ways.

I'm clearly missing something here.

When I use these two routines as separate lisp routines, they work fine.

But if I place them together in the same lisp, both "RED" LDR's get changed to LDR_LS100.

Code - Auto/Visual Lisp: [Select]
  1.  (if (setq sel1 (ssget "_X" '((0 . "MULTILEADER"))));;multi-leader
  2.    (repeat (setq int1 (sslength sel1))
  3.     (setq obj1 (vlax-ename->vla-object (ssname sel1 (setq int1 (1- int1)))))
  4.     (progn (eq (vla-get-stylename obj1) "LDR_L100_RED")
  5.        (vla-put-stylename obj1 "LDR_L100")
  6.        )
  7.      )
  8.    )
  9.  
  10.   (if (setq sel2 (ssget "_X" '((0 . "MULTILEADER"))));;multi-leader
  11.    (repeat (setq int2 (sslength sel2))
  12.     (setq obj2 (vlax-ename->vla-object (ssname sel2 (setq int2 (1- int2)))))
  13.     (progn (eq (vla-get-stylename obj2) "LDR_LS100_RED")
  14.        (vla-put-stylename obj2 "LDR_LS100")
  15.        )
  16.      )
  17.    )


What am I missing?


Code - Auto/Visual Lisp: [Select]
  1.  ...(progn (eq (vla-get-stylename obj1) "LDR_L100_RED")...
  2.  
  3.  
  4.  
  5.  ...(progn (eq (vla-get-stylename obj2) "LDR_LS100_RED")...
  6.  

Should be

Code - Auto/Visual Lisp: [Select]
  1.  ...(if (eq (vla-get-stylename obj1) "LDR_L100_RED")...
  2.  
  3.  
  4.  
  5.  
  6.  ...(if (eq (vla-get-stylename obj2) "LDR_LS100_RED")...
  7.  
J. Logan
ACAD 2018

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

ronjonp

  • Needs a day job
  • Posts: 7215
Re: multi-leader style change ?
« Reply #2 on: November 23, 2020, 05:30:33 PM »
You could also combine the code like so:
Code - Auto/Visual Lisp: [Select]
  1. (if (setq sel1 (ssget "_X" '((0 . "MULTILEADER"))))
  2.   ;;multi-leader
  3.   (repeat (setq int1 (sslength sel1))
  4.     (setq obj1 (vlax-ename->vla-object (ssname sel1 (setq int1 (1- int1)))))
  5.     (setq sn (strcase (vla-get-stylename obj1)))
  6.     (cond ((= sn "LDR_L100_RED") (vla-put-stylename obj1 "LDR_L100"))
  7.           ((= sn "LDR_LS100_RED") (vla-put-stylename obj1 "LDR_LS100"))
  8.     )
  9.   )
  10. )

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

jlogan02

  • Newt
  • Posts: 178
Re: multi-leader style change ?
« Reply #3 on: November 23, 2020, 05:55:09 PM »
You could also combine the code like so:
Code - Auto/Visual Lisp: [Select]
  1. (if (setq sel1 (ssget "_X" '((0 . "MULTILEADER"))))
  2.   ;;multi-leader
  3.   (repeat (setq int1 (sslength sel1))
  4.     (setq obj1 (vlax-ename->vla-object (ssname sel1 (setq int1 (1- int1)))))
  5.     (setq sn (strcase (vla-get-stylename obj1)))
  6.     (cond ((= sn "LDR_L100_RED") (vla-put-stylename obj1 "LDR_L100"))
  7.      ((= sn "LDR_LS100_RED") (vla-put-stylename obj1 "LDR_LS100"))
  8.     )
  9.   )
  10. )


I figured there was a way shorter method. I did try (cond...but not like that.


Thanks for that, RonJonP.
J. Logan
ACAD 2018

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

ronjonp

  • Needs a day job
  • Posts: 7215
Re: multi-leader style change ?
« Reply #4 on: November 23, 2020, 06:39:50 PM »
Glad to help :) .. you can also use an association list like so:
Code - Auto/Visual Lisp: [Select]
  1. (if (setq sel1 (ssget "_X" '((0 . "MULTILEADER"))))
  2.   ;;multi-leader
  3.   (progn (setq l '(("LDR_L100_RED" "LDR_L100") ("LDR_LS100_RED" "LDR_LS100")))
  4.          (repeat (setq int1 (sslength sel1))
  5.            (setq obj1 (vlax-ename->vla-object (ssname sel1 (setq int1 (1- int1)))))
  6.            (if (setq sn (cadr (assoc (strcase (vla-get-stylename obj1)) l)))
  7.              (vla-put-stylename obj1 sn)
  8.            )
  9.          )
  10.   )
  11. )

Or wcmatch if all *_RED names need to be changed:
Code - Auto/Visual Lisp: [Select]
  1. (if (setq sel1 (ssget "_X" '((0 . "MULTILEADER"))))
  2.   ;;multi-leader
  3.   (repeat (setq int1 (sslength sel1))
  4.     (setq obj1 (vlax-ename->vla-object (ssname sel1 (setq int1 (1- int1)))))
  5.     (if (wcmatch (setq sn (strcase (vla-get-stylename obj1))) "*_RED")
  6.       (vla-put-stylename obj1 (substr sn 1 (- (strlen sn) 4)))
  7.     )
  8.   )
  9. )
« Last Edit: November 23, 2020, 06:45:44 PM by ronjonp »

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

jlogan02

  • Newt
  • Posts: 178
Re: multi-leader style change ?
« Reply #5 on: November 25, 2020, 03:41:25 PM »
Glad to help :) .. you can also use an association list like so:
Code - Auto/Visual Lisp: [Select]
  1. Or wcmatch if all *_RED names need to be changed:
  2. [code=cadlisp-7](if (setq sel1 (ssget "_X" '((0 . "MULTILEADER"))))
  3.   ;;multi-leader
  4.   (repeat (setq int1 (sslength sel1))
  5.     (setq obj1 (vlax-ename->vla-object (ssname sel1 (setq int1 (1- int1)))))
  6.     (if (wcmatch (setq sn (strcase (vla-get-stylename obj1))) "*_RED")
  7.       (vla-put-stylename obj1 (substr sn 1 (- (strlen sn) 4)))
  8.     )
  9.   )
  10. )

This last bit is exactly it. It's an instance of, if you don't lisp enough you forget crap. I'm working on "sister" code that goes along with this one and have encountered the same issue with the names. This will definitely help.

I have questions on that lisp, but will create a separate post for it. Actually, I think one of the examples I'm using is from you.

Thanks again.
J. Logan
ACAD 2018

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