Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can I tie a key from a custom dictionary to display in a field?

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
mid-awe
1162 Views, 13 Replies

How can I tie a key from a custom dictionary to display in a field?

A question that I haven't been able to find is how I can tie a key from a custom dictionary to display in a field?

 

I know that I can dump the custom dictionary into globals and the fields can track those values, but instead of strangling my available memory I'd rather track the dictionary key directly.

 

How can I utilize the Entity name or the actual dictionary name & key?

 

Thank you in advance for any help/suggestions you may be able to offer.

13 REPLIES 13
Message 2 of 14
mid-awe
in reply to: mid-awe

No replies at all must mean this is impossible or rediculously impracticle? Smiley Frustrated

 

Message 3 of 14
dgorsman
in reply to: mid-awe

Haven't tried it, since fields are built to be tied to entities or LISP values I suspect any implementation would be unreliable.  Usually any data being linked would be a value rather than a key.

 

LISP variables aren't *that* expensive to memory, unless you have hordes of them.  In that case you are probably better off setting up data links to a database, and manipulating the database contents.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 4 of 14
mid-awe
in reply to: dgorsman

dgorsman, thank you. That at least helps me to choose a direction to work toward. I have a few hundred LISP variables and I agree. In most cases not all LISP variables will contain values and therefore will never be assigned. I will later output the values to an excel sheet. This will be used to generate specific reports based on drawing content and that is the need for the dictionary references as well as the fields (to keep track of exact dictionary reference values).

Again, thank you for the insights.
Message 5 of 14
kefer_kb
in reply to: mid-awe

Maybe I cannot answer your full question, but i use dictionary funtion like this:

 

Create my own dictionary "GFM_3DSPRO", if it doesn't exist.

(if (not (dictsearch (namedobjdict) "GFM_3DSPRO"))
    (progn
      (dictadd (namedobjdict) "GFM_3DSPRO" (entmakex (list '(0 . "DICTIONARY") '(100 . "AcDbDictionary"))))
    );endprogn
  );endif

 Store data.

(vlax-ldata-put "GFM_3DSPRO" "myname" "Franz Kefer")
(vlax-ldata-put "GFM_3DSPRO" "age" 47)

 Read data.

(vlax-ldata-get "GFM_3DSPRO" "myname")
(vlax-ldata-get "GFM_3DSPRO" "age")

read the full dictionary list, e.g. to see all stored variables.

