Skip to content

Commit a09c4b6

Browse files
committed
add AutoLISP example script for getting XDATA
1 parent 07778be commit a09c4b6

File tree

2 files changed

+52
-18
lines changed

2 files changed

+52
-18
lines changed

autolisp/showxdata.lsp

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(defun C:SHOWXDATA (/ appid entity_list xdata_list)
2+
(setq appid (getstring "Show XDATA for which AppID:"))
3+
(setq entity_list (entget (car (entsel)) (list appid)))
4+
(setq xdata_list (assoc -3 entity_list))
5+
(car (cdr xdata_list))
6+
)

docs/source/tutorials/custom_data.rst

+46-18
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,36 @@ storing XData, AppData and extension dictionaries in DXF entities and objects,
1818
storing XRecords in the OBJECTS section and ends by using proxy entities or
1919
even extending the DXF format by user defined entities and objects.
2020

21+
This is the common prolog for all Python code examples shown in this tutorial:
22+
23+
.. code-block:: Python
24+
25+
import ezdxf
26+
27+
doc = ezdxf.new()
28+
msp = doc.modelspace()
29+
2130
Retrieving User Data
2231
--------------------
2332

2433
Retrieving the is a simple task by `ezdxf`, but often not possible in CAD
25-
applications without using the scripting features (AutoLisp) or even the SDK.
34+
applications without using the scripting features (AutoLISP) or even the SDK.
35+
36+
AutoLISP Resources
37+
++++++++++++++++++
38+
39+
- `Autodesk Developer Documentation <http://help.autodesk.com/view/OARX/2018/ENU/>`_
40+
- `AfraLISP <https://www.afralisp.net/index.php>`_
41+
- `Lee Mac Programming <http://www.lee-mac.com>`_
2642

2743
.. warning::
2844

29-
I have no experience with AutoLisp so far and I created this scripts for
30-
AutoLisp while writing this tutorial. There may be better ways to accomplish
45+
I have no experience with AutoLISP so far and I created this scripts for
46+
AutoLISP while writing this tutorial. There may be better ways to accomplish
3147
these tasks, and feedback on this is very welcome.
3248
Everything is tested with BricsCAD and should also work with the
3349
full version of AutoCAD.
3450

35-
This is the common prolog for all Python code examples shown in this tutorial:
36-
37-
.. code-block:: Python
38-
39-
import ezdxf
40-
41-
doc = ezdxf.new()
42-
msp = doc.modelspace()
43-
4451
Header Section
4552
--------------
4653

@@ -71,12 +78,12 @@ Getting the data in `BricsCAD` at the command line::
7178
: USERI1
7279
New current value for USERI1 (-32768 to 32767) <4711>:
7380

74-
Getting the data by AutoLisp::
81+
Getting the data by AutoLISP::
7582

7683
: (getvar 'USERI1)
7784
4711
7885

79-
Setting the value by AutoLisp::
86+
Setting the value by AutoLISP::
8087

8188
: (setvar 'USERI1 1234)
8289
1234
@@ -105,7 +112,7 @@ variable:
105112

106113
.. image:: gfx/custom_header_property.png
107114

108-
AutoLisp script for getting the custom document properties:
115+
AutoLISP script for getting the custom document properties:
109116

110117
.. code-block:: Lisp
111118
@@ -163,7 +170,7 @@ which may never be used by `ezdxf` in the future.
163170
The data is stored as XDATA in then BLOCK entity of the model space for DXF R12
164171
and for DXF R2000 and later as a DXF :class:`~ezdxf.entities.Dictionary`
165172
in the root dictionary by the key ``EZDXF_META``.
166-
See following chapters for accessing such data by AutoLisp.
173+
See following chapters for accessing such data by AutoLISP.
167174

168175
XDATA
169176
-----
@@ -173,7 +180,7 @@ Each application needs a unique AppID registered in the AppID table to add
173180
XDATA to an entity. The AppID ``ACAD`` is reserved and by using `ezdxf`
174181
the AppID ``EZDXF`` is also registered automatically.
175182
The total size of XDATA for a single DXF entity is limited to 16kB for AutoCAD.
176-
XDATA is supported by all DXF versions and is accessible by AutoLisp.
183+
XDATA is supported by all DXF versions and is accessible by AutoLISP.
177184

178185
The valid group codes for extended data are limited to the following values,
179186
see also the internals of :ref:`xdata_internals`:
@@ -204,6 +211,27 @@ Group Code Description
204211
.. literalinclude:: src/customdata/xdata.py
205212
:lines: 10-40
206213

214+
AutoLISP script for getting XDATA for AppID ``YOUR_UNIQUE_ID``:
215+
216+
.. code-block:: Lisp
217+
218+
(defun C:SHOWXDATA (/ entity_list xdata_list)
219+
(setq entity_list (entget (car (entsel)) '("YOUR_UNIQUE_ID")))
220+
(setq xdata_list (assoc -3 entity_list))
221+
(car (cdr xdata_list))
222+
)
223+
224+
Script output:
225+
226+
.. code-block:: Text
227+
228+
: SHOWXDATA
229+
Select entity: ("YOUR_UNIQUE_ID" (1000 . "custom text") (1040 . 3.141592) ...
230+
231+
.. seealso::
232+
233+
`AfraLISP XDATA tutorial <https://www.afralisp.net/autolisp/tutorials/extended-entity-data-part-1.php>`_
234+
207235
Extension Dictionaries
208236
----------------------
209237

@@ -221,7 +249,7 @@ AutoCAD internally to store the handle to the :ref:`extension_dictionary` and
221249
the :ref:`reactors` in DXF entities.
222250
`Ezdxf` supports these kind of data storage for any AppID and the data is
223251
preserved by AutoCAD and BricsCAD, but I haven't found a way to access this
224-
data by AutoLisp or even the SDK.
252+
data by AutoLISP or even the SDK.
225253
So I don't recommend this feature to store application defined data,
226254
because :ref:`extended_data` and the :ref:`extension_dictionary` are well
227255
documented and safe ways to attach custom data to entities.

0 commit comments

Comments
 (0)