Author Topic: Set xdata to all elements with its layer name  (Read 1033 times)

0 Members and 1 Guest are viewing this topic.

diaa.caliph

  • Mosquito
  • Posts: 2
Set xdata to all elements with its layer name
« on: July 01, 2021, 10:18:40 PM »
i'm trying to set xdata for all elements in drawing with its layer name
the code gives error bad DXF group: (-1)
i'm not expert in autolisp i'm trying to get it done if anyone can figure it out

Code - Auto/Visual Lisp: [Select]
  1. (defun c:outline ( / i s str )
  2.    (regapp "XXXX")
  3.    (setq s (ssget "x"))
  4.        (repeat (setq i (sslength s))
  5.          (setq str (cdr (assoc 8 (entget (ssname s (setq i (1- i)))))))
  6.  
  7.                
  8.            (entmod
  9.                (list (cons -1 (ssname s (setq i (1- i))))
  10.                   '(   -3
  11.                        ( "XXXX"
  12.                          
  13.                            (1000 . str)
  14.                          
  15.                        )
  16.                    )
  17.                )
  18.            )
  19.        )
  20.    
  21.    (princ)
  22. )


EDIT (John): Added code tags.
« Last Edit: July 01, 2021, 10:35:02 PM by John Kaul (Se7en) »

CodeDing

  • Newt
  • Posts: 51
Re: Set xdata to all elements with its layer name
« Reply #1 on: July 01, 2021, 10:37:06 PM »
diaa.caliph,

Odd request if I say so myself, but it would go something like this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:OUTLINE ( / ss cnt eg lyr xd)
  2.   (regapp "XXXX")
  3.   (if (setq ss (ssget "_X"))
  4.     (repeat (setq cnt (sslength ss))
  5.       (setq eg (entget (ssname ss (setq cnt (1- cnt))) '("*")))
  6.       (setq lyr (cdr (assoc 8 eg)))
  7.       (if (setq xd (assoc -3 eg))
  8.         (setq xd (list (append xd (list (list "XXXX" (cons 1000 lyr))))))
  9.         (setq xd (list (list -3 (list "XXXX" (cons 1000 lyr)))))
  10.       );if
  11.       (entmod (append eg xd))
  12.     );repeat
  13.   ;else
  14.     (prompt "\nNO ENTITIES FOUND.")
  15.   );if
  16.   (prompt "\nOUTLINE Complete.")
  17.   (princ)
  18. );defun
  19.  

Hope that helps.
Best,
~DD
~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help?
Try my custom GPT 'AutoLISP Ace'

diaa.caliph

  • Mosquito
  • Posts: 2
Re: Set xdata to all elements with its layer name
« Reply #2 on: July 01, 2021, 11:31:59 PM »
Superb CodeDing, that's exactly what needed, big thanks