Author Topic: Replace StyleName mline  (Read 2863 times)

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 343
Replace StyleName mline
« on: June 19, 2016, 11:01:16 AM »
Hello,
I need to change the styleName of one or more MLINE entities :

(vlax-put (vlax-ename->vla-object ent1) 'StyleName newstilename)

Unfortunately the styleName property is read-only.
However, in BricsCAD, I can manually change the style of one or more MLINE entities with the properties panel.
Can I do the same thing in Lisp?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Replace StyleName mline
« Reply #1 on: June 19, 2016, 11:59:13 AM »
Yes you can!
Code - Auto/Visual Lisp: [Select]
  1. ; (MlineStyleSet (car (entsel)) "NewStyle1")
  2. (defun MlineStyleSet (enm stl / elst obj stlEnm)
  3.   (if
  4.     (setq stlEnm
  5.       (cdr
  6.         (assoc
  7.           -1
  8.           (dictsearch (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_MLINESTYLE"))) stl)
  9.         )
  10.       )
  11.     )
  12.     (progn
  13.       (setq elst (entget enm))
  14.       (entmod
  15.         (subst
  16.           (cons  2 stl)
  17.           (assoc 2 elst)
  18.           (subst
  19.             (cons 340 stlEnm)
  20.             (assoc 340 elst)
  21.             elst
  22.           )
  23.         )
  24.       )
  25.       (setq obj (vlax-ename->vla-object enm))
  26.       ; (vla-update obj) ; This doesn't do the trick.
  27.       (vla-put-coordinates obj (vla-get-coordinates obj)) ; But this does.
  28.     )
  29.   )
  30. )

Edit: Minor changes to code.
« Last Edit: June 19, 2016, 03:02:55 PM by roy_043 »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Replace StyleName mline
« Reply #2 on: June 20, 2016, 03:38:24 AM »
The code can improved by using the BricsCAD (vle-dictobjname) function:
Code - Auto/Visual Lisp: [Select]
  1.     (setq stlEnm
  2.       (cdr
  3.         (assoc
  4.           -1
  5.           (dictsearch (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_MLINESTYLE"))) stl)
  6.         )
  7.       )
  8.     )
Can be replaced by:
Code - Auto/Visual Lisp: [Select]
  1.     (setq stlEnm (vle-dictobjname (vle-dictobjname (namedobjdict) "ACAD_MLINESTYLE") stl))

Lupo76

  • Bull Frog
  • Posts: 343
Re: Replace StyleName mline
« Reply #3 on: June 20, 2016, 03:44:00 AM »
Thanks roy 043!
it is just what I wanted!


ahsattarian

  • Newt
  • Posts: 112
Re: Replace StyleName mline
« Reply #4 on: October 02, 2023, 12:01:57 PM »
Yes you can!
Code - Auto/Visual Lisp: [Select]
  1. ; (MlineStyleSet (car (entsel)) "NewStyle1")
  2. (defun MlineStyleSet (enm stl / elst obj stlEnm)
  3.   (if
  4.     (setq stlEnm
  5.       (cdr
  6.         (assoc
  7.           -1
  8.           (dictsearch (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_MLINESTYLE"))) stl)
  9.         )
  10.       )
  11.     )
  12.     (progn
  13.       (setq elst (entget enm))
  14.       (entmod
  15.         (subst
  16.           (cons  2 stl)
  17.           (assoc 2 elst)
  18.           (subst
  19.             (cons 340 stlEnm)
  20.             (assoc 340 elst)
  21.             elst
  22.           )
  23.         )
  24.       )
  25.       (setq obj (vlax-ename->vla-object enm))
  26.       ; (vla-update obj) ; This doesn't do the trick.
  27.       (vla-put-coordinates obj (vla-get-coordinates obj)) ; But this does.
  28.     )
  29.   )
  30. )

Edit: Minor changes to code.


It's not working for me  !!!