Author Topic: Dictionariy with Xrecords & how to Handle them  (Read 1930 times)

0 Members and 1 Guest are viewing this topic.

rajonminote@gmail.com

  • Mosquito
  • Posts: 1
Dictionariy with Xrecords & how to Handle them
« on: September 18, 2023, 05:40:41 PM »
I am working on retrieving and modifying fields of a block in AutoCAD 2021. The block has a dictionary attached to it and has xrecords in the dictionary.
I am trying to delete and add new xrecord to repalce the values in the xrecords but I get an error creating a Xrecord. it says invalid group-code 1002

entget of xrecord is :
((-1 . <Entity name: 3002dbb0>) (0 . "XRECORD") (5 . "117B") (102 . "{ACAD_REACTORS") (330 . <Entity name: 3002d9c0>) (102 . "}") (330 . <Entity name: 3002d9c0>) (100 . "AcDbXrecord") (280 . 1) (5 . "0") (330 . <Entity name: 3002d9b0>) (1002 . "{") (1000 . "DS_POINT") (1000 . "TO") (1000 . "String") (1000 . "Item_Group = TIEPOINT") (1000 . "DD") (1000 . "<NONE>") (1000 . "NO") (1000 . "XNE") (1000 . "N") (1000 . "0") (1000 . "0") (1000 . "DD") (1002 . "}"))


 I havve attached the screen shot of the structure within AutoCAD database.
Can some one point me in the right direction on how to update the values (1000 . "DD") to (1000 . "MR") in the xrecord and thus update the block.

Thanks
MR

BIGAL

  • Swamp Rat
  • Posts: 1434
  • 40 + years of using Autocad
Re: Dictionariy with Xrecords & how to Handle them
« Reply #1 on: September 18, 2023, 11:55:10 PM »
Afralisp has some good tutorials about using XDATA, I would start there.

https://www.afralisp.net/autolisp/tutorials/extended-entity-data-part-1.php
A man who never made a mistake never made anything

HasanCAD

  • Swamp Rat
  • Posts: 1422
Re: Dictionariy with Xrecords & how to Handle them
« Reply #2 on: September 19, 2023, 02:21:55 AM »
...
 I have attached the screen shot of the structure within AutoCAD database.
...
How did you extract the database-like this screenshot?

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8804
  • AKA Daniel
Re: Dictionariy with Xrecords & how to Handle them
« Reply #3 on: September 19, 2023, 03:57:22 AM »
...
 I have attached the screen shot of the structure within AutoCAD database.
...
How did you extract the database-like this screenshot?

Looks like OdaMfcApp, ODA's dwg inspecting tool

HOSNEYALAA

  • Newt
  • Posts: 106
Re: Dictionariy with Xrecords & how to Handle them
« Reply #4 on: September 19, 2023, 06:56:20 AM »

How did you extract the database-like this screenshot?
[/quote]

Looks like OdaMfcApp, ODA's dwg inspecting tool
[/quote]

can you see tis 
 @HasanCAD
https://www.youtube.com/watch?v=TWYLdklQL2Y&list=PLGcXVZF_4NLMQeU_dg9ZoNrrWytpTkHIP&index=7

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Dictionariy with Xrecords & how to Handle them
« Reply #5 on: September 19, 2023, 07:33:13 AM »
Hi,

Some functions from the Dictionaries library at the bottom of this page.

