Author Topic: New Item in dictionary  (Read 6004 times)

0 Members and 1 Guest are viewing this topic.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
New Item in dictionary
« on: June 17, 2013, 04:51:35 AM »
Hello!

I´m experimenting with dictionary and found the very cool tool from Irne to display items in a dictionary. My question is how can I put more items in a dictionary
The first thing I wrote a function that can write a dictionary
Code: [Select]
    (defun Dict:New(GcList name / NEWDICT)
        (if(dictsearch (namedobjdict) name)(dictremove (namedobjdict) name))
        (setq newdict(dictadd (namedobjdict) name
                              (entmakex (list '(0 . "DICTIONARY")
                                              '(100 . "AcDbDictionary")))))
        (dictadd newdict name (entmakex
                                  (append (list '(0 . "XRECORD")
                                                '(100 . "AcDbXrecord"))
                                          GCList)
                                  )
                 )
        )
Next think I thought to can read a dictionary
   
Code: [Select]
(defun Dict:Read (name / DICT)
        (if (setq dict(dictsearch (namedobjdict) name))
            (vl-remove-if '(lambda(A)
                               (not(member(car A)'(1 70 40 10))))
                          (dictnext(cdr(assoc -1 dict))'T)
                          )
            )
        )
To test if it works
Code: [Select]
(defun c:test ( / liste) (setq liste (list (cons 1 "MyTest"))) (Dict:New liste "Dict1") (Dict:Read "Dict1") )


okay now I want more items like (2 . "MyTest2") (3 . "MyTest3") (4 . "MyTest4")

so I wrote a program that looks for a dictionary and ask which Text you want type in
Code: [Select]
    (if (Dict:Read (setq Dictname (getstring "\nSelect a Dictionay! ")))
        (if (setq string (getstring "\nType a Text! "))
            (vlax-invoke
                (vlax-ename->vla-object
                    (cdr (assoc -1 (dictsearch (namedobjdict) Dictname)))
                    )
                'addobject
                string ; Eingabe eines neuen Text
                "???"
                )
            )
        (alert "\nDictionary not found ")
        )
    (princ)

The question is invoke is not working with TextItems, which type must I have?


cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: New Item in dictionary
« Reply #2 on: June 18, 2013, 05:41:02 AM »
Hi!

Thank you, I have got with help from Irne´DictEdit tool, very nice done from him.
My question is now, if I create a dictionary and type in a function, for example like this simpleline
looks like so here
Code: [Select]
(defun c:test () (entsel "\nSelect something "))
In my Item comes a cuple of backslashs
Code: [Select]
((-1 . <Entity name: 7ffff741cc0>) (0 . "XRECORD") (5 . "3CC64") (102 . "{ACAD_REACTORS") (330 . <Entity name: 7ffff741c30>) (102 . "}") (330 . <Entity name: 7ffff741c30>) (100 . "AcDbXrecord") (280 . 1) (70 . 0) (1 . "(defun c:test () (entsel \"\\nSelect something \"))"))
that bother me if I want run the function
Code: [Select]
(eval (read (cdr (assoc 1 Item))))
Have anybody a trick how can change
Code: [Select]
(1 . "(defun c:test () (entsel \"\\nSelect something \"))")
correctly in
Code: [Select]
(1 . "(defun c:test () (entsel "\nSelect something "))")

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: New Item in dictionary
« Reply #3 on: June 18, 2013, 07:05:42 AM »
Have anybody a trick how can change
Code: [Select]
(1 . "(defun c:test () (entsel \"\\nSelect something \"))")
correctly in
Code: [Select]
(1 . "(defun c:test () (entsel "\nSelect something "))")

The first example is correct; the second example is wrong.

Since the quotation mark (") is the delimiter in AutoLISP to denote a string literal, the backslash escape character must be used to mark quotation characters within the string as literal quotes, not to be interpreted as string delimiters.

Similarly, since the backslash is an escape character, backslash characters present in the string must be prefixed with a backslash to mark them as literal characters, not to be interpreted as escape characters.

Read the following articles to understand more:

String Literal
Escape Character
Delimiter Collision
Leaning Toothpick Syndrome

For more examples, type the following at the command-line:
Code: [Select]
(getstring t "\nEnter a string: ")
And enter a string containing backslashes and/or quotation marks when prompted.

[ If I'm honest, I'm surprised that you haven't encountered this before.. ]

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: New Item in dictionary
« Reply #4 on: June 18, 2013, 08:22:03 AM »
Thanks Lee, it works now

andrew_nao

  • Guest
Re: New Item in dictionary
« Reply #5 on: June 18, 2013, 10:19:26 AM »
im gonna bookmark this for future read.
my mental capacity just cant grasp how this works at the moment

thanks for the share though

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: New Item in dictionary
« Reply #6 on: June 20, 2013, 05:36:51 AM »
Try this lines put/get a dictionary
to save a function in a drawing dictionary

(vlax-ldata-put "dict2" "function" "(defun c:test (/) (entsel \" Select something \")))")

you can run the function
(eval (read (vlax-ldata-get "dict2" "function")))




andrew_nao

  • Guest
Re: New Item in dictionary
« Reply #7 on: June 20, 2013, 01:47:15 PM »
Try this lines put/get a dictionary
to save a function in a drawing dictionary

(vlax-ldata-put "dict2" "function" "(defun c:test (/) (entsel \" Select something \")))")

you can run the function
(eval (read (vlax-ldata-get "dict2" "function")))

thanks for the sample code. i got the understanding of ldata but the links that CAB has posted a few of them say ldata isnt good to use..
i guess for small stuff it wouldnt hurt though

andrew_nao

  • Guest
Re: New Item in dictionary
« Reply #8 on: July 25, 2013, 03:18:50 PM »
ok sorry to revive this but i need to ask

i started messing with xrecord data
i wrote this up for testing
Code: [Select]
  (setq
    xlist (list '(0 . "XRECORD")
                '(100 . "AcDbXrecord")
                '(1 . "DWGPROPS")
                (cons 2 (getvar "dwgprefix")) ;title
                (cons 3 (getvar "dwgname")) ;subject         
                (cons 4 (getvar "loginname")) ;author
                (cons 6 "Comments")
                (cons 7 (getvar "dwgname")) ;keyword
                (cons 8 (getvar "loginname")) ;LastSavedBy
                (cons 9 "RevisionNo")
                (cons 300 "hello world")
)
)
now the questions i have is
1- "(cons 2, 3, 4.., etc)" are the DXF codes ??
2- (cons 300...) is for custom info, how high can i take it?
how much custom can i put in this record?
ive read the links from CAB but i didnt notice anything that says how much it can handle.


edit: i answered my own questions
#1 yes
#2 part 1 (cons 309..) is as high as i can go without getting bad dxf code error
#2 part 2 can only have 9

new question
how many records can a dwg have?




« Last Edit: July 25, 2013, 03:37:08 PM by andrew_nao »

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: New Item in dictionary
« Reply #9 on: July 25, 2013, 04:22:32 PM »
Read up on the DXF definitions: http://usa.autodesk.com/adsk/servlet/item?id=12272454&linkID=10809853&siteID=123112

Open the PDF of your version (though XData hasn't changed in quite a few years so any should do). Go to the "Advanced DXF Issues" group, under that is a sub-headin "About Extended Data (DXF)". It gives a sample of how it looks inside a DXF file and then a description of the codes and their meanings, some of them have special meanings which could cause problems if you send the wrong type of data. Note XData may contain more than one item with the same code, so you can add a whole batch of them one after another.

Just remember that XData has a limit on its total size. You use the xdsize and xdroom functions to check how much your data is going to take up and how much "room" is left for you to put into an entity's DXF data list.

As for the ldata issue, I personally don't see an issue if you wish to use it. In general people stay away from it because it's only available to ARX and Lisp, it's impossible to get at through VBA (I don't know about DotNet). So if all your code is going to be lisp, and only that is going to make use of this data - there doesn't seem to be much of a problem.

Edit: Sorry  :embarrassed: stupid me! Missed that you were talking about XRecords. No those don't have an issue with what you place inside them, you can even also add numerous codes of the same number into the same XRecord. Though usually you'd have one piece of data per XRecord placed inside a dictionary given a name / autoname. Then you can use dictsearch to find the relevant xrecord or dictnext if you simply want to step through them.
« Last Edit: July 25, 2013, 04:29:38 PM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

andrew_nao

  • Guest
Re: New Item in dictionary
« Reply #10 on: July 26, 2013, 08:58:13 AM »
thats alot of reading (300 pages) your help is much appreciated

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: New Item in dictionary
« Reply #11 on: July 26, 2013, 11:29:56 AM »
You don't need to read all of it. I've never read through that entire thing. I only use it as a reference to look-up the meanings for each of the codes.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

andrew_nao

  • Guest
Re: New Item in dictionary
« Reply #12 on: July 26, 2013, 12:15:58 PM »
another question

in the code i posted above how can i get a variable in places of the dwgprops?

'(1 . "dwgprops") <-- as it is now

'(1 . var) <-- what im trying to do


irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: New Item in dictionary
« Reply #13 on: July 26, 2013, 01:39:22 PM »
Instead of using quote (i.e. the ' prefix, which takes what you've written as litteral) you make the list item using cons:
Code - Auto/Visual Lisp: [Select]
  1. (setq var "dwgprops")
  2. (cons 1 var) ;Returns (1 . "dwgprops")
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

andrew_nao

  • Guest
Re: New Item in dictionary
« Reply #14 on: July 26, 2013, 02:37:00 PM »
Instead of using quote (i.e. the ' prefix, which takes what you've written as litteral) you make the list item using cons:
Code - Auto/Visual Lisp: [Select]
  1. (setq var "dwgprops")
  2. (cons 1 var) ;Returns (1 . "dwgprops")

 :ugly:  i knew that!... lol

ty sir