Jump to content
3dwannab

LISP fn to return xref count and alert box

Recommended Posts

3dwannab

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)))
)

Share this post


Link to post
Share on other sites
Aftertouch

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)

Share this post


Link to post
Share on other sites
hanhphuc
   (if (> (setq c (XREFCNT)) 0)
    (alert (strcat "Number of External Reference Drawings = " (itoa c)))
    )

Share this post


Link to post
Share on other sites
3dwannab

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")
	)

Share this post


Link to post
Share on other sites
BIGAL

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)

Share this post


Link to post
Share on other sites
3dwannab
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")
	)
)

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...