OpenDCL Forums

OpenDCL => Runtime/AutoLISP => Topic started by: Joseph on February 26, 2010, 12:31:45 AM

Title: Tip to use vlax-ldata-xxx function with OpenDCL
Post by: Joseph on February 26, 2010, 12:31:45 AM
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.

Title: Re: Tip to use vlax-ldata-xxx function with OpenDCL
Post by: owenwengerd on February 26, 2010, 05:32:06 AM
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.
Title: Re: Tip to use vlax-ldata-xxx function with OpenDCL
Post by: Fred Tomke on February 26, 2010, 05:37:33 AM
Hello, and welcome to the forum. Thank you for sharing your experiences. Unfortunately, I have to disagree with you in two points:

Code (autolisp) Select
(defun c:test_Form1_Save_OnClicked ()  
(dcl_SendString "(savedata) ")
); c:test_Form1_Save_OnClicked

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
Title: Re: Tip to use vlax-ldata-xxx function with OpenDCL
Post by: Joseph on February 26, 2010, 08:24:54 AM
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.
Title: Re: Tip to use vlax-ldata-xxx function with OpenDCL
Post by: Fred Tomke on February 26, 2010, 11:29:51 AM
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?

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.

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 (http://www.opendcl.com/forum/index.php?topic=657.msg3283#msg3283). The screenshot shows the debugger info for object dictionaries.

Regards,
Fred
Title: Re: Tip to use vlax-ldata-xxx function with OpenDCL
Post by: Joseph on February 27, 2010, 12:43:00 AM
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.
Title: Re: Tip to use vlax-ldata-xxx function with OpenDCL
Post by: Joseph on February 27, 2010, 01:06:19 AM
I tried your arx file under autocad 2010x32. I made a screenshot for you Fred. Check out.
Title: Re: Tip to use vlax-ldata-xxx function with OpenDCL
Post by: Fred Tomke on February 27, 2010, 02:45:19 AM
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
Title: Re: Tip to use vlax-ldata-xxx function with OpenDCL
Post by: Joseph on February 27, 2010, 03:14:32 AM
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 (http://www.cadalyst.com/cad/autocad/attaching-data-autocad-entity-objects-4814)

Best regards.
Title: Re: Tip to use vlax-ldata-xxx function with OpenDCL
Post by: Fred Tomke on February 27, 2010, 04:36:26 AM
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
Title: Re: Tip to use vlax-ldata-xxx function with OpenDCL
Post by: Joseph on February 27, 2010, 05:40:12 AM
Hello Fred again. I made a screenshot of your Longdata.dwg datas, they can be accessed with LISP easy.

Best regards.
Title: Re: Tip to use vlax-ldata-xxx function with OpenDCL
Post by: owenwengerd on February 27, 2010, 06:05:01 AM
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.
Title: Re: Tip to use vlax-ldata-xxx function with OpenDCL
Post by: Fred Tomke on March 03, 2010, 02:07:46 PM
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