Author Topic: store data in database  (Read 5170 times)

0 Members and 1 Guest are viewing this topic.

csgoh

  • Newt
  • Posts: 176
store data in database
« on: October 02, 2004, 12:43:08 PM »
Hi; I am new in lisp.

Is there any way to store certain data for eg, 1,2,90.0000,100.000 which represents the start point number,the end point number, its bearing in deg.minsec and its distance into the database. I've read thru' the help files on the dictionary and xrecords but could not understand much of it. I need to store lots of data of these types and then draw polygons by just calling the point numbers. any routines to this effect? Any help would be much appreciated.
Thanks

csgoh

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
store data in database
« Reply #1 on: October 02, 2004, 05:23:49 PM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

csgoh

  • Newt
  • Posts: 176
store data in database
« Reply #2 on: October 03, 2004, 03:57:01 AM »
By storing the infomation using the xdata, then the entity must exist first and appear in the drawing. I intend not to have an entity present as yet but only to store those basic info in the database first.  If the entity is present together with the basic info, then it can be deleted, which is not allowed. Any other suggestions?
Thanks

SMadsen

  • Guest
store data in database
« Reply #3 on: October 03, 2004, 06:07:54 AM »
With 'database' I suppose you mean the drawing? If the data doesn't have to be in a drawing, I would put the data in a simple ascii file. Maybe you even get the data in that form from another program?
If it does have to be in the drawing, I would use Dictionaries and XRecords to store it. The "problem" with that approach is that the project tends to grow with the need to edit the data. Data in XRecords is not as easily edited as ascii files.

csgoh

  • Newt
  • Posts: 176
store data in database
« Reply #4 on: October 06, 2004, 06:39:41 AM »
With the data stored in an ascii file, it is opened to abuse and  it has to be loaded every time the drawing is opened. I am thinking of a much secure way of storing the data. And the data is only edited if there is wrong entry, otherwise it remains intact.
Also could you further explain further when you say the project tends to grow with the need to edit the data.
Thanks.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
« Last Edit: February 07, 2006, 09:23:43 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

SMadsen

  • Guest
store data in database
« Reply #6 on: October 06, 2004, 08:30:55 AM »
Good links, CAB

csgoh, nothing is secure in AutoCAD. 95% of all data structures can be accessed directly via the API's and the rest can be accessed with a little extra effort. That being said - and your end users not being programming wizards, - dictionaries are perhaps the best way to keep data relatively undisturbed within a drawing. Relatively meaning that dictionaries can be accessed, deleted or otherwise manipulated by common means (all it takes is a single AutoLISP or VBA statement) but that normal users are not able to poke around enough to disturb the data.
The most common case of normal users destroying dictionary data is when they wblock drawings - in which case data will be lost.

With "project tends to grow with the need to edit the data" I just mean that providing interfaces to fill in data and change data is often more work than writing code to create dicts and xrecords. Just a simple dialog interface to show existing data can easily exceed the amount of code that actually creates the data.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
store data in database
« Reply #7 on: October 06, 2004, 10:17:48 AM »
Quote from: SMadsen
The most common case of normal users destroying dictionary data is when they wblock drawings - in which case data will be lost.

Agreed, unless you use a hard owned xdictionary. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

SMadsen

  • Guest
store data in database
« Reply #8 on: October 06, 2004, 10:36:08 AM »
How do you make a dictionary hard owned, and how do you get it to be wblock'ed along with graphical entities?

whdjr

  • Guest
store data in database
« Reply #9 on: October 06, 2004, 01:23:28 PM »
I think its a group code 280.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
store data in database
« Reply #10 on: October 06, 2004, 01:42:09 PM »
Sorry, I got pulled off to a meeting as I was about to post this before.

The code below will add an xdictionary to an entity, returning the entity name of the xdictionary, and subsequent code will add hard owned dictionaries to an entity's xdictionary.

Regarding wblocking, I'm referring to the common practive of using wblock filename * to purge drawings. As long as the xdictionary is attached to a permanent object, like layer "0" for example, the data will go along for the ride.

Code: [Select]
(defun AddXDictToEntity ( ename / data xdict )

    ;;
    ;;  Copyright © 2003 Michael Puckett
    ;;
    ;;  add an xdictionary to an entity if it does not
    ;;  have one, otherwise return the existing one
    ;;

    (cond

        ;;  this works with every entity
        ;;  and object I've tried, thus far

        (   (< 14 (atoi (getvar "acadver")))
            (if
                (setq xdict
                    (vlax-invoke-method
                        (vlax-ename->vla-object ename)
                       'GetExtensionDictionary
                    )
                )
                (vlax-vla-object->ename xdict)
            )
        )

        ;;  xdictionary exists, return it

        (   (cdr
                (assoc 360
                    (member
                       '(102 . "{ACAD_XDICTIONARY")
                        (setq data (entget ename))
                    )
                )
            )
        )

        ;;  i've only tested "normal" entities, table
        ;;  entities, and 3dsolids, so far code below
        ;;  works for all except viewports and linetype
        ;;  continuous ...

        (   (setq xdict
                (entmakex
                    (list
                       '(0 . "DICTIONARY")
                        (cons
                            (if
                                (vl-member-if
                                   '(lambda (x)
                                        (member x
                                           '(   (100 . "AcDbSymbolTable")
                                                (100 . "AcDbModelerGeometry")
                                                (100 . "AcDbViewport")
                                            )
                                        )
                                    )
                                    data
                                )
                                330
                                360
                            )
                            ename
                        )
                       '(100 . "AcDbDictionary")
                       '(280 . 1)
                    )
                )
            )
            (if
                (entmod
                    (append
                        (reverse (member (assoc 5 data) (reverse data)))
                        (list
                           '(102 . "{ACAD_XDICTIONARY")
                            (cons 360 xdict)
                           '(102 . "}")
                        )
                        (cdr (member (assoc 5 data) data))
                    )
                )
                xdict
            )
        )
    )
)


;;  example:


(AddXDictToEntity (tblobjname "layer" "0"))


;=======================================================================
;
; Typical data
;
;=======================================================================
; IAcadDictionary: A container object for storing and retrieving objects
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00b07a68>
;   Count (RO) = 0
;   Document (RO) = #<VLA-OBJECT IAcadDocument 00f58f8c>
;   Handle (RO) = "7059"
;   HasExtensionDictionary (RO) = 0
;   Name = AutoCAD.Application: Not applicable
;   ObjectID (RO) = 1074258440
;   ObjectName (RO) = "AcDbDictionary"
;   OwnerID (RO) = 1074257984
; Methods supported:
;   AddObject (2)
;   AddXRecord (1)
;   Delete ()
;   GetExtensionDictionary ()
;   GetName (1)
;   GetObject (1)
;   GetXData (3)
;   Item (1)
;   Remove (1)
;   Rename (2)
;   Replace (2)
;   SetXData (2)
; DXF Group Codes:
;   (-1 . <Entity name: 4007e208>)
;   (0 . "DICTIONARY")
;   (330 . <Entity name: 4007e040>)
;   (5 . "7059")
;   (100 . "AcDbDictionary")
;   (280 . 1)
;   (281 . 1)


(defun AddDictToEntityXDict ( ename symbol / xdict dict )

    ;;
    ;;  Copyright © 2003 Michael Puckett
    ;;
    ;;  add a named, hard owned dictionary to an entity's
    ;;  xdictionary if the dictionary already exists return
    ;;  it
    ;;

    (if (setq xdict (AddXDictToEntity ename))
        (cond
            (   (setq dict (dictsearch xdict symbol))
                (cdr (assoc -1 dict))
            )
            (   (dictadd xdict symbol
                    (entmakex
                       '(   (0 . "DICTIONARY")
                            (100 . "AcDbDictionary")
                            (280 . 1)
                        )
                    )
                )
            )
        )
    )
)


;;  example:


(AddDictToEntityXDict (tblobjname "layer" "0") "MyHardOwnedDick")


;=======================================================================
;
; Typical data
;
;=======================================================================
; IAcadDictionary: A container object for storing and retrieving objects
; Property values:
;   Application (RO) = #<VLA-OBJECT IAcadApplication 00b07a68>
;   Count (RO) = 0
;   Document (RO) = #<VLA-OBJECT IAcadDocument 00f58f8c>
;   Handle (RO) = "705B"
;   HasExtensionDictionary (RO) = 0
;   Name = "MyHardOwnedDick"
;   ObjectID (RO) = 1074258456
;   ObjectName (RO) = "AcDbDictionary"
;   OwnerID (RO) = 1074258448
; Methods supported:
;   AddObject (2)
;   AddXRecord (1)
;   Delete ()
;   GetExtensionDictionary ()
;   GetName (1)
;   GetObject (1)
;   GetXData (3)
;   Item (1)
;   Remove (1)
;   Rename (2)
;   Replace (2)
;   SetXData (2)
; DXF Group Codes:
;   (-1 . <Entity name: 4007e218>)
;   (0 . "DICTIONARY")
;   (5 . "705B")
;   (102 . "{ACAD_REACTORS")
;   (330 . <Entity name: 4007e210>)
;   (102 . "}")
;   (330 . <Entity name: 4007e210>)
;   (100 . "AcDbDictionary")
;   (280 . 1)
;   (281 . 1)

Cheers :D
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

whdjr

  • Guest
store data in database
« Reply #11 on: October 06, 2004, 02:23:32 PM »
Quote from: MP
Cheers :D

Cheers is right.  This stuff is awesome.

Three Cheers for Michael Puckett.

CHEERS!!!CHEERS!!!CHEERS!!!