Problems running fndshape.lsp - gives me "too many arguments" error

Problems running fndshape.lsp - gives me "too many arguments" error

Haider_of_Sweden
Collaborator Collaborator
1,019 Views
4 Replies
Message 1 of 5

Problems running fndshape.lsp - gives me "too many arguments" error

Haider_of_Sweden
Collaborator
Collaborator

Please have a look at this lisp-script - it used to work and now it doesn't anymore. Not sure what happened between then and now. I am using AutoCAD 2016.

It's a life saver for me, to fix this irritating popup that tells me a SHX is missing. This lisp tells me where this shape-file is being used.

 

;; ------------------------------------------------------------------
;; FNDSHAPE.LSP  Copyright 2006  R.K. McSwain  all rights reserved
;;
;;  Author: R.K. McSwain
;;
;;  Initial Release [27 FEB 2005]
;;
;;  Feel free to copy, and modify as desired, just
;;  retain this header and append as necessary.
;;
;;
;; ------------------------------------------------------------------
(defun c:fndshape
		  (/	  ENT
		   LT	  OUTPUT
		   SHPNST ST
		   FN	  FP
		   I	  INS
		   ITEM	  LTENT
		   LTNAME LTOBJ
		   OBJ	  OSTR
		   REF	  SHAPENM
		   SHAPENO
		   SHPN	  STENT
		   STNAME STOBJ
		   TMP
		  )
  (vl-load-com)
  (setq output '())

    ; Step 1 - Find complex linetypes that reference a SHAPE
  (while (setq lt (tblnext "ltype" (not lt)))
    (setq ltname (cdr (assoc 2 lt)))
    (setq ltObj (tblobjname "ltype" ltname))
    (setq ltEnt (entget ltObj))
    (setq i 0)
    (while (< i (length ltEnt))
      (setq item (nth i ltEnt))
      (if (and
	    (eq (car item) 74)
	    (eq (cdr item) 4)
	  )
	(progn
	  (setq shapeno (itoa (cdr (nth (1+ i) ltEnt))))
	  (setq
	    shapenm (cdr (assoc 3 (entget (cdr (nth (+ i 2) ltEnt)))))
	  )
	  (setq	ostr
		 (strcat "LINETYPE ["	  ltname
			 "] uses SHAPE # ["
			 shapeno	  "] in the file ["
			 shapenm	  "]"
			)
	  )
	  (setq	output (cons ostr output)
		i      10000
	  )
	)
      )
      (setq i (1+ i))
    )
  )

    ; Step 2 - Find loaded SHAPE FILES
  (while (setq st (tblnext "style" (not st)))
    (setq stname (cdr (assoc 2 st)))
    (setq stObj (tblobjname "style" stname))
    (setq stEnt (entget stObj))
    (if	(eq 1 (logand (cdr (assoc 70 stEnt)) 1))
      (setq ostr
		   (strcat "The following SHAPE FILE is loaded: ["
			   (vl-princ-to-string (cdr (assoc 3 st)))
			   "]"
		   )
	    output (cons ostr output)
      )
    )
    (setq i (1+ i))
  )

    ; Step 3 - Find inserted SHAPES
  (setq tmp (ssget "X" '((0 . "SHAPE"))))
  (if tmp
    (progn
      (setq i 0)
      (while (< i (sslength tmp))
	(setq obj (ssname tmp i))
	(setq ent (entget obj))
	(setq shpn (cdr (assoc 2 ent)))
	(if (not shpn)
	  (setq shpnST "An unknown shape ")
	  (setq shpnST (strcat "SHAPE named " shpn "] "))
	)
	(setq ins (cdr (assoc 10 ent)))
	(setq ref (cdr (assoc 2 (entget (cdr (assoc 330 ent))))))

	(setq ostr (strcat shpnST
			   "is INSERTED in "
			   ref
			   " at "
			   (vl-princ-to-string ins)
		   )
	)
	(setq output (cons ostr output))
	(setq i (1+ i))
      )
    )
  )
  (if output
    (progn
      (setq output (reverse output))
      (setq fn (strcat (getenv "temp") "\\fndshape.txt"))
      (setq fp (open fn "w"))
      (foreach item output
	(write-line item fp)
      )
      (close fp)
      (startapp "notepad" fn)
    )
    (alert "Nothing found")
  )
  (princ)
)
(princ "\n Type FNDSHAPE to run...")
(princ)
0 Likes
Accepted solutions (1)
1,020 Views
4 Replies
Replies (4)
Message 2 of 5

dlanorh
Advisor
Advisor
This won't be much help, but this runs error free in 2012. I can't test it in anything higher, but perhaps someone else can.

I am not one of the robots you're looking for

0 Likes
Message 3 of 5

ВeekeeCZ
Consultant
Consultant

@Haider_of_Sweden , try to locate the line which fails first. Look HERE how to do that.

Then, perhaps, the author itself could help. @rkmcswain 

0 Likes
Message 4 of 5

Haider_of_Sweden
Collaborator
Collaborator

None of the methods helped. So I looked into the APPLOAD and erased everything I had put there that got loeaded during startup.

What I discovered was that this code was the cause FNDSHAPE stopped working:

 

;;Close all drawing without saving
;;Original code by someone on Autodesk forums
;;Modified by cadmoogle to 'Close last drawing'
(defun doc:CloseAllButActive (TrueOrFalse / cnt)
(setq cnt 0)
(vlax-for Item (vla-get-Documents (vlax-get-acad-object))
(if (= (vla-get-Active Item) :vlax-False)
(progn
(vla-close Item TrueOrFalse)
(setq cnt (1+ cnt))
)
)
)
cnt
); end defun


(defun close (/) ;added by cadmoogle to close the last drawing without saving
(command "close" "Y")
(princ)
); end defun

(defun c:CCC ( / cnt) ;Closes all drawings except active
(setq cnt (doc:CloseAllButActive :vlax-False))
(if (> cnt 0)
(princ (strcat "\n(" (itoa cnt) ") document" (if (> cnt 1) "s" "") "closed without saving."))
(princ "\nNo other documents to close.")
)
(close)
(princ)
); end defun

please note the bold part. When I commented it, things started to work again.

 

What could be the reason?

0 Likes
Message 5 of 5

DannyNL
Advisor
Advisor
Accepted solution

You cannot defun a close command as this is a protected LISP command.

So the function close has to be renamed to something different, i.e. closedwg.

0 Likes