Author Topic: Working with dictionaries  (Read 2062 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
Working with dictionaries
« on: September 21, 2011, 07:52:39 AM »
Hello everyone ...

I would like to know how many dictionaries which each drawing would have . (e.g Mleaders , dimensions ...... etc )
And the title ( name ) of each dictionary name .

Finally , how to extract the style names of a dictionary in a list ?

Hope that not too much .

Many thanks .

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Working with dictionaries
« Reply #1 on: September 21, 2011, 08:11:53 AM »
To get you started, take a look at:

Code: [Select]
(entget (namedobjdict))
And:

Code: [Select]
(vla-get-dictionaries (vla-get-activedocument (vlax-get-acad-object)))
Also, study the functions:  dictnext, dictsearch

Coder

  • Swamp Rat
  • Posts: 827
Re: Working with dictionaries
« Reply #2 on: September 21, 2011, 08:18:33 AM »
Thanks Lee .

I know the basics but my needs are behind or after that .

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Working with dictionaries
« Reply #3 on: September 21, 2011, 08:22:15 AM »
I know the basics but my needs are behind or after that .

The above post will answer your first question, and studying the functions to which I referred will answer your second. Which part of my post was too basic?

Coder

  • Swamp Rat
  • Posts: 827
Re: Working with dictionaries
« Reply #4 on: September 21, 2011, 08:48:20 AM »
With these codes I could get the number of Dicts that we have in each dwg session , but how to extract the name of styles in each dictionary ?

Code: [Select]
(setq Dlst (entget (namedobjdict)))
(setq n (vl-remove-if-not
          '(lambda (st)
             (eq (car st) 3)
           )
          Dlst
        )
)
(length n)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Working with dictionaries
« Reply #5 on: September 21, 2011, 08:55:58 AM »
Hint:

Code: [Select]
(dictsearch (namedobjdict) "Your_Dictionary_Name")
Or:

Code: [Select]
(vlax-for item
    (vla-item
        (vla-get-dictionaries (vla-get-activedocument (vlax-get-acad-object)))
        "Your_Dictionary_Name"
    )
    ...
)

But be aware that the Item method will error if the key doesn't exist.

Coder

  • Swamp Rat
  • Posts: 827
Re: Working with dictionaries
« Reply #6 on: September 21, 2011, 09:34:54 AM »
Thanks Lee ,

Code: [Select]
(setq n (vl-remove-if-not '(lambda (st) (eq (car st) 3))
          (dictsearch (namedobjdict) "ACAD_MLEADERSTYLE")
        ))
Or .....

Code: [Select]
(vlax-for item
    (vla-item
        (vla-get-dictionaries (vla-get-activedocument (vlax-get-acad-object)))
        "ACAD_MLEADERSTYLE"
    )
(setq styls (cons (vla-get-name item)styls))
)

Thanks a lot Lee for the infos and for the hint which gives the encouragement to look for it .  :-)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Working with dictionaries
« Reply #7 on: September 21, 2011, 09:49:14 AM »
Thanks a lot Lee for the infos and for the hint which gives the encouragement to look for it .  :-)

Teach a man to fish and all that  :wink: