TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Peter2 on May 27, 2015, 03:39:37 PM

Title: setvar "CPLOTSTYLE" to existing plotstyle
Post by: Peter2 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
Title: Re: setvar "CPLOTSTYLE" to existing plotstyle
Post by: ronjonp 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")
Title: Re: setvar "CPLOTSTYLE" to existing plotstyle
Post by: BlackBox 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
Title: Re: setvar "CPLOTSTYLE" to existing plotstyle
Post by: Peter2 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)
Title: Re: setvar "CPLOTSTYLE" to existing plotstyle
Post by: ronjonp 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 (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

Title: Re: setvar "CPLOTSTYLE" to existing plotstyle
Post by: ronjonp on May 27, 2015, 04:04:27 PM
How can I check if "test" exists?
....
[Edit] - D@mn ninjas
;D
Title: Re: setvar "CPLOTSTYLE" to existing plotstyle
Post by: Peter2 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!
Title: Re: setvar "CPLOTSTYLE" to existing plotstyle
Post by: Peter2 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".
Title: Re: setvar "CPLOTSTYLE" to existing plotstyle
Post by: roy_043 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.
Title: Re: setvar "CPLOTSTYLE" to existing plotstyle
Post by: roy_043 on May 28, 2015, 04:04:45 AM
Try using:
Code: [Select]
(vl-catch-all-apply 'setvar '(cplotstyle "test"))
Title: Re: setvar "CPLOTSTYLE" to existing plotstyle
Post by: Peter2 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.
Title: Re: setvar "CPLOTSTYLE" to existing plotstyle
Post by: ronjonp 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)
Title: Re: setvar "CPLOTSTYLE" to existing plotstyle
Post by: Peter2 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!