Jump to content

Recommended Posts

Posted

Hello!

 

How to store variables values in dwg, for use in other work sessions?

You can store lists?

 

Of course without using setq, userr, users or writing the registry.

 

Costin

Posted

Read about these functions .

 

vl-propagate 
vl-bb-ref
vl-bb-[i]set[/i]

Posted

I do not want to transfer variables from one drawing to another, but at the same drawing from one day to another.

I read somewhere that if you can store data in structure table of drawing.

 

Costin

Posted

Yes, something like that. How to do it?

Posted

Thank you. It is very helpful.

Posted (edited)

A very good material. Thank you very much.

I found some material in the book The Visual LISP Developers Bible 2003 Edition, by David M. Stein,

Chapter 15 pages 103 - 106.

Edited by Costinbos77
Posted

A very good material. Be slightly revised, but it is just the thing.

 

Thank you very much for your recommendation.

Posted

Another example may be usefull

 

(defun get-or-create-Dict (/ adict)

 ;;test if "MyDict" is already present in the main dictionary
 (if (not (setq adict (dictsearch (namedobjdict) "MyDict")))

   ;;if not present then create a new one and set the main
   ;; dictionary as owner
   (progn

     (setq adict (entmakex '((0 . "DICTIONARY")(100 . "AcDbDictionary"))))

     ;;if succesfully created, add it to the main dictionary
     (if adict (setq adict (dictadd (namedobjdict) "MyDict" adict)))
   )

   ;;if present then just return its entity name
   (setq adict (cdr (assoc -1 adict)))
 )
)

(defun get-or-make-Xrecord (/ adict anXrec)
; change to allow w1 etc and thickness 

 (cond
    ;;first get our dictionary. Notice that "MyDict" will be
   ;;created here in case it doesn't exist
   ((setq adict (get-or-create-Dict))
     (cond
       ;;if "MyDict" is now valid then look for "MyDictVARS" Xrecord 
      ((not (setq anXrec (dictsearch adict wallvar))) 
;the variable MyDictvars is name of xrecord so need to be a variable to add lots
       ;;if "MyDictVARS" was not found then create it
       ;(setq anXrec (entmakex '((0 . "XRECORD")
(setq anXrec (entmakex (list (cons 0  "XRECORD")
                               (cons 100  "AcDbXrecord")
                               ;(1 . wallvar)
   (cons 1 wallvar)
   (cons 40 wallsize)
    ;(40 . wallsize)
                               )
                    )
       )
       ;;if creation succeeded then add it to our dictionary
       (if anXrec (setq anXrec (dictadd adict wallvar anXrec)))
      )
      ;;if it's already present then just return its entity name
      (setq anXrec
       (cdr (assoc -1 (dictsearch adict wallvar)))
      )
    )
   )
 )
)
(defun getMyDictvars (/ vars varlist)
 ;;retrieve XRecord "wallvar" from dictionary "MyDict"
 ;;which in turn calls both functions above
 (setq vars (get-or-make-Xrecord))

 ;;if our Xrecord is found, then get values in group code 
 (cond (vars
        (setq varlist  (entget vars))
        (setq WALLname (cdr (assoc 1 varlist)))
        (setq WALLTHICK  (cdr (assoc 40 varlist)))
       )

       ;;otherwise return nil
       (T nil)
 )
)

Posted

Depends on what you want to save. There are basically 5 ways of saving data inside a DWG:

  1. Drawing Properties: http://www.cadtutor.net/forum/showthread.php?32034-Drawing-Properties
  2. XData
  3. XRecods inside dictionaries
  4. Lisp data: http://docs.autodesk.com/ACD/2011/ENU/filesALR/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-680c.htm (actually also uses a dictionary ... just already sorted out for you. I'm including it since it's used a bit differently from a normal dictionary)
  5. Sheet Sets (though not stricktly inside the DWg itself): http://www.cadtutor.net/forum/showthread.php?64749-Populate-Sheet-Set-Custom-Properties-by-gathering-attributes-from-a-block

Each has its use, and you must decide which is preferable for your case. E.g. 1 is for the DWG as a whole and can be listed as a column inside Windows Explorer. 5 is per tab and can be edited in the Sheet Set Manager.

 

As for 2 & 3 ... they can be attached to anything inside the DWG ... both have pro's and cons, e.g.:

 

XData has a maximum size and can only handle certain data types, while Dictionaries have no size barier and can effectively handle any data.

 

On the other hand XData has some "smart" types like linked Handles, and values which transform together with modification to the parent entity (e.g. code 1041 will be a real value number scaled together with the entity http://docs.autodesk.com/ACD/2011/ENU/filesALG/WS73099cc142f4875516d84be10ebc87a53f-7a06.htm)

Posted

Thanks for your answers.

 

Such variable xx = represents the number last drawing numbered parcel (47). When I want to fill the drawing, look in the dictionary value of xx and leave it, resulting in 48, 49, and so on.

Posted

Check out Lee-mac's auto-renumbering if you remove 27 it will renumber all block objects also adds.

Posted

Yes, for what you're referring to I'm not sure it's necessary to store the data (and even then why not simply use one of the UserI# variables?) All you need to do is find the last number itself (the text / attribute), and if the parcels are numbered using an attributed block this is very easy to do with a selection set.

 

It's basically what Lee's AutoLabelAttributes does ... simply does so through reactors checking for new block inserts, copying & erasing, then renumbering if such happens without needing extra user input.

 

Alternatively my AutoIncrement routines allow for such ideas onto any text/attrib and allows to insert / remove / shift one from somewhere in the middle as well. It is also showing how to use LispData (vlax-ldata-* dictionaries) to link the individual items to each other - which IMO would be the simplest for you to use if you do want to roll your own data store.

Posted

Thanks for the replies.

It's great with dictionaries, because if someone deletes the attribute that contains the value xx, stay eyes in the sun.

 

users, userr use them for other variables .

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...