Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Edit/Append XDATA in Block Definition?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Anonymous
1280 Views, 4 Replies

Edit/Append XDATA in Block Definition?

I need to append custom XDATA to a block definition, using plain AutoLISP. 

 

I came up with the following routine, that works fine for general entities, e.g. a circle in the drawing:

 

 

 

(defun write-xdata-to-app(entity appname datalist / entityData exdata newent)
	;; register application name
	(regapp appname) 
	;; read entity data
	(setq entityData (entget entity))
	;; set name of app as first entry
 	(setq datalist (cons appname datalist))
	;; sets the variable exdata equal to the new extended data—in this case, a text string.
  (setq exdata
    (list
			(list -3 datalist)
    )
  )
	;; appends new data list to entity's list.
  (setq newent (append entityData exdata)) 
  ;; modify the entity with the new definition data.
	(entmod newent)
)

 

 

 

However, getting the entity name for a block definition with 

 

 

 

(setq block-def-entity-name (tblsearch "BLOCK" "myBlockName"))

 

 

 

, using my routine to append some xdata and displaying all xdata for that entity using

 

 

 

(cdr (assoc -3 (entget block-def-entity-name (list "*"))))

 

 

 

does not give me anything, even though there's already some xdata in that block definition, which can clearly be seen by reading the DXF's "0 BLOCK" group for that block.

 

Labels (1)
4 REPLIES 4
Message 2 of 5
CodeDing
in reply to: Anonymous

@Anonymous ,

 

You can not assign XDATA to a Block Definition. You can assign it to a block instance though..

You can test this with your function like so, and it will return either nil or an entity list:

(write-xdata-to-app (tblobjname "BLOCK" "myBlock") "myApp" '((1002 . "{") (1000 . "abcdef") (1002 . "}")))
...OR...
(write-xdata-to-app (car (entsel "\nSelect Block: ")) "myApp" '((1002 . "{") (1000 . "abcdef") (1002 . "}")))

 

So, if I were to assume, you are selecting a block instance and assigning the XDATA to that, then instead of retrieving that block instance you are mistakenly retrieving the block definition..

 

Hope that helps. if you have any questions please don't hesitate to ask.

Best,

~DD

 

~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help? Try my custom GPT 'AutoLISP Ace':
https://chat.openai.com/g/g-Zt0xFNpOH-autolisp-ace
Message 3 of 5
john.uhden
in reply to: CodeDing

However, you could ad the xdata to the first entity in the block definition.

For example, I made a block named "X" of just a bunch of lines.

Then:

Command: (setq e2 (tblsearch "block" "x"))
((0 . "BLOCK") (2 . "x") (70 . 0) (10 0.0 0.0 0.0) (-2 . <Entity name:
40081de0>))

Command: (setq e2 (cdr (assoc -2 e2)))
<Entity name: 40081de0>

Command: (write-xdata-to-app e2 "JFU" '((1000 . "abc")))
((-1 . <Entity name: 40081de0>) (0 . "LINE") (330 . <Entity name: 40081dc8>) (5
. "3C") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbLine") (10 1.16052
-0.716949 0.0) (11 -0.824577 -0.701695 0.0) (210 0.0 0.0 1.0) (-3 ("JFU" (1000
. "abc"))))

John F. Uhden

Message 4 of 5
Anonymous
in reply to: CodeDing

Thanks a lot for your anser, @CodeDing ! I indeed misread an XDATA (1001) section in a block definition as belonging to that block. Instead, ist actually belonged to the INSERT right above it. Attaching my custom stuff to that very INSERT now solved my problem 😁

 

Best regards from Vienna,

Heinz

Message 5 of 5
Anonymous
in reply to: john.uhden

Dear @john.uhden , thanks for your comment! I actually succeeded in adding XDATA to a block definition itself, by just placing a (-3 ...) in the respective ENTMAKE section of groupcode (0 - BLOCK). The XDATA could also be read from the actual block definition afterwards. However, my problem was that i was of the impression of needing to add XDATA to a block definition that already existed (and was produced elsewhere). Which, obviously, is not possible. It turned out, though, that the XDATA i thought belonged to that block definition, actually belonged to an INSERT within that block definition. 

 

Best regards, 

Heinz 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Customer Advisory Groups


Autodesk Design & Make Report