List all xrefs in a dwg and open in notepad

List all xrefs in a dwg and open in notepad

thomas.schive
Enthusiast Enthusiast
2,584 Views
3 Replies
Message 1 of 4

List all xrefs in a dwg and open in notepad

thomas.schive
Enthusiast
Enthusiast

Hello!

 

Right now I'm trying to combine some LISP programs in order to create one that would be really useful to me right now. I want the LISP routine to first of all read alle the xrefs in a dwg, store them in a list and then open the list with the xrefs in a suitable way - a temporarily txt file in notepad for copy-paste would be great. Well, after reading on earlier forum threads and writing some myself, I've got this code:

 

;;------------------------------------------------------ START OF CODE

(defun c:listxref ()
(vl-load-com)
    (setq activedocument (vla-get-activedocument (vlax-get-Acad-Object)));_setq finit
    (setq lesblocks (vla-get-blocks activedocument));_setq finit
    (setq xrefliste '());_setq finit
    (vlax-for item lesblocks
        (setq ouixref (vlax-get-property item 'isXref));_setq finit
        (if (= ouixref :vlax-true);_si c'est vrai...
            (progn
                (setq ablock (vlax-get-property item 'Name));... Lisez le nom du block ...
                (setq xrefliste (append (list ablock) xrefliste));... ajoutez le nom de la liste ...
            );_progn finit
        );_if finit
    );_vlax for finit
    (defun ouvreznotepad (listexref skille / f of)
        (setq f (strcat (getvar 'TEMPPREFIX) "§XrefsTemp§.txt")
            of (open f "w"))
        (mapcar
            (function
                (lambda (lp)
                    (mapcar (function (lambda (n) (princ n of)(princ skille of))) lp)
                    (princ "\n" of)
                )
            )
        listexref
        )
        (close of)
        (startAPP (strcat "notepad.exe " f))
        (princ)
    )
    (print xrefliste)
    (ouvreznotepad xrefliste "\t")
    (princ)
);_defun finit
(princ)

;;------------------------------------------------------- END OF CODE

 

So, right now it manages to list all xrefs in the command window, but I can't see that it manages to open notepad with the temporarily text file that I would like it to do... Anyone who can seek out the error(s) in the code?

 

Regards ts

0 Likes
Accepted solutions (1)
2,585 Views
3 Replies
Replies (3)
Message 2 of 4

DannyNL
Advisor
Advisor
Accepted solution

You are nesting too many MAPCAR functions. The second MAPCAR gets a STRING instead of a LIST and that gives an error.

Also you are using n (number of XRef's?) but you do not set the variable.

 

Try this

 

(defun c:listxref ()
(vl-load-com)
    (setq activedocument (vla-get-activedocument (vlax-get-Acad-Object)));_setq finit
    (setq lesblocks (vla-get-blocks activedocument));_setq finit
    (setq xrefliste '());_setq finit
    (vlax-for item lesblocks
        (setq ouixref (vlax-get-property item 'isXref));_setq finit
        (if (= ouixref :vlax-true);_si c'est vrai...
            (progn
                (setq ablock (vlax-get-property item 'Name));... Lisez le nom du block ...
                (setq xrefliste (append (list ablock) xrefliste));... ajoutez le nom de la liste ...
            );_progn finit
        );_if finit
    );_vlax for finit
    (defun ouvreznotepad (listexref skille / f of)
        (setq f (strcat (getvar 'TEMPPREFIX) "§XrefsTemp§.txt")
            of (open f "w"))
        (setq n 0)
        (mapcar
            (function
                (lambda (lp)
                    (princ (setq n (1+ n)) of)(princ skille of)(princ lp of)
                    (princ "\n" of)
                )
            )
        listexref
        )
        (close of)
        (startAPP (strcat "notepad.exe " f))
        (princ)
    )
    (print xrefliste)
    (ouvreznotepad xrefliste "\t")
    (princ)
);_defun finit
(princ)

 

Message 3 of 4

thomas.schive
Enthusiast
Enthusiast

Thanks! This worked out just as planned.

 

/ts

0 Likes
Message 4 of 4

DannyNL
Advisor
Advisor

Glad I could help Smiley Happy

0 Likes