Jump to content

Recommended Posts

Posted

Hey,

 

What is the best and most common way to establish a database

in autolisp ? I mean, suppose I want to store some data, variables or parameters

to be later used and retrieved when I re-open my drawing. Is there a way to store such data in a table object of some sort ?

 

Hope my question is not too general.

 

Thanks a lot

Posted

Perhaps look into using a Dictionary to store your data within the drawing; or, if the data pertains to certain specific entities in the drawing, xData may be more suitable. Otherwise you could write the data to an external file and read it when the drawing is re-opened.

Posted

There are some variables in the drawing you can use Useri1-5 userr1-5 so thats 5 integers 5 reals but if other software accesses these you have a problem.

 

Oops same thing as DICTIONARY post above

Posted

Had a task that xdata would be usefull for so created a test.lsp

 

(setq wallvar "W2")
(setq wallsize 100.0)

; then load the next bit of lisp code do the function 
(get-or-make-Xrecord)

; Change the variables wallvar & wallsize and run multiple times both creating and retrieving. 

 

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

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

   ;;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) "BIGAL" adict)))
   )

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

(defun get-or-make-Xrecord (/ adict anXrec)

 (cond
    ;;first get our dictionary. Notice that "BIGAL" will be
   ;;created here in case it doesn't exist
   ((setq adict (get-or-create-Dict))
     (cond
       ;;if "BIGAL" is now valid then look for "BIGALVARS" Xrecord 
      ((not (setq anXrec (dictsearch adict wallvar))) 
;the variable BIGALvars is name of xrecord 
       ;;if "BIGALVARS" 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 getBIGALvars (/ vars varlist)
 ;;retrieve XRecord "wallvar" from dictionary "BIGAL"
 ;;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)
 )
)

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...