Jump to content

LISP fn to return xref count and alert box


3dwannab

Recommended Posts

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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