Author Topic: Need help with XDATA  (Read 6286 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Need help with XDATA
« Reply #15 on: April 21, 2005, 10:23:45 AM »
Correct. If that is possible.

Say there are 10 lwpolylines. The user intiates the command and is prompted to select 1 or many (all) then, the routine will assign the xdata accordingly to each lwpolyline with the specific information that is gathered from the lisp. The only thing that will be different would be the entity handle in the xdata, all of the rest of the xdata information will be the same.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Jimmy D

  • Guest
Need help with XDATA
« Reply #16 on: April 22, 2005, 02:11:10 AM »
Don,

I believe something like this should do it.
Didn't do much testing though, and no error-trapping etc...

Code: [Select]
(defun c:ppp ()
   (setvar "cmdecho" 0)      ;switch off command echo

;;Select one, multiple or all LWPOLYLINE's
(initget 1 "Select All")
(setq Keyw (getkword "\nEnter selection option (Select / All): "))
(cond
((= Keyw "Select")(setq SS (ssget '((0 . "LWPOLYLINE")))))
((= Keyw "All")(setq SS (ssget "X" '((0 . "LWPOLYLINE")))))
)

;check if the application has been registered
   (if (not (tblsearch "APPID" "CP_INFO"))
;if not, register it
             (regapp "CP_INFO"))            

;Get dwgprefix,... once
(setq dwgprefix# (getvar "dwgprefix"))
(setq dir (substr dwgprefix# 20 6))
(setq dwgname (getvar "DWGNAME"))

(setq Count 0)
   ;loop SS-list
  (repeat (sslength SS)
    ;select one entity from list
    (setq e (entget (ssname SS Count)))
     ;if there is no exdata
     (if (not (assoc -3 e))          
     (progn
       ;create new xdata list
       (setq xd (list (list -3 (list "CP_INFO"
                (cons 1000 "CP_TAG|SPACE")
                (cons 1000 (strcat "dde|" dir "|" dwgname "|" (cdr (assoc 5 e)))))
       )))
      ;append it and entmod
      (setq e (append e xd))
      (entmod e)
      (setq Count (+ Count 1))
      ));end if end progn
    );end repeat
(princ)
)


I left out the subroutine (didn't have much use anymore) and I've put
the xdata to append in one line.

I hope this is what you wanted  :D

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Need help with XDATA
« Reply #17 on: April 22, 2005, 07:51:14 AM »
That did it. Many thanks. That was exactly what I was trying to accomplish.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Jimmy D

  • Guest
Need help with XDATA
« Reply #18 on: April 22, 2005, 08:00:03 AM »
I'm glad that I could help!  :lol:

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Need help with XDATA
« Reply #19 on: April 22, 2005, 08:08:43 AM »
I will post the final code once I tweak it a bit.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Need help with XDATA
« Reply #20 on: April 22, 2005, 08:36:21 AM »
Ok, as promised here si the final code. I added a few thingies to it and added error functionality.

Code: [Select]

(defun tag_err (msg) ;; error handler
    (tag_exit)
    (if
      (or
        (= msg "Function cancelled")
        (= msg "quit / exit abort")
      )
      (princ)
      (princ (strcat "\nError: msg"))
    );end if
    (princ)
);end tag_err
(defun tag_start () ;; startup function
    (command "_.UNDO" "BEGIN")
    (setq olderr *error*
          *error* tag_err)
    (setq oldecho (getvar "cmdecho"))
    (setvar "cmdecho" 0)
    (princ)
);end tag_start
(defun tag_exit () ;; exit function
    (setvar "cmdecho" oldecho)
    (setq *error* olderr
          olderr nil)
    (command "_.UNDO" "END")
    (princ)
);end tag_exit
(defun c:tag ( / Keyw SS dwgprefix# dir dwgname count e xd )
(tag_start)
   (setvar "cmdecho" 0)      ;switch off command echo
(initget 0 "Select All")
(setq Keyw (getkword "\nEnter selection option (Select / All) <All> : ")) ;;Select one, multiple or all LWPOLYLINE's
   (if (or
         (= Keyw "")
         (null Keyw)
       );end or
     (setq Keyw "All")
     (setq Keyw "Select")
   )
(cond
((= Keyw "Select")(setq SS (ssget '((0 . "LWPOLYLINE")))))
((= Keyw "All")(setq SS (ssget "X" '((0 . "LWPOLYLINE")))))
)
;check if the application has been registered
   (if (not (tblsearch "APPID" "CP_INFO"))
;if not, register it
             (regapp "CP_INFO"))
;Get dwgprefix,... once
(setq dwgprefix# (getvar "dwgprefix"))
(setq dir (substr dwgprefix# 20 6))
(strip_extension (getvar "dwgname"))
(setq dwgname (strip_extension (getvar "dwgname")))
(setq Count 0)
   ;loop SS-list
  (repeat (sslength SS)
    ;select one entity from list
    (setq e (entget (ssname SS Count)))
     ;if there is no exdata
     (if (not (assoc -3 e))
     (progn
       ;create new xdata list
       (setq xd (list (list -3 (list "CP_INFO"
                (cons 1000 "CP_TAG|SPACE")
                (cons 1000 (strcat "dde|" dir "|" dwgname "|" (cdr (assoc 5 e)))))
       )))
      ;append it and entmod
      (setq e (append e xd))
      (entmod e)
      (setq Count (+ Count 1))
      ));end if end progn
    );end repeat
  (tag_exit)
(princ)
)
(defun strip_extension (filename / cnt fname found)
  (setq cnt 1
 fname "")
  (repeat (strlen filename)
    (if (= (substr filename cnt 1) ".")
      (setq found T)
    )
    (if (not found)
      (setq fname (strcat fname (substr filename cnt 1)))
    ) ;end if
    (setq cnt (1+ cnt))
  ) ;end repeat
  (eval fname)
)


Thanks again for the help.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023