vla-GetExtensionDictionary

vla-GetExtensionDictionary

DGRL
Advisor Advisor
3,083 Views
15 Replies
Message 1 of 16

vla-GetExtensionDictionary

DGRL
Advisor
Advisor

Dear Autodesk

 

Where can I find the compete list of dict extensions

 

(dictnext dict "ACAD_FIELD")

This one will make a selection of entities ONLY containing a field

 

What do I need to put in for

 

ATTRIBS

MTEXT

TEXT

ECT ECT

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
3,084 Views
15 Replies
Replies (15)
Message 2 of 16

_gile
Consultant
Consultant

Hi,

 

Dictionaries are containers for xrecords, custom objects or other dictionaries. There're two types of dictionaries: the named dictionaries which typically are children of the named object dictionary (accessible through the namedobjdict LISP function ; and the extension dictionaries which can be attached to an AutoCAD object. See this topic for more information.

 

So any AutoCAD object (graphical entities as non-graphical objects) might have one (and only one) extension dictionary. These dictionaries are mainly use by AutoCAD or third applications to attach data to an object (a little like xdata).

 

The "ACAD_FIELD" dictionary you're refering to, only exists in the extension dictionary of TEXT and MTEXT entities which have some field code in their text string.

So, a MTEXT entity can have or not have an extension dictionary and this dictionary can have or not have the "ACAD_FIELD" entry., but as soon as a MTEXT entity contains a field code, AutoCAD attaches an extension dictionary to the MTEXT (is it has not have already one) and attach a "ACAD_FIELD" which contains the field data.

 

So, looking for the "ACAD_FIELD" entry in a MTEXT extension dictionary to know if a MTEXT contains some field is not applicable for anything.

 

When you're saying  "What do I need to put in for ATTRIBS, TEXT, MTEXT, ETC ETC" what do you expect?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 16

DGRL
Advisor
Advisor

Hi @_gile

 

 

As you mentioned before to me making a filter based on assoc 102 is not smart as MTEXT can contain other assoc 102

I assume same is for ATTRIBS

And what do I expect

Well maybe i just putt in ACAD_FIELD // ACAD_MTEXT // ACAD_TEXT // ACAD_ECT

It might be easier for me to see the list of available extension dictionary or how you may call that

I just want to make a filter for ATTRIBS in this case and I do not want to keep asking here how to make filters for ALL AUTOCAD ENTITIES

 

Do you have a lisp for me with ALL the FILTERS possible?

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 4 of 16

_gile
Consultant
Consultant

You still do not understand.

 

An entity (MTEXT, TEXT, ATTRIB, ATTDEF) may have an extension dictionary and this extension dictionary may have an "ACAD_FIELD" entry and, if so, that means the entity contains a field.

 

This little commented routine shows this:

 

