Author Topic: setvar "CPLOTSTYLE" to existing plotstyle  (Read 3449 times)

0 Members and 1 Guest are viewing this topic.

Peter2

  • Swamp Rat
  • Posts: 653
setvar "CPLOTSTYLE" to existing plotstyle
« on: May 27, 2015, 03:39:37 PM »
I have named plotstyles and want to use
Code - Auto/Visual Lisp: [Select]
  1. (setvar "CPLOTSTYLE" "test")
Of course I get an error if the named plotstyle "test" does not exist.

How can I check if "test" exists?

Thanks
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

ronjonp

  • Needs a day job
  • Posts: 7529
Re: setvar "CPLOTSTYLE" to existing plotstyle
« Reply #1 on: May 27, 2015, 03:54:48 PM »
Perhaps:

Code - Auto/Visual Lisp: [Select]
  1. (defun _plotstylexist-p (stylename / d)
  2.   (and (setq d (dictsearch (namedobjdict) "ACAD_PLOTSTYLENAME"))
  3.        (dictsearch (cdr (assoc -1 d)) stylename)
  4.   )
  5. )
  6. (_plotstylexist-p "normal")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BlackBox

  • King Gator
  • Posts: 3770
Re: setvar "CPLOTSTYLE" to existing plotstyle
« Reply #2 on: May 27, 2015, 03:59:16 PM »
How can I check if "test" exists?

You can use something like this:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:FOO (/ _GetPlotSettings acDoc)
  2.  
  3.   (defun _GetPlotSettings (doc / plotSettings)
  4.                           "ACAD_PLOTSETTINGS"
  5.                 )
  6.       (setq plotSettings (cons (vla-get-name x) plotSettings))
  7.     )
  8.     (reverse plotSettings)
  9.   )
  10.  
  11.   (if
  12.     (and
  13.       (vl-position "Test" (_GetPlotSettings acDoc))
  14.     )
  15.      (setvar 'cplotstyle "Test")
  16.      (prompt "\n** \"Test\" is not an available plot style ** ")
  17.   )
  18.   (princ)
  19. )
  20.  


[Edit] - D@mn ninjas
"How we think determines what we do, and what we do determines what we get."

Peter2

  • Swamp Rat
  • Posts: 653
Re: setvar "CPLOTSTYLE" to existing plotstyle
« Reply #3 on: May 27, 2015, 04:00:22 PM »
Thanks ronjonp

in the meantime I found a post by irneb (thanks too !  :-))

http://forums.augi.com/archive/index.php/t-102823.html
Code - Auto/Visual Lisp: [Select]
  1. (setq ed (entget (cdr (cadr (member '(3 . "ACAD_PLOTSTYLENAME") root)))))
  2. (member (cons 3 "test") ed)
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

ronjonp

  • Needs a day job
  • Posts: 7529
Re: setvar "CPLOTSTYLE" to existing plotstyle
« Reply #4 on: May 27, 2015, 04:03:57 PM »
Thanks ronjonp

in the meantime I found a post by irneb (thanks too !  :) )

http://forums.augi.com/archive/index.php/t-102823.html
Code - Auto/Visual Lisp: [Select]
  1. (setq ed (entget (cdr (cadr (member '(3 . "ACAD_PLOTSTYLENAME") root)))))
  2. (member (cons 3 "test") ed)


Glad you found what you needed. Be aware that using member to look for an item in a list is case sensitive.
Code - Auto/Visual Lisp: [Select]
  1. (member (cons 3 "Test")(list (cons 3 "test")))
  2. nil


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ronjonp

  • Needs a day job
  • Posts: 7529
Re: setvar "CPLOTSTYLE" to existing plotstyle
« Reply #5 on: May 27, 2015, 04:04:27 PM »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Peter2

  • Swamp Rat
  • Posts: 653
Re: setvar "CPLOTSTYLE" to existing plotstyle
« Reply #6 on: May 27, 2015, 04:17:00 PM »
Hi

thanks to all.

@ronjonp: works fine, short, easy, not case-sensitive, .. - perfect.

@BlackBox: I tried, but "_GetPlotSettings" returns always nil ..

@irneb (from 2009): works too, but with case-sensitivity.

Thanks for that great forum!
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

Peter2

  • Swamp Rat
  • Posts: 653
Re: setvar "CPLOTSTYLE" to existing plotstyle
« Reply #7 on: May 27, 2015, 05:08:46 PM »
Additional info for special cases:
Code - Auto/Visual Lisp: [Select]
  1. ...(dictsearch (namedobjdict) "ACAD_PLOTSTYLENAME"))...
The dictionary is not refreshed when the STB is changed. Usually this happens not very often, but ..

- I had "a.stb" with plotstyle "test": Everything OK.
- I replaced it with "b.stb" without "test": The code says "test exists", while (setvar "cplotstyle" "test") reports an error "test does not exists".
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: setvar "CPLOTSTYLE" to existing plotstyle
« Reply #8 on: May 27, 2015, 05:52:43 PM »
Actually the "ACAD_PLOTSTYLENAME" dictionary does not list the styles in the STB file. It lists the styles that are in use in the drawing.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: setvar "CPLOTSTYLE" to existing plotstyle
« Reply #9 on: May 28, 2015, 04:04:45 AM »
Try using:
Code: [Select]
(vl-catch-all-apply 'setvar '(cplotstyle "test"))

Peter2

  • Swamp Rat
  • Posts: 653
Re: setvar "CPLOTSTYLE" to existing plotstyle
« Reply #10 on: May 28, 2015, 09:26:01 AM »
Actually the "ACAD_PLOTSTYLENAME" dictionary does not list the styles in the STB file. It lists the styles that are in use in the drawing.
Yes, you're right. Searching the "available" plotstyles needs another solution.
Try using:
Code: [Select]
(vl-catch-all-apply 'setvar '(cplotstyle "test"))
Yes, it works. Namely there is still an error-message created by Autocad (not Lisp), but the lisp continues to work.
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23

ronjonp

  • Needs a day job
  • Posts: 7529
Re: setvar "CPLOTSTYLE" to existing plotstyle
« Reply #11 on: May 28, 2015, 10:09:00 AM »
Actually the "ACAD_PLOTSTYLENAME" dictionary does not list the styles in the STB file. It lists the styles that are in use in the drawing.
Yes, you're right. Searching the "available" plotstyles needs another solution.
Try using:
Code: [Select]
(vl-catch-all-apply 'setvar '(cplotstyle "test"))
Yes, it works. Namely there is still an error-message created by Autocad (not Lisp), but the lisp continues to work.
Maybe this ?
Code - Auto/Visual Lisp: [Select]
  1. (vl-directory-files (getenv "PrinterStyleSheetDir") "*.*tb" 1)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Peter2

  • Swamp Rat
  • Posts: 653
Re: setvar "CPLOTSTYLE" to existing plotstyle
« Reply #12 on: May 28, 2015, 10:25:05 AM »
Returns nil. I suppose this should return the existing files, but for this I have another solution.

But the analysis of the STB leads too far from my basic target; I'm happy with the solution above. Thanks a lot for your help!
Peter

AutoCAD Map 3D 2023 German (so some technical terms will be badly retranslated to English)
BricsCAD V23