Code - Auto/Visual Lisp: [Select]
  1. ;; gc:GetOrCreateExtDict (gile)
  2. ;; Returns the extension dictionary of the entity.
  3. ;; The dictionary is created if it didn't already exist.
  4. ;;
  5. ;; Argument : ent (ENAME)
  6.  
  7. (defun gc:GetOrCreateExtDict (ent / elst dict)
  8.   (cond
  9.     ((cdadr (member '(102 . "{ACAD_XDICTIONARY") (setq elst (entget ent)))))
  10.     ((setq dict (entmakex
  11.                   '((0 . "DICTIONARY") (100 . "AcDbDictionary"))
  12.                 )
  13.      )
  14.      (entmod
  15.        (vl-list*
  16.          (assoc -1 elst)
  17.          (assoc 0 elst)
  18.          (assoc 5 elst)
  19.          (cons 102 "{ACAD_XDICTIONARY")
  20.          (cons 360 dict)
  21.          (cons 102 "}")
  22.          (vl-remove-if (function (lambda (x) (member (car x) '(-1 0 5)))) elst)
  23.        )
  24.      )
  25.      dict
  26.     )
  27.   )
  28. )
  29.  
  30. ;; gc:GetXrecData
  31. ;; Returns the Xrecord data (list of dotted pairs).
  32. ;;
  33. ;; Arguments
  34. ;; dict : ENAME of the dictionary
  35. ;; key : name of the Xrecord
  36.  
  37. (defun gc:GetXrecData (dict key / xrec)
  38.   (if (and
  39.         (setq xrec (dictsearch dict key))
  40.         (= (cdr (assoc 0 xrec)) "XRECORD")
  41.       )
  42.     (cdr (member (assoc 280 xrec) xrec))
  43.   )
  44. )
  45.  
  46. ;; gc:SetXrecData
  47. ;; Sets the data to the Xrecord and return the ENAME of the Xrecord.
  48. ;;
  49. ;; Arguments
  50. ;; dict : ENAME of the dictionary
  51. ;; key : name of the Xrecord
  52. ;; data : data as list of dotted pairs
  53.  
  54. (defun gc:SetXrecData (dict key data / xrec)
  55.   (if (snvalid key)
  56.     (progn
  57.       (and (setq xrec (dictsearch dict key))
  58.            (entdel (cdr (assoc -1 xrec)))
  59.       )
  60.       (dictadd
  61.         dict
  62.         key
  63.         (entmakex
  64.           (append
  65.             (list '(0 . "XRECORD")
  66.                   '(100 . "AcDbXrecord")
  67.             )
  68.             data
  69.           )
  70.         )
  71.       )
  72.     )
  73.   )
  74. )
Speaking English as a French Frog

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: Dictionariy with Xrecords & how to Handle them
« Reply #6 on: September 19, 2023, 09:42:39 AM »
Hi,

Some functions from the Dictionaries library at the bottom of this page.

Hi Gile

There is an easier way to create a dictionary for an entity
Code - Auto/Visual Lisp: [Select]
  1. (defun _get_or_create_dict (e)
  2.   (vlax-vla-object->ename
  3.       (if (eq (type e) 'ename) (vlax-ename->vla-object e) e)
  4.     )
  5.   )
  6. )

For
Code - Auto/Visual Lisp: [Select]
  1.   (setq xrec (dictsearch dict key))
  2.   (= (cdr (assoc 0 xrec)) "XRECORD")
  3. )

there is a safe alternative

Code - Auto/Visual Lisp: [Select]
  1. (dictremove dict key)

gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Dictionariy with Xrecords & how to Handle them
« Reply #7 on: September 19, 2023, 11:16:30 AM »
Hi Stefan,

There is an easier way to create a dictionary for an entity
Code - Auto/Visual Lisp: [Select]
  1. (defun _get_or_create_dict (e)
  2.   (vlax-vla-object->ename
  3.       (if (eq (type e) 'ename) (vlax-ename->vla-object e) e)
  4.     )
  5.   )
  6. )

I know this.
This library (quite old now) was designed to avoid the use of COM/ActiveX.

For
Code - Auto/Visual Lisp: [Select]
  1.   (setq xrec (dictsearch dict key))
  2.   (= (cdr (assoc 0 xrec)) "XRECORD")
  3. )

there is a safe alternative

Code - Auto/Visual Lisp: [Select]
  1. (dictremove dict key)

I guess you meant:
Code - Auto/Visual Lisp: [Select]
  1.       (and (setq xrec (dictsearch dict key))
  2.            (entdel (cdr (assoc -1 xrec)))
  3.       )
If so, you're absolutely right.
Speaking English as a French Frog

Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: Dictionariy with Xrecords & how to Handle them
« Reply #8 on: September 19, 2023, 01:09:24 PM »
Hi Stefan,

I guess you meant:
Code - Auto/Visual Lisp: [Select]
  1.       (and (setq xrec (dictsearch dict key))
  2.            (entdel (cdr (assoc -1 xrec)))
  3.       )
If so, you're absolutely right.

You are absolutely right.