;; Returns T if the entity (MTEXT, TEXT, ATTRIB, ATTDEF) has some field; otherwise, nil.
(defun HasField (ent / dxfLst xdict)
  (and
    ;; get the DXF data list of the entity
    (setq dxfLst (entget ent))
    ;; get the entity extension dictionary (may return nil if none)
    (setq xdict (cdr (assoc 360 (member '(102 . "{ACAD_XDICTIONARY") dxfLst))))
    ;; check for the "ACAD_FIELD" entry in the extension dictionary (may return nil if none)
    (dictsearch xdict "ACAD_FIELD")
  )
)

Now talking about filtering entities, there mainly two ways:

  1. with a selection and a selection filter this only allow to filter on first level entities and some of their properties (block reference name, text contents, ...)
  2. iterating through a collection of entities (possibly a filtered selection set) and make your own tests, this allows all type of deep filtering.

1. You cand filter TEXT (ssget '((0 . "TEXT"))), MTEXT (ssget '((0 . "MTEXT"))) or both (ssget '((0 . "MTEXT,TEXT"))), but you cannot directly filter ATTRIBS or (M)TEXTs having fields (see this topic and the realted ones).

 

2. You can deeply inspect each entity, for example get (and inspect) the attribute references (ATTRIB) of a block reference, or check if a (M)TEXT contains a field.

 

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 16

DGRL
Advisor
Advisor

Hi @_gile

 

 

You are correct

 

I do not understand this and the whole LISP


Autodesk should consider MAKING way better documentation about this

You sent me http://help.autodesk.com/view/OARX/2018/ENU/
This should cover everything needed for a developer to get started
Yet it does not provide the info needed.

 

Where can I get extensive documentation about LISP used in and for Autodesk Products?
How in the world can I know stuff like this if CANT even find it anywhere?

 

 

Anyway Thanks for the explanation.

As for now I will just stop coding in lisp coz i am not good in it anyway.

Sad that I tried to become a good coder yet im failing

 

 

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 6 of 16

_gile
Consultant
Consultant

@DGRL wrote:

Hi @_gile

 

 

You are correct

 

I do not understand this and the whole LISP


Autodesk should consider MAKING way better documentation about this

You sent me http://help.autodesk.com/view/OARX/2018/ENU/
This should cover everything needed for a developer to get started
Yet it does not provide the info needed.

 

Where can I get extensive documentation about LISP used in and for Autodesk Products?
How in the world can I know stuff like this if CANT even find it anywhere?

 

 

Anyway Thanks for the explanation.

As for now I will just stop coding in lisp coz i am not good in it anyway.

Sad that I tried to become a good coder yet im failing

 

 

 

 


Do not be discouraged. Other have been able to learn LISP, so there's no reason you cannot.


The AutoLISP Developer's Guide is, as far as I know, the most extensive documentation about AutoLISP / Visual LISP existing today.
I'm pretty sure you did not read it all (I did not).

You can also find other resources on the internet, but the way most of us learned is by reading other ones codes and experimenting.

 

Anyway, you probaly won't find ready-made examples which exactly correspond to what you're looking for.

Perhaps you should begin with simpler tasks (it seems to me you're trying to build something too complex for a beginer).

 

And you should get help from other here and elsewhere...

 

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 16

DGRL
Advisor
Advisor

@_gile

 

Thanks for boosting me 🙂

I admit i did not read all of The AutoLISP Developer's Guide.
And maybe i should read it in my own language so i understand better ( language can make it hard to understand correctly )

 

The codes i got from you so far are in my library and i constantly asses them to learn from
Off course i am experimenting but due to lack of knowledge its hard

For me it does not look to complex but for coding it might
I fully understand what i want but i just dont know how to approach such using this level of lisp.

 

there is already a lot i can do likt changing all entities within a block to layer 0
or color and other related stuff but when it comes to stuff like this it is just a little hard to me.

 

Remember you told me not to cheat ( or someone else in same conversation ) and only to use vlax and mapcar lambda functions

I will spend time reading about that and i guess rest will come later.

 

Google is nice and lisp routines that can be found with it can also confuse you and that is what is going on with me

So many different ways to "change" entities within a block but none of them doing what i need to do.

 

and autodesk made a complete list already of the dictionary
why cant we just see that list?

Do i really have to vlax-dump-object T to see there info?


I just want 1 answer
Where can i find that list or HOW CAN I KNOW WHAT to fill in

Is there only 1 dictionary ? i.e

(dictsearch xdict "ACAD_FIELD")

Because i do not believe that there is only 1 dict called ACAD_FIELD

There must be more

 

 

 

 

 

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 8 of 16

_gile
Consultant
Consultant

@DGRL wrote:

I just want 1 answer
Where can i find that list or HOW CAN I KNOW WHAT to fill in

Is there only 1 dictionary ? i.e

(dictsearch xdict "ACAD_FIELD")

Because i do not believe that there is only 1 dict called ACAD_FIELD

There must be more

 


Please attentively read the topic about dictionaries I linked in a previous message.

 

By definition, a dictionary cannot contain duplicated entry names so there can be only one ACAD_FIELD dictionary per extension dictionary.

If your goal is to get all ACAD_FIELD dictionaries in a drawing, you have to iterate through all enetities wich can have one in their extension dictionary (ATTRIB, ATTDEF, MTEXT, TEXT).

 

I do not know how should I try to explain this in an other way, so I purpose you to make some test with the following routines and understand by yourself the "Dictionary stuff".

 

These routines use the gc:GetExtDict and gc:GetDictEntries functions from the gc-Dictionary.lsp library (available here).

 

;; gc:GetExtDict (gile)
;; Returns the extension dictionary of the object (or nil)
;;
;; Argument : obj (ENAME)

(defun gc:GetExtDict (obj)
  (cdadr (member '(102 . "{ACAD_XDICTIONARY") (entget obj)))
)

;; gc:GetDictEntries
;; Return the list of all entries in the dictionary as dotted pairs (name . ENAME)
;;
;; Argument : dict the dictionary (ENAME or DXF list)

(defun gc:GetDictEntries (dict / result)
  (and (= (type dict) 'ENAME) (setq dict (entget dict)))
  (while
    (setq dict (vl-member-if (function (lambda (x) (= (car x) 3))) (cdr dict)))
     (setq result (cons (cons (cdar dict) (cdadr dict)) result))
  )
  (reverse result)
)

 

This one prints the name of all named dictionaries contained by the root dictionary (Named Object Dictionary)

 

;; List all dictionaries in the named object dictionary
(defun listNamedObjDict ()
  (foreach entry (gc:GetDictEntries (namedobjdict))
    (princ (strcat "\n" (car entry)))
  )
  (princ)
)

 

 

This one prints the name of all layouts in the drawing. This is the AutoCAD stores the Layout objects of a drawing.

You can try with other dictionaries repalcing "ACAD_LAYOUT" by some othe name returned by the previous function.

 

;; list all entries in the ACAD_LAYOUT dictionary
(defun listLayoutDict (/)
  (setq dictionaries (gc:GetDictEntries (namedobjdict))
        layoutDict   (cdr (assoc "ACAD_LAYOUT" dicts))
  )
  (foreach entry (gc:GetDictEntries layoutDict)
    (princ (strcat "\n" (car entry)))
  )
  (princ)
)

 

This one list the entries of the object extension dictionary (if any).

 

;; list all entries in the object extension dictionary
(defun listExtensionDict (obj)
  (if (setq xdict (gc:GetExtDict obj))
    (foreach entry (gc:GetDictEntries xdict)
      (princ (strcat "\n" (car entry)))
    )
    (princ "\nThe object do not have an extension dictionary")
  )
  (princ)
)

 

You can try this last one with a selected drawing entity (try with a MTEXT with field and a MTEXT without field)

 

(listExtensionDict (car entsel)))  

 You can also try with non graphic objects as the layer "0"

 

(listExtensionDict (tblobjname "Layer" "0"))

 

or the Model space BLOCK_RECORD.

 

(listExtensionDict (cdr (assoc 330 (entget (tblobjname "block" "*Model_space")))))

Remember that not all objects have an extension dictionary.

 

 

The next step can be creation and adding dictionaries and xrecords to the root dictionary or to an extension dictionary (and create it if not already exists).

See the dictadd function in the AutoLISP Reference, it contains an example.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 9 of 16

john.uhden
Mentor
Mentor

Thank goodness you are not afraid of using...

 

(and

...

...

...

)

John F. Uhden

0 Likes
Message 10 of 16

john.uhden
Mentor
Mentor

Ditto what @_gile responded.

Except that I think a lot of us here learned by digging into each entity to discover what poorly documented characteristics it may contain.  We see 330 and 350 and 360 codes and dig into what they represent.  Then we look at vla-object properties to look for correlations that have actual names.  Then we found this -3 thingy that represented xdata, and then those curious dictionaries which can contain xrecords.

 

I am a lousy typist and hate typing anyway, so my acaddoc.lsp has things like...

(setq dump vlax-dump-object)

(setq e2o vlax-ename->vla-object)

(setq o2e vlax-vla-object->ename)

(defun c:NEL ()(entget (car (nentsel))))

(defun c:OD ()(vlax-dump-object (setq object (vlax-ename->vla-object (car (entsel))))))

(defun c:NOD ()(vlax-dump-object (setq object (vlax-ename->vla-object (car (nentsel))))))

 

Notice how I left object as a global?  That's so that I can see its applicable methods if I want...

(dump object 1)

 

With your irresistible urge to test you will find things like vla-delete is more powerful than entdel.

John F. Uhden

Message 11 of 16

_gile
Consultant
Consultant

@john.uhden wrote:

Thank goodness you are not afraid of using...

 

(and

...

...

...

)


Sorry I don't understand what you mean.

Isn't this exactly the purpose of the and function?

Short circuit evaluation of multiple condition to return T or nil.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 12 of 16

john.uhden
Mentor
Mentor

The long and is a form I learned years ago from Stephan Koster and am very fond of it, though certain others here have criticized me for it.  Even though it may corrupt files tous le mond, I will continue to use it.

John F. Uhden

0 Likes
Message 13 of 16

DGRL
Advisor
Advisor

Dear @_gile

 

Things are starting to get clear now
I really really thank you for the time and effort you take in trying to teach me

As for now when I have free time im going to read more of the DEV help and all the other links you send me

 

Due to this I decided as per today that when I can I will make a library of functions needed to "debug" routines.

The basis in the library I work with is not what it should be.

 

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 14 of 16

DGRL
Advisor
Advisor

@john.uhden wrote:

Ditto what @_gile responded.

Except that I think a lot of us here learned by digging into each entity to discover what poorly documented characteristics it may contain.  We see 330 and 350 and 360 codes and dig into what they represent.  Then we look at vla-object properties to look for correlations that have actual names.  Then we found this -3 thingy that represented xdata, and then those curious dictionaries which can contain xrecords.

 

I am a lousy typist and hate typing anyway, so my acaddoc.lsp has things like...

(setq dump vlax-dump-object)

(setq e2o vlax-ename->vla-object)

(setq o2e vlax-vla-object->ename)

(defun c:NEL ()(entget (car (nentsel))))

(defun c:OD ()(vlax-dump-object (setq object (vlax-ename->vla-object (car (entsel))))))

(defun c:NOD ()(vlax-dump-object (setq object (vlax-ename->vla-object (car (nentsel))))))

 

Notice how I left object as a global?  That's so that I can see its applicable methods if I want...

(dump object 1)

 

With your irresistible urge to test you will find things like vla-delete is more powerful than entdel.


 

Dear @john.uhden

 

Thanks for this small routine
It helps me a lot

As I also want to see the Methods supported I changed the NOD routine

 

(defun c:NOD ()(vlax-dump-object (setq object (vlax-ename->vla-object (car (nentsel))))T))

Now NEL will show the assoc (dxf) list
OD will show you dump properties and NOD includes Methods supported

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 15 of 16

john.uhden
Mentor
Mentor

I am pleased to hear of your progress.

 

For the lurkers, the reason for c:NOD vs. c:OD is that NOD is intended to return subentity data such as an attribute or vertex or anything within a block.

OD = Object Dump

NOD = Nested Object Dump

John F. Uhden

Message 16 of 16

DGRL
Advisor
Advisor

Dear @john.uhden

Off course the T needs to be inserted also in the c:od  and only if you want to see the methods supported off course 

 

Thanks to both of you for "supporting" and helping me so much

 

And @_gile i learned a lot from you last few days and i just cant say THANKS enough 

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes