Tip to use vlax-ldata-xxx function with OpenDCL

Started by Joseph, February 26, 2010, 12:31:45 AM

Previous topic - Next topic

Joseph

I saw in a post that vlax-ldata-xxx functions doesn't work with OpenDCl and it's right. But there is a method to save data with vlax-ldata-xxx when you work with OpenDCL. Lets say that we already selected an object in Autocad an appeared the OpenDCL dialog and we introduced 3 data to save to the selected object. Lets say that the dialog has a "Save" button and when we click on it the 3 entered data will be saved with vlax-ldata-put function to the selected object. Here is the code:

Code (autolisp) Select
(defun savedata()
(vlax-ldata-put selected_object ("MyKey1" "EnteredData1"))
(vlax-ldata-put selected_object ("MyKey2" "EnteredData2"))
(vlax-ldata-put selected_object ("MyKey3" "EnteredData3"))
)

(defun c:test_Form1_Save_OnClicked ()
(dcl_Control_SetKeepFocus test_Form1 NIL)    ;;Set the dialog focus ot nil
  (dcl_Control_SetEventInvoke test_Form1 1)    ;;Enables the command line, so u can enter commands now
           (dcl_SendString "(savedata) ")                      ;;This is how you start the (savedata) function throgh the command line
(dcl_Control_SetKeepFocus test_Form1 T)      ;;Set back the focus of the dialog
  (dcl_Control_SetEventInvoke test_Form1 0)    ;;Disables the command line, now u can't call functions or commands through the command line
)


I hate EED (Extended Entity Data)  >:( . The vlax-ldata-xxx more easier to use and you can save unlimited data with it  ;) .

-LONG LIVE THE VLAX-LDATA-XXX-

I hope i could help for some people who work with vlax-ldata-xxx function and didn't knew this little trick.  :)

Best regards.


owenwengerd

That's great if it works for you, but I highly discourage use of the Ldata functions. Ldata is not portable across AutoCAD versions, and its format is not documented, thereby leaving your data at the mercy of Autodesk.
Owen Wengerd (Outside The Box) / ManuSoft

Fred Tomke

Hello, and welcome to the forum. Thank you for sharing your experiences. Unfortunately, I have to disagree with you in two points:


  • I saw in a post that vlax-ldata-xxx functions doesn't work with OpenDCl and it's right.

    That's is wrong: Don't expect that anything can be changed in the drawing database while a modal form is shown or a syncronous event handler is running. If you want to change something in the drawing database you have either to close the form (and don't do anything in the drawing while the OnClose event is running!!!) or you have to call a asynchronous command similar to the way you've given in you post. Changing the SetKeepFocus property state is not needed. Changing the EventInvoke property state the way you did is like getting off the car before stopping it: the EventInvoke property controls the way the event handler shall be called. Changing the property state at runtime of the synchronous called event shouldn't have any effect. That's why I wouldn't trust that way. Have a look at this sample how to do that properly. In case your sample is a modeless form (or dockable or palette) I recommend you to do the following:
    - set the EventInvoke property state of the Save button to 1 in OpenDCL Studio, save the project and reload the project in AutoCAD.
    - the only thing you need in your event handler
Code (autolisp) Select
(defun c:test_Form1_Save_OnClicked ()  
(dcl_SendString "(savedata) ")
); c:test_Form1_Save_OnClicked

    [/li]
  • The vlax-ldata-xxx more easier to use and you can save unlimited data with it.
    That's not right. I've got an answer from ADN that there are limitations. LDATA are limited to 1023 characters (if you are saving lists convert the list into string using (vl-prin1-to-string) to get the number of reserved chars) and not at last LDATA can even destroy your drawing. We were using LDATA for years and we are converting all the LDATA into real dictionary structures. In AutoCAD 2007 vlax-ldata-list returns only the first char of the dict key. LDATA cannot be read via ActiveX.
    For all unexperienced Lisp developers I can highly recommend not to use LDATA. I've already given a link with experiences. And I'm not alone.

If anybody has problems changing anything in the drawing database while a form is still active, let me know. I can help you to control that. Even if you use LDATA  ;) !

Regards,
Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Joseph

I know that the autocad 2007 saves the first character of the ldata key and this is disturbing. What yo mean on 1023 character? I save to my objects this type of lists: ("0.00000000" "27.23496379" "39.44805586" "58.59683628" "71.28699270" "89.37963458" "111.57272113" "140.35459636" "155.17567089" "160.31370056" "212.04139236" "244.82385758" "287.00000000" "302.00000000" "323.00000000" "374.17805003" "425.25475756" "461.37503650" "492.45285970" "502.90714459" "530.26188088" "560.26502813" "591.00000000") and some lists has more than 150 of this type of data and i had never any problem.  Thats why i didn't use EED. I can open my drawings in any version of autocad and works fine the ldata except the autocad 2007.

Tell me about real dictionary. Thanks.

Fred Tomke

Hi, Blade,

yes, the way you do it, is nearly the same I did.
I built a small sample for you to point the problems.

DXF-files including too much LDATA cannot be opened anymore.
Once a drawing with LDATA is saved as DXF, you cannot open the DXF in AutoCAD anymore.
Have a try with the data.dxf. Can you open it?

  • Open data.dwg
  • Load the new.lsp
  • Type save1 into the commandline and press enter.
  • Select the line.
  • Type get_data into the commandline and press enter.
  • This is not much data.
  • Save drawing as DXF.
  • Close DXF file
  • Open DXF file anew
  • AutoCAD can open the DXF file
  • Load the new.lsp
  • Type save2 into the commandline and press enter.
  • Select the line.
  • Type get_data into the commandline and press enter.
  • This is only one additional char in Option10.
  • Save drawing as DXF.
  • Close DXF file
  • Open DXF file anew
  • AutoCAD cannot open the DXF anymore.

Objects cannot be managed anymore.

Please, tell me, which AutoCAD release are you using?
In the dbg.zip you can find some Debuggers for drawings.

  • Open LoangData.dwg
  • Load the right Debugger ARX depending on your AutoCAD release.
  • Type SnoopEnts into the commandline and press enter.
  • Pick the polygon and press enter.
  • A dialog appears. Press Extension Dict button
  • Select SC_PLANT_DATA and press DXF button.
  • Because of too much data this object cannot be managed anymore. Close all the forms.
  • The SC_PLANT_DATA key has the handle 222 in this drawing.
  • Type (handent "222") into the commandline. An entity is returned <Objectname: 7db2f550>
  • Now type (entget (handent "222")) into the commandline. Note that the return value is nil.
  • Try it with your drawings and your objects. Is the debugger form filled with something?

Hope this shows the problem a bit.

Showing the way of using real dictionaries will take a while for me to prepare. I prefer the way using ActiveX. But there is also a way using Lisp only but I'm not familiar with it.
If you only save lists like in your posts I'd prefer EED as the much easiest way and not Dictionaries. Dictionaries are designed to save complex data as you can see here. The screenshot shows the debugger info for object dictionaries.

Regards,
Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Joseph

I tested your sample. It really destroys the drawing if you use it like a DXF.  With DWG extension works without any problem. We use and almoust everybody, the DWG format.

Joseph

I tried your arx file under autocad 2010x32. I made a screenshot for you Fred. Check out.

Fred Tomke

Hi, Blade, is it really necessary to add the object's handle in the dict key's? Your polyline has the handle 425DB.
Nice to hear that LDATA work for you. Our customers got very angry that they couldn't open their DXF files anymore.
It's just a matter of time until borders are reached.

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Joseph

It's not necesary to add the handle to LDATE key. I just put it there :) With DWG files you will never have problem with LDATA only under AutoCAD 2007 :)

I was reading an article on a site and it was wrote:

Internally, LDATA is a collection of data dictionary records from which each record is accessed by a key name. Dictionaries are stored in a section of the drawing database different from the entities, one that is better optimized to locate and manipulate randomly structured data using a keyed reference. In the entity there is just a reference to the dictionary object. Performance for the entity is not compromised, and no limit exists as to how much data you can attach to it. To top it off, it is easier to attach LISP data such as lists of data. The LDATA functions make the job of attaching data to entities easy, as you will see in the next few paragraphs.

here is the url: http://www.cadalyst.com/cad/autocad/attaching-data-autocad-entity-objects-4814

Best regards.

Fred Tomke

Thank you for your reply and the link. Of course, attaching and getting LDATA is easy using vlax-ldata-... functions. I have not said anything contrary. But when you open the LongData.dwg from my previous posting and select the polygon in the drawing with the SnoopEnts command from the debugger you can see that the dictionary object cannot be managed anymore even in a DWG.

I cannot prevent you from using LDATA. But I will warn that not everything is gold that glitters around AutoCAD.

Regards,
Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Joseph

Hello Fred again. I made a screenshot of your Longdata.dwg datas, they can be accessed with LISP easy.

Best regards.

owenwengerd

Blade, the purpose of Fred's response is not to argue about how easy ldata is to use or how well it works for you, but to make sure that others don't mistake ldata as a good idea. No professional programmer should use ldata, and any mention of ldata should be accompanied by ample warnings about its danger.
Owen Wengerd (Outside The Box) / ManuSoft

Fred Tomke

Hi, Blade, as I promised, I've uploaded a sample how to create dictionaries and Xrecords which can also be read by other applications than with lisp.
Note, it is only a sample. The amount of code and time depends on the data which have to be saved. I use different types of lists and structures to save.
Since I have no knowledge and experiences in doing that using AutoLISP I only did it with ActiveX. Have a look at the commands at the beginning of the file.

Regards,
Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]