(entget (cdr (car (cdr (member '(3 . "GFM_3DSPRO") (entget (namedobjdict)))))))

 

 Remove dictionary from drawing.

(dictremove (namedobjdict) "GFM_3DSPRO")

 

www.gfm.at
Message 6 of 14
mid-awe
in reply to: kefer_kb

Thank you kefer.kb,

That looks to be a very mature approach. You've presented some interesting methods although I recommend storing everything as strings unless the dictionary value will be used to do math at some point. The main reason is from my experience it is more predictable and will save debugging time down the road.

I particularly like your use of dictsearch. For me I store the values in globals and call each of them explicitly when I need them.
Message 7 of 14
Lee_Mac
in reply to: mid-awe

Although not formally documented and not available through the standard AutoCAD Field command, an AutoCAD Field Expression can in fact reference almost any ActiveX property of almost any VLA-Object.

 

Therefore, it is indeed possible to reference a key from a custom dictionary using a Field Expression, as the following example demonstrates:

 

;; An example demonstrating how to create an AutoCAD Field Expression
;; referencing a custom dictionary entry -  Lee Mac 2013-10-10

(defun c:dictfield ( / dic ins nod xrc )
    (setq nod (namedobjdict))
    (if (null (setq dic (cdr (assoc -1 (dictsearch nod "MyCustomDictionary")))))
        (setq dic
            (dictadd nod "MyCustomDictionary"
                (entmakex
                   '(
                        (000 . "DICTIONARY")
                        (100 . "AcDbDictionary")
                    )
                )
            )
        )
    )
    (if dic
        (progn
            (if (null (setq xrc (cdr (assoc -1 (dictsearch dic "MyCustomData")))))
                (setq xrc
                    (dictadd dic "MyCustomData"
                        (entmakex
                           '(
                                (000 . "XRECORD")
                                (100 . "AcDbXrecord")
                                (001 . "My Data")
                            )
                        )
                    )
                )
            )
            (if xrc
                (if (setq ins (getpoint "\nSpecify point for Field: "))
                    (vlax-invoke
                        (vlax-get-property (LM:acdoc)
                            (if (= 1 (getvar 'cvport))
                                'paperspace
                                'modelspace
                            )
                        )
                        'addmtext
                        (trans ins 1 0)
                        0.0
                        (strcat
                            "%<\\AcObjProp Object(%<\\_ObjId "
                            (LM:objectid (vlax-ename->vla-object xrc))
                            ">%).Name>%"
                        )
                    )
                )
                (princ "\nUnable to create xrecord: \"MyCustomData\".")
            )
        )
        (princ "\nUnable to create dictionary: \"MyCustomDictionary\".")
    )
    (princ)
)

;; ObjectID  -  Lee Mac
;; Returns a string containing the ObjectID of a supplied VLA-Object
;; Compatible with 32-bit & 64-bit systems

(defun LM:ObjectID ( obj )
    (eval
        (list 'defun 'LM:ObjectID '( obj )
            (if
                (and
                    (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
                    (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
                )
                (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
               '(itoa (vla-get-objectid obj))
            )
        )
    )
    (LM:ObjectID obj)
)

;; Active Document  -  Lee Mac
;; Returns the VLA Active Document Object

(defun LM:acdoc nil
    (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
    (LM:acdoc)
)

(vl-load-com) (princ)
Message 8 of 14
mid-awe
in reply to: Lee_Mac

Lee Mac - LISP NINJA Extraordinaire 🙂

I had given up on this approach. You are constantly changing my mind about Visual LISP limitations.

Thank you very much Lee.
Message 9 of 14
Lee_Mac
in reply to: mid-awe


@mid-awe wrote:
Lee Mac - LISP NINJA Extraordinaire 🙂

 

Smiley Happy


@mid-awe wrote:
I had given up on this approach. You are constantly changing my mind about Visual LISP limitations.

Thank you very much Lee.

 

Although nowhere near as powerful as .NET, where customisation of existing functionality is concerned, there really isn't too much that Visual LISP & Vanilla AutoLISP cannot achieve (of course, that's coming from a LISP advocate Smiley Wink)

 

As always, you're most welcome mid-awe, happy to help.

Message 10 of 14
hmsilva
in reply to: Lee_Mac

Nice one Lee!

 

Henrique

EESignature

Message 11 of 14
Lee_Mac
in reply to: hmsilva

Thank you Henrique! Smiley Happy

Message 12 of 14
kefer_kb
in reply to: mid-awe

@mid-awe

I am happy if i could help you a little bit. The main reason for use dictionary is simple. It is the best way for me to store process data in a drawing.

I use ACAD, especially 3D-functions for a radial forging simulation with 4 or more forging dies. During simulation, actual progress data are stored in my dictionary object and the dwg-file on harddisc.

If ACAD crashed, I reload the last saved drawing und start my programm again. If my dictionary is present and contain data, the programm read it and continue simulation process on correct position without any user intervention. (save a lot of time for complex simulations)

Take a look to added images, one before start, and one after finish of simulation.

@Lee Mac
Thanks for the demonstration of the possibility of professional software eingineereing ... my head is smoking Smiley Wink

with kind regards
Franz

before forging. You see 1 die of 4after forging simulationsimulation finished

www.gfm.at
Message 13 of 14
Lee_Mac
in reply to: kefer_kb

Message 14 of 14
mid-awe
in reply to: kefer_kb

Franz,

 

Thank you for the explaination. I obviously use the dictionary for different reasons and I'm still testing the waters with new ideas (new to me and the company that employs me at this time). I've dabbled often over the years and am only now really stretching my imagination for applications of this great asset.

 

As for 3D, I do all my 3D work with Blender 2.68. Not only because it's awesome and free, but also because the Python API is fast & flexible. Plus, AutoCAD can't touch the incredible Modifiers, Modeling tools, Cycles rendering, Bullet Physics, Particles, Simulators, etc., etc... Interactive 3D Visualiztion at my fingertips. It literally takes less than 30min to drop a camera in a scene, add some logic (with a template appended it's even faster), and presto - nearly instant walkthrough with high quality realtime rendering. And; if I choose, I can save an excutable of my project and give it to the client to run on their own machine with no concern for royalties or other BS.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost