Help with getting Ldata with dbx

Discussion in 'AutoCAD' started by rgood, Sep 9, 2004.

  1. rgood

    rgood Guest

    I am attempting to get data from another drawing (using dbx) created with the vlax-ldata commands

    Here is what I have, as sad as it is:

    ;;I am attempting to get information from an ldata dictionary
    ;; "MyDict" with the key "Rob"

    (defun GetLdata ( / vDwgName dbxObj dbxObj dbxObjDict)
    (setq vDwgName "d:\\dwg\\temp.dwg")

    ;;get interface object
    (setq dbxObj (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument.16"))

    ;;open drawing
    (vla-open dbxObj vDwgName)


    ;; Need to utilize an application name somehow.
    ;;(regapp "TesterApp")
    ;;

    ;;THIS IS WHERE I AM BLITZING OUT.
    (setq xxdict (vla-item (vla-get-dictionaries dbxObj) "TesterApp"))

    (if xxDict
    (vlax-ldata-get xxDict "TesterApp")

    );_end if

    (vlax-release-object dbxObj)

    ) ;_ end of defun

    I have read previous posts in regards to getting information from other drawings using dbx. The problem I am not grasping is the use of the APPNAME in the routine.

    Can someone lighten my path ahead.

    Robert Good.
     
    rgood, Sep 9, 2004
    #1
  2. rgood

    Joe Burke Guest

    Robert,

    I'm not sure what role "TesterApp" plays here. Seems you don't need it, given my
    understanding of what you are trying to do.

    Here's a test function which might help. Open a DBX doc, add a dictionary, put some
    data and get that data. Then test the two are equal.

    Be sure not to select an open file, since ObjectDBX doesn't work with those. This
    will not modify srcdoc since it isn't saved.

    Joe Burke

    ;; JB 9/9/2004
    (defun c:test ( / *acad* path srcpath srcdoc srcdictionaries putdata getdata)
    (setq *acad* (vlax-get-acad-object))
    (setq path (getvar "dwgprefix"))
    (setq srcpath (getfiled "Source File" path "dwg" 0))
    (setq srcdoc (vla-GetInterfaceObject *acad* "ObjectDBX.AxDbDocument.16"))
    (vla-open srcdoc srcpath)
    (setq srcdictionaries (vla-get-dictionaries srcdoc))
    (vlax-invoke srcdictionaries 'Add "MyDict")
    (setq putdata (vlax-ldata-put "MyDict" "Rob" "testdata"))
    (setq getdata (vlax-ldata-get "MyDict" "Rob"))
    (vlax-release-object srcdoc)
    (if (equal putdata getdata)
    (princ getdata)
    (princ "Failed ")
    )
    (princ)
    ) ;end

    using dbx. The problem I am not grasping is the use of the APPNAME in the routine.
     
    Joe Burke, Sep 9, 2004
    #2
  3. rgood

    rgood Guest

    Joe,
    Thanks for the reply. The concept you supplied writes the ldata dictionary to the current open document, not the dbx document.
    the routine needs something like:
    (vla-ldata-put dbxDoc DictName Key "string to add")
    the issue is there is no option in the vla-ldata functions to put the name of the document I want to write to. This is were I was headded with the appname situation on the prev. post.

    here is a clip of what I was using for my guide:
    (posted by peter ?? from another dbx topic)





    (defun DBXLDATAIN (DWGNAME APPNAME STRLST / DBXOBJ DBXFILE DWGNAME LOOBJ OBJ)
    (setq DBXOBJ (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument.16"))
    (vla-open DBXOBJ (findfile DWGNAME))
    (ldatalist DBXOBJ APPNAME STRLST)
    (vla-saveas DBXOBJ (vla-get-name DBXOBJ) 0)
    (vlax-release-object DBXOBJ) 'T
    ) ;_ end of defun




    (defun DBXLDATAOUT (DWGNAME APPNAME / DBXOBJ DBXFILE DWGNAME LOOBJ OBJ)
    (if (dbx-register)
    (progn
    (setq DBXOBJ (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument.16"))
    (vla-open DBXOBJ (findfile DWGNAME))
    (setq STRLST (get_ldatalist DBXOBJ APPNAME))
    (vlax-release-object DBXOBJ)
    STRLST
    ) ;_ end of progn
    ) ;_ end of if
    ) ;_ end of defun




    (defun LDATALIST (DOCOBJ APPNAME STRLST / EOBJ)
    (setq EOBJ (vla-item (vla-get-layers DOCOBJ) "0"))
    (if EOBJ
    (vlax-ldata-put EOBJ APPNAME STRLST)
    ) ;_end if
    (prin1)
    ) ;_end defun




    ; Function for retrieving ldata from a object

    (defun GET_LDATALIST (DOCOBJ APPNAME / EOBJ STRLST)
    (setq EOBJ (vla-item (vla-get-layers DOCOBJ) "0"))
    (if EOBJ
    (setq STRLST (vlax-ldata-get EOBJ APPNAME))
    ) ;_end if
    ) ;_end defun

    He is attaching his ldata to layer "0", where I am attempting to put it in a global dictionary.

    Robert Good.
     
    rgood, Sep 9, 2004
    #3
  4. rgood

    Joe Burke Guest

    Robert,

    I see what you are getting at, and I think you are right. Needs more thought
    tomorrow...

    Regards
    Joe Burke

    current open document, not the dbx document.
    document I want to write to. This is were I was headded with the appname situation on
    the prev. post.
     
    Joe Burke, Sep 9, 2004
    #4
  5. rgood

    Joe Burke Guest

    Robert,

    One last stab at it before I crash... Does this work? It assumes "MyDict" does not
    exist in the active doc or srcdoc before running the program.

    Joe Burke

    (defun c:test ( / *acad* activedoc path srcpath srcdoc
    srcdictionaries putdata getdata dict)
    (setq *acad* (vlax-get-acad-object))
    (setq activedoc (vla-get-ActiveDocument *acad*))
    (setq path (getvar "dwgprefix"))
    (setq srcpath (getfiled "Source File" path "dwg" 0))
    (setq srcdoc (vla-GetInterfaceObject *acad* "ObjectDBX.AxDbDocument.16"))
    (vla-open srcdoc srcpath)
    (setq srcdictionaries (vla-get-dictionaries srcdoc))
    (setq dict (vlax-invoke srcdictionaries 'Add "MyDict")) ;revised
    (setq putdata (vlax-ldata-put dict "Rob" "testdata")) ;use dict object
    (setq getdata (vlax-ldata-get dict "Rob"))
    (vlax-release-object srcdoc)
    (if (equal putdata getdata)
    (princ getdata)
    (princ "Failed ")
    )
    (if (setq getdata (vlax-ldata-get "MyDict" "Rob"))
    (princ "\nData returned from the active document. ")
    (princ "\nDictionary not found in open document. ")
    )
    (princ)
    ) ;end
     
    Joe Burke, Sep 9, 2004
    #5
  6. rgood

    rgood Guest

    Joe,
    I ran your routine thru the test mill and it worked. the only issue is if I re-run the routine the dbx doc did not retain the entry to ldata. I'm guessing we have to add a vla-save in there.
    I modified your setup as follows:

    (defun c:test (/ *acad* activedoc path srcpath srcdoc srcdictionaries putdata getdata dict)
    (setq *acad* (vlax-get-acad-object))
    (setq activedoc (vla-get-ActiveDocument *acad*))
    ;;(setq path (getvar "dwgprefix"))
    ;;(setq srcpath (getfiled "Source File" path "dwg" 0))
    (setq srcpath "d:\\dwg\\temp.dwg")
    (setq srcdoc (vla-GetInterfaceObject *acad* "ObjectDBX.AxDbDocument.16"))
    (vla-open srcdoc srcpath)
    (setq srcdictionaries (vla-get-dictionaries srcdoc))

    ;;test if dictionary exists
    (if (not (vla-item srcdictionaries "MyDict"))
    (setq dict (vlax-invoke srcdictionaries 'Add "MyDict"))
    (setq dict (vla-item srcdictionaries "MyDict"))
    ) ;_end if

    ;;if entry does not exist, create it.
    (if (not (vlax-ldata-get dict "Rob"))
    (setq putdata (vlax-ldata-put dict "Rob" "testdata")) ;use dict object
    ) ;_end if

    (setq getdata (vlax-ldata-get dict "Rob"))

    ;;(vla-save srcdoc);_???gives me an error?????

    (vlax-release-object srcdoc)
    (if (equal putdata getdata)
    (princ getdata)
    (princ "Failed ")
    ) ;_ end of if
    (if (setq getdata (vlax-ldata-get "MyDict" "Rob"))
    (princ "\nData returned from the active document. ")
    (princ "\nDictionary not found in open document. ")
    ) ;_ end of if
    (princ)
    );_end defun


    Robert Good.
     
    rgood, Sep 9, 2004
    #6
  7. ;;(vla-save srcdoc);_???gives me an error?????

    use: vla-saveas instead...
     
    Luis Esquivel, Sep 9, 2004
    #7
  8. rgood

    Joe Burke Guest

    Robert,

    As Luis said, use SaveAs with ObjectDBX documents.

    (vlax-invoke srcdoc 'SaveAs srcpath)

    Hi Luis. :)

    Joe Burke
     
    Joe Burke, Sep 9, 2004
    #8
  9. Robert,

    Hi Joe.... !
     
    Luis Esquivel, Sep 9, 2004
    #9
  10. rgood

    rgood Guest

    Joe, Luis,

    Thanks for helping me out.

    what a beautiful door you just opened for me.

    thanks again,

    Robert Good.
     
    rgood, Sep 10, 2004
    #10
  11. rgood

    Joe Burke Guest

    You're welcome, Robert.

    Once thing to keep in mind. If you do a SaveAs, the DBX document is saved in the
    active version format. So you might have 2004 set to save files in 2000 format.
    But the DBX doc will be 2004 format.

    Joe Burke
     
    Joe Burke, Sep 10, 2004
    #11
  12. What beautiful door is that?

    You are making a big mistake by using 'LDATA' to
    begin with.

    I would strongly advise you to use your own xrecord
    and dictionary code, and avoid LDATA like the plague.

    Rather than reiterate why, just search these newsgroups
    on google, and you'll find plenty of discussion about it.
     
    Tony Tanzillo, Sep 10, 2004
    #12
  13. rgood

    rgood Guest

    I have read all the warnings about ldata. I was planning on using xdata and xrecords due to all the warnings on ldata functions.

    As I recall, all the warnings had to do with drawing created in r14 format files.

    About a 18 mos. ago I setup a small routine that stored ldata in a commonly used notation flag. I also store some scale factor information in a global dicitonary in each drawing. I have not had any problems with corruptions, or any glitches.
    (I was, am working in 2000+ environment)

    I converted the files all the way back to r12 dxf, still with no curruptions. and frankly, ldata is so much easier to use.

    Im not sure about the speed diff. between accessing data via ldata or xdata. ??

    Frankly, I am still undecided which option my final product will use. I hear your warning and am concerned about ldata. Afterall, you never know what the end user will do.

    (I spend a couple of weeks programming a database in access for a client. After I was sure it was bulletproof, the client and I sat down for a test run. Within 30 seconds she had managed to do 3 different things that I had never expected / forsaw. And you just can't sit there and say "What in the #@%% did you do that for!!)

    Thanks for the information
    Robert Good.
     
    rgood, Sep 10, 2004
    #13
  14. I have read all the warnings about ldata. I was planning on using xdata and
    xrecords due to all the warnings on ldata functions.

    As I recall, all the warnings had to do with drawing created in r14 format
    files.
    ....


    Obviously you have *not* read all the warnings. Search for more recent posts
    on LData and ActiveX/VBA.
     
    R. Robert Bell, Sep 10, 2004
    #14
  15. rgood

    rgood Guest

    point taken,
    I have not read the more recent posts on ldata.

    Thanks for the guidance.

    Robert Good.
     
    rgood, Sep 10, 2004
    #15
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.