3dwannab Posted July 2, 2018 Posted July 2, 2018 Hi all, I have a script taken from here which I've tweaked to get the count. (defun C:XREFCNT (/ i x) (setq i 0) (vlax-for x (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object)) ) (if (eq (vla-get-IsXref x) :vlax-true) (setq i (1+ i)) ) ) i ) XREFCNT returns the number in the commandline. How do I then do an alert, the code below doesn't work. It errors with: error: bad argument type: fixnump: # (if XREFCNT > 0) (alert (strcat "Number of External Reference Drawings = " (itoa (strcat XREFCNT))) ) Quote
Aftertouch Posted July 2, 2018 Posted July 2, 2018 The command XREFCNT is defined as '#'. Change this: (itoa (strcat XREFCNT)) To: (itoa (strcat (XREFCNT))) And change (defun C:XREFCNT (/ i x) To: (defun XREFCNT (/ i x) Quote
hanhphuc Posted July 2, 2018 Posted July 2, 2018 (if (> (setq c (XREFCNT)) 0) (alert (strcat "Number of External Reference Drawings = " (itoa c))) ) Quote
3dwannab Posted July 2, 2018 Author Posted July 2, 2018 Thanks to both of you. Here's the working code. (defun XREFCNT (/ i x) (setq i 0) (vlax-for x (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object)) ) (if (eq (vla-get-IsXref x) :vlax-true) (setq i (1+ i)) ) ) i ) ; SETS XREF PATHS TO "RELATIVE" IF IN DRAWING (if (> (setq c (XREFCNT)) 0) ; (alert (strcat "Number of External Reference Drawings = " (itoa c))) (command "-XREF" "T" "*" "R") ) Quote
BIGAL Posted July 3, 2018 Posted July 3, 2018 You can use C:xrefcnt but defun call has to match (c:xrefcnt) Is there a reason for IF to be outside the defun ? (defun c:XREFCNT2 (/ i x) (setq i 0) (vlax-for x (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object)) ) (if (eq (vla-get-IsXref x) :vlax-true) (setq i (1+ i)) ) ) (if (> i 0) (alert (strcat "Number of External Reference Drawings = " (rtos i 2 0))) (alert "No Xrefs") ) ) (c:XREFCNT2) Quote
3dwannab Posted July 3, 2018 Author Posted July 3, 2018 Is there a reason for IF to be outside the defun ? Because I have this below to use the redir command. And I call it elsewhere in the startup script. (if (vl-string-search "company_name_here" (strcat(getvar 'dwgprefix))) (progn (if (> (setq c (XREFCNT)) 0) (Command ".script" "XRef_company_name_here_Paths_Fix.scr") ) (setq StyleSheet "company_name_here.ctb") ) ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.