TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Ben Clark on April 14, 2017, 10:33:23 AM

Title: List of Visual Styles in DWG
Post by: Ben Clark on April 14, 2017, 10:33:23 AM
My last post went unanswered. So as a result of doing my own fishing, I've boiled it down to an easier one  :-D. I still don't understand dictionaries well though.

I need a function that outputs a list of all the visual styles in the drawing (so that I can check for the existence of a certain visual style).

Anybody have a way to do this?
Title: Re: List of Visual Styles in DWG
Post by: Lee Mac on April 14, 2017, 10:37:43 AM
Simple example:
Code - Auto/Visual Lisp: [Select]
  1. (defun dictnames ( dic / itm rtn )
  2.     (while (setq itm (dictnext dic (null itm)))
  3.         (setq rtn (cons (cdr (assoc 2 itm)) rtn))
  4.     )
  5. )
Code - Auto/Visual Lisp: [Select]
  1. (dictnames (cdr (assoc -1 (dictsearch (namedobjdict) "acad_visualstyle"))))
Title: Re: List of Visual Styles in DWG
Post by: Ben Clark on April 14, 2017, 10:41:38 AM
Lee, worked like a charm. Thank you so much!

Know of a good source out there that I could check out that would give me a good handle on the namedobjdict?
Title: Re: List of Visual Styles in DWG
Post by: gile on April 14, 2017, 10:55:31 AM
Hi,

It might be interesting to get a list of (entryKey . ename) pairs for each entry in a dictionary

Code - Auto/Visual Lisp: [Select]
  1. (defun getDictEntries (lst)
  2.   (if (setq lst (member (assoc 3 lst) lst))
  3.     (cons (cons (cdar lst) (cdadr lst)) (getDictEntries (cddr lst)))
  4.   )
  5. )

Code - Auto/Visual Lisp: [Select]
  1. (getDictEntries (dictsearch (namedobjdict) "acad_visualstyle"))
Title: Re: List of Visual Styles in DWG
Post by: Grrr1337 on April 14, 2017, 11:05:48 AM
It might be interesting to get a list of (entryKey . ename) pairs for each entry in a dictionary

Cool idea, gile!
Heres a sample result:

Code - Auto/Visual Lisp: [Select]
  1. _$ (getDictEntries (entget (namedobjdict)))
  2. (("ACAD_CIP_PREVIOUS_PRODUCT_INFO" . <Entity name: 7ff6b14049e0>)
  3.   ("ACAD_COLOR" . <Entity name: 7ff6b1403bb0>)
  4.   ("ACAD_DETAILVIEWSTYLE" . <Entity name: 7ff6b1404a30>)
  5.   ("ACAD_GROUP" . <Entity name: 7ff6b14038d0>)
  6.   ("ACAD_LAYOUT" . <Entity name: 7ff6b14039a0>)
  7.   ("ACAD_MATERIAL" . <Entity name: 7ff6b1403ba0>)
  8.   ("ACAD_MLEADERSTYLE" . <Entity name: 7ff6b1404150>)
  9.   ("ACAD_MLINESTYLE" . <Entity name: 7ff6b1403970>)
  10.   ("ACAD_PLOTSETTINGS" . <Entity name: 7ff6b1403990>)
  11.   ("ACAD_PLOTSTYLENAME" . <Entity name: 7ff6b14038e0>)
  12.   ("ACAD_SCALELIST" . <Entity name: 7ff6b14040c0>)
  13.   ("ACAD_SECTIONVIEWSTYLE" . <Entity name: 7ff6b1404a10>)
  14.   ("ACAD_TABLESTYLE" . <Entity name: 7ff6b1403c60>)
  15.   ("ACAD_VISUALSTYLE" . <Entity name: 7ff6b1403ef0>)
  16.   ("AcDbVariableDictionary" . <Entity name: 7ff6b1403ae0>)
  17. )
Title: Re: List of Visual Styles in DWG
Post by: Lee Mac on April 14, 2017, 11:16:32 AM
gile, is there any advantage to retrieving dictionary entries using a list iterator as opposed to using dictnext which is designed for this purpose? i.e.:

Code - Auto/Visual Lisp: [Select]
  1. (defun dictenames ( dic / itm rtn )
  2.     (while (setq itm (dictnext dic (null itm)))
  3.         (setq rtn (cons (cons (cdr (assoc 2 itm)) (cdr (assoc -1 itm))) rtn))
  4.     )
  5. )
Title: Re: List of Visual Styles in DWG
Post by: gile on April 14, 2017, 11:27:55 AM
I do not think there's any advantage (neither any disadvantage), it's just an old one I had in a library.
Title: Re: List of Visual Styles in DWG
Post by: ahsattarian on December 21, 2021, 03:26:56 PM
Is there any way to activate them as well ????