adding xdata to a line

kemp

Usenet Archive
Joined
Dec 18, 2003
Messages
142
Reaction score
0
I've been playing with xdata but I am having trouble getting it to do what I want:

add a 2d point as xdata to a line.

Here is a snippet of what I've tried, but fails:

(setq lastent (entget (entlast)))
(regapp "NEWDATA")
(setq exdata
'((-3 ("NEWDATA"
(1010 . p1) ;;original is (1000 . "This is a new thing!") ))) ) (setq newent (append lastent exdata))
(entmod newent)

One issue is the ' is keeping p1 from being evaluated.

Hope someone sees a simple error I can fix. This lisp is only very slightly modified from autocad's reference.

Later I plan to add a reactor that will modify the line based on this point in xdata, but that is a whole nother issue I will cross when I get there :)

Thanks a bunch, kemp
 
(cons 1010 <value>)

Here's a easier method.

;(Xdata-add Data App String Appname Layer Handle 3D Real Int)

(defun Xdata-add (Data Part String Appname Layer Handle 3D Real Int /)

(if (not (tblsearch "appid" Part))
(regapp (strcat "YourPart_" Part))
)
(setq XDlist (list (strcat "YourPart_" Part)))
(if String (setq XDlist (append XDlist (list (cons 1000 String))))) (if Appname (setq XDlist (append XDlist (list (cons 1001 Appname))))) (if Layer (setq XDlist (append XDlist (list (cons 1003 Layer))))) (if Handle (setq XDlist (append XDlist (list (cons 1005 Handle))))) (if 3D (setq XDlist (append XDlist (list (cons 1010 3D))))) (if Real (setq XDlist (append XDlist (list (cons 1040 Real))))) (if Int (setq XDlist (append XDlist (list (cons 1070 Int))))) (entmod (append Data (list (list -3 Xdlist))))
)
 
If it just 1 string only you want to add;

(defun add_xdata_str (e a v);;;EName APPID String_value (and (not (tblsearch "APPID" a)) (regapp a)) (and (= (type e) 'ENAME) (= (type v) 'STR) (= (type a) 'STR) (entmod (append (entget e) (list (cons -3 (list (cons a (list (cons 1000 v))))))))))

-David
 
Both of these functions will be useful to me (especially in understanding what I'm doing). Thanks Rudy and David!

kemp
 
Here is the function I wrote & use...
In many cases I like to store a lot of info in an entity... You just call this function immediately after creating the item... Give it a "Program Name" (Identifier) and a list of data... (lists, strings, numbers, whatever...)

;;######################################3
; Add XData to Last entity created
(defun AddXdata (progNam xdatalist / xdlist pre)

(setq lastent (entget (entlast)))
(setq xdlist nil)

(regapp progNam)

(foreach Item xdatalist
(cond
((= (type Item) 'INT)
(setq pre 1070))
((= (type Item) 'REAL)
(setq pre 1040))
((= (type Item) 'LIST)
(setq pre 1010))
((= (type Item) 'STR)
(setq pre 1000)))

(setq wtoadd (cons pre Item))
(if (/= Item nil)
(setq xdlist (append xdlist (list wtoadd))))
)

(setq myexdata (list (list -3 (append (list progNam) xdlist))))

(setq newent
(append lastent myexdata))
(entmod newent)

(princ)
)
;;########################################
 

Latest threads

Back
Top