Author Topic: Apply Plot style table to all layout  (Read 4668 times)

0 Members and 1 Guest are viewing this topic.

miquan

  • Guest
Apply Plot style table to all layout
« on: July 24, 2013, 06:02:51 PM »
Dear all,

I use this lisp for set plot style table of layout to specific one.
Code - Auto/Visual Lisp: [Select]
  1. ; (defun c:PLOTHORY ()
  2.     )
  3.     "monochrome.ctb"
  4.   )
  5. )

But it still works only in current layout.
Could you possily help me to modify for all layout setting?

Thanks in advanced,
Miquan

Ketxu

  • Newt
  • Posts: 109
Re: Apply Plot style table to all layout
« Reply #1 on: July 25, 2013, 12:32:22 AM »
You could try :
Code - Auto/Visual Lisp: [Select]
  1.         (vla-get-Layouts
  2.                 (vla-get-ActiveDocument (vlax-get-acad-object))
  3.     )
  4.         '(lambda(x)(vla-put-StyleSheet x "monochrome.ctb"))
  5. )

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Apply Plot style table to all layout
« Reply #2 on: July 25, 2013, 06:42:14 AM »
 :-D :-D
Funny I was just trying to do the same thing.   
I love this place!
Thanks!.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

miquan

  • Guest
Re: Apply Plot style table to all layout
« Reply #3 on: July 25, 2013, 09:06:43 PM »
Dear ketxu,

Thanks for your support.
I works fine.

PS: you're from vietnam?

Miquan

Ketxu

  • Newt
  • Posts: 109
Re: Apply Plot style table to all layout
« Reply #4 on: July 26, 2013, 02:30:47 PM »
Yeah. Im living in Ha Noi

BlackBox

  • King Gator
  • Posts: 3770
Re: Apply Plot style table to all layout
« Reply #5 on: July 26, 2013, 04:43:22 PM »
FWIW -

It's actually faster to iterate the Layouts Collection, and manipulate each Layout Object directly, than it is to Map an anonymous function to same... To demonstrate, here's a quick speed test:

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun _foo1 (ctb)
  3.     )
  4.     '(lambda (x) (vla-put-StyleSheet x ctb))
  5.   )
  6. )
  7.  
  8. (defun _foo2 (ctb)
  9.                 (vla-get-activedocument (vlax-get-acad-object))
  10.               )
  11.     (vla-put-stylesheet x ctb)
  12.   )
  13. )
  14.  



... And the results from console:

Code - Auto/Visual Lisp: [Select]
  1. _$ (bench '(_foo1 _foo2) '("FOO.ctb") 10000)
  2.  
  3. _FOO1
  4. Elapsed: 4774
  5. Average: 0.4774
  6.  
  7. _FOO2
  8. Elapsed: 3791
  9. Average: 0.3791
  10.  
"How we think determines what we do, and what we do determines what we get."

BlackBox

  • King Gator
  • Posts: 3770
Re: Apply Plot style table to all layout
« Reply #6 on: July 26, 2013, 04:47:25 PM »
Also, as it is loosely related, for those who might be interested: vla-SetActivePageSetup
"How we think determines what we do, and what we do determines what we get."

3dwannab

  • Newt
  • Posts: 45
Re: Apply Plot style table to all layout
« Reply #7 on: May 15, 2024, 03:53:09 PM »
Added checking if the plot style exists.

Code: [Select]
;;----------------------------------------------------------------------;;
;; setPlotStyle FUNCTION
;; https://www.theswamp.org/index.php?topic=45000.msg502065#msg502065
;; Added checking if the plot style exists by 3dwananb on 2024.05.15

(defun setPlotStyle (ctb / CurDoc installedPs)
  (setq CurDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (setq installedPs (vlax-safearray->list (vlax-variant-value (vla-GetPlotStyleTableNames (vla-get-ActiveLayout CurDoc))))) ;;get the plotstyles
  (if (/= nil (vl-position ctb installedPs))
    (progn
      (princ (strcat "\nPlot Style successfully set to: '" ctb "'\n"))
      (vlax-map-collection
        (vla-get-Layouts
          (vla-get-ActiveDocument (vlax-get-acad-object))
        )
        '(lambda (x) (vla-put-StyleSheet x ctb))
      )
    )
    (princ (strcat "\nPlot Style '" ctb "' not found!\n"))
  ) ;; if verify if the plotstyle exist, if not, print to the commandline.
)

(setPlotStyle "monochrome.ctb")

Lonnie

  • Newt
  • Posts: 183
Re: Apply Plot style table to all layout
« Reply #8 on: May 16, 2024, 11:59:34 AM »
Added checking if the plot style exists.

I was messing with changing page setup when I saw this. Since this was played with today I thought why not?

Removed case sensitivity

Code: [Select]
(setq ctbLower (strcase ctb nil))
(setq installedPsLower (mapcar '(lambda (ps) (strcase ps nil)) installedPs))

Code: [Select]
(if (/= nil (vl-position ctbLower installedPsLower))


Code: [Select]
;;----------------------------------------------------------------------;;
;; setPlotStyle FUNCTION
;; https://www.theswamp.org/index.php?topic=45000.msg502065#msg502065
;; Added checking if the plot style exists by 3dwananb on 2024.05.15

(defun setPlotStyle (ctb / CurDoc installedPs ctbLower installedPsLower)
  ;; Get the active document
  (setq CurDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
  ;; Get the list of installed plot styles
  (setq installedPs (vlax-safearray->list (vlax-variant-value (vla-GetPlotStyleTableNames (vla-get-ActiveLayout CurDoc)))))

  ;; Convert the input plot style name and the list of installed plot styles to lowercase for case-insensitive comparison
  (setq ctbLower (strcase ctb nil))
  (setq installedPsLower (mapcar '(lambda (ps) (strcase ps nil)) installedPs))

  ;; Check if the specified plot style exists in a case-insensitive manner and set it
  (if (vl-position ctbLower installedPsLower)
    (progn
      (princ (strcat "\nPlot Style successfully set to: '" ctb "'\n"))
      (vlax-map-collection
        (vla-get-Layouts CurDoc)
        '(lambda (x) (vla-put-StyleSheet x ctb))
      )
    )
    (progn
      (princ (strcat "\nPlot Style '" ctb "' not found!\n"))
      ;; Print the available plot style tables if the specified plot style is not found
      (princ "\nAvailable plot style tables:\n")
      (mapcar '(lambda (ps) (princ (strcat ps ""))) installedPs)
    )
  ) ;; If plotstyle exists, set it; otherwise, print available plot styles.
)

;; Example invocation
(setPlotStyle "monochrome.ctb")



Before I did that I added the list of files to look at trying to figure out why it failed.

Code: [Select]
(setq CurDoc (vla-get-ActiveDocument (vlax-get-acad-object)))

Code: [Select]
(setq installedPs (vlax-safearray->list (vlax-variant-value (vla-GetPlotStyleTableNames (vla-get-ActiveLayout CurDoc)))))
« Last Edit: May 16, 2024, 01:56:46 PM by Lonnie »