Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
andrew_nao
Posts: 1,419
Registered: ‎06-03-2002
Message 1 of 14 (678 Views)

; error: bad argument type: stringp nil

678 Views, 13 Replies
03-17-2008 06:45 AM
this code is to find an xref, detach it and insert it as a block
if its an old block it delete it and insert a new block
if its a new block with old info it will just redefine it
it works, however i still get an error at the end
; error: bad argument type: stringp nil
i know what causes it but i dont know how to correct it
if i remove the noted code below i dont get the error
can anyone tell me where im wrong?



(defun c:XLIST ()

(SETQ DS (GETVAR "DIMSCALE"))

(defun is_xref (name / ename data)
(and name
(setq ename (tblobjname "block" name))
(setq data (entget ename))
(= 4 (logand 4 (cdr (assoc 70 data))))
)
)

(SETQ SSB (SSGET "x"
(LIST (CONS 2 "*FMT*")
(cons 10
'(0.0 0.0 0.0)
)
)
)
)

;;
(setq ss (ssget "X" (list (cons 0 "INSERT")))) ; get all Blocks
(setq C 0) ; first element is 0 in ss
(repeat (sslength ss) ; repeat loop for each element in ss
(setq entity (ssname ss C)) ; get ss element 0
(setq elist (entget entity)) ; get the entity list (dxf list)
(setq blockname (strcase (cdr (assoc 2 elist)))) ; get block name
(setq blockcheck (substr blockname 1 5))
(setq fmt (strcat blockcheck "2K6"))
(setq fmtx (strcat blockname "=" fmt))


(if (or
(= blockname "FMTA1R14")
(= blockname "FMTA1")
(= blockname "FMTA2R14")
(= blockname "FMTA2")
(= blockname "FMTB1R14")
(= blockname "FMTB1")
(= blockname "FMTC1R14")
(= blockname "FMTC1")
(= blockname "FMTM1R14")
(= blockname "FMTM1")
(= blockname "FMTM2R14")
(= blockname "FMTM2")
(= blockname "FMTS1R14")
(= blockname "FMTS1")
(= blockname "FMTW1R14")
(= blockname "FMTW1")
(= blockname "FMTR1R14")
(= blockname "FMTR1")
(= blockname "FMTE1R14")
(= blockname "FMTE1")
)

(progn

(if (not (is_xref blockname))
(progn
(setvar "cmdecho" 0)
(command "erase" ssb "")
(command "-purge" "all" "*" "n")
(command "-insert" fmt "0,0" ds ds "")
(setvar "cmdecho" 1)
) ; progn
) ; if
)

============== error is with this========
(if (tblsearch "block" fmt)
(progn
(setvar "cmdecho" 0)
(command "_.insert" fmtx)
(command)
(setvar "cmdecho" 1)
) ;progn
) ;if
==================================
)


(setq C (+ C 1)) ; increment the counter
; repeat .. end repeat loop
)
;;
(setq zlst nil)
(setq zitm (tblnext "BLOCK" T))
(while (/= zitm nil)
(if (/= (assoc 1 zitm) nil)
(progn (setq znam (cdr (assoc 2 zitm)))
(setq zlst (append zlst (list znam)))))
(setq zitm (tblnext "BLOCK")))
(if (/= zlst nil)
;;(setq zret (acad_strlsort zlst))
(setq zret (acad_strlsort
(append zlst )))
(setq zret nil))
(if (= znam (strcase znam))
(setq znam1 (strcase znam t))
)
(setq b1 (substr znam1 1 5))
(setq b2 (strcat b1 "2k6"))
(if (or (= znam1 "fmta1")
(= znam1 "fmta1r14")
(= znam1 "fmta2r14")
(= znam1 "fmtb1")
(= znam1 "fmtb1r14")
(= znam1 "fmtc1")
(= znam1 "fmtc1r14")
(= znam1 "fmts1")
(= znam1 "fmts1r14")
(= znam1 "fmtw1")
(= znam1 "fmtw1r14")
(= znam1 "fmtm1")
(= znam1 "fmtm1r14")
(= znam1 "fmtm2")
(= znam1 "fmtm2r14")
(= znam1 "fmtr1")
(= znam1 "fmtr1r14")
(= znam1 "fmte1")
(= znam1 "fmte1r14")
)

(progn
(command "-xref" "d" znam)
)
)
(command "-insert" b2 "0,0" ds ds "")
(princ)


)
*Kent Cooper
Message 2 of 14 (678 Views)

Re: ; error: bad argument type: stringp nil

03-17-2008 08:49 AM in reply to: andrew_nao
My guess is that since 'fmtx' is in the form oldblock=newblock, the insert command is asking whether
you want to replace the block definition, and you need to answer Yes to that question before you
cancel the insertion with the (command) function with no arguments. Try changing
(command "_.insert" fmtx)
to
(command "_.insert" fmtx "y")

--
Kent Cooper


wrote...
this code is to find an xref, detach it and insert it as a block
if its an old block it delete it and insert a new block
if its a new block with old info it will just redefine it
it works, however i still get an error at the end
; error: bad argument type: stringp nil
i know what causes it but i dont know how to correct it
if i remove the noted code below i dont get the error
can anyone tell me where im wrong?

....
(setq blockname (strcase (cdr (assoc 2 elist)))) ; get block name
(setq blockcheck (substr blockname 1 5))
(setq fmt (strcat blockcheck "2K6"))
(setq fmtx (strcat blockname "=" fmt))
....
============== error is with this========
(if (tblsearch "block" fmt)
(progn
(setvar "cmdecho" 0)
(command "_.insert" fmtx)
(command)
(setvar "cmdecho" 1)
) ;progn
) ;if
==================================
....
Distinguished Contributor
Tom Smith
Posts: 3,729
Registered: ‎12-17-2003
Message 3 of 14 (678 Views)

Re: ; error: bad argument type: stringp nil

03-17-2008 09:18 AM in reply to: andrew_nao
I think Kent's correct.

The way to debug these kinds of command calls is to leave cmdecho turned on, so you can see what's happening.
Distinguished Contributor
andrew_nao
Posts: 1,419
Registered: ‎06-03-2002
Message 4 of 14 (678 Views)

Re: ; error: bad argument type: stringp nil

03-17-2008 10:48 AM in reply to: andrew_nao
appreciate the help as always fellas but that didnt work
still get the error
i commented out the cmdecho and it did display any errors
only the purging of linetypes and things

wrote in message news:5877689@discussion.autodesk.com...
I think Kent's correct.

The way to debug these kinds of command calls is to leave cmdecho turned on,
so you can see what's happening.
Valued Contributor
shawndoe
Posts: 73
Registered: ‎03-27-2005
Message 5 of 14 (678 Views)

Re: ; error: bad argument type: stringp nil

03-17-2008 01:53 PM in reply to: andrew_nao
Hi,

Look into setting the system variable EXPERT to 1. That will surpress confirmation dialogues. It can actually do quite a bit more then that depending on the setting, default is 0.

(setvar "EXPERT" 1)

Have a good one.
Shawndoe
Distinguished Contributor
Tom Smith
Posts: 3,729
Registered: ‎12-17-2003
Message 6 of 14 (678 Views)

Re: ; error: bad argument type: stringp nil

03-17-2008 02:07 PM in reply to: andrew_nao
The error means that a function expected a string argument and it got nulll instead.

If you want to debug this manually, you could look for possible cases where you're calling a function which expects a string and isn't getting one.

But why don't you try using VLIDE, which comes with a boat load of debugging tools?
Distinguished Contributor
andrew_nao
Posts: 1,419
Registered: ‎06-03-2002
Message 7 of 14 (678 Views)

Re: ; error: bad argument type: stringp nil

03-18-2008 06:22 AM in reply to: andrew_nao
i dont really know how to use vlide
Distinguished Contributor
andrew_nao
Posts: 1,419
Registered: ‎06-03-2002
Message 8 of 14 (678 Views)

Re: ; error: bad argument type: stringp nil

03-18-2008 06:24 AM in reply to: andrew_nao
by setting expert mode to 1 that really doesnt fix the problem
cause i know its still there
Distinguished Contributor
Tom Smith
Posts: 3,729
Registered: ‎12-17-2003
Message 9 of 14 (678 Views)

Re: ; error: bad argument type: stringp nil

03-18-2008 06:51 AM in reply to: andrew_nao
>i dont really know how to use vlide

Do you know how to use Google? Here are a few of the 287 results returned from searching "autocad vlide tutorial."

http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=2765435&linkID=9240615

http://management.cadalyst.com/cadman/Harry's+Code+Class+Newsletter+(Archives)/Harrys-Code-Class-Tips-for-Programmers-February-20/ArticleStandard/Article/detail/407767

http://discussion.autodesk.com/thread.jspa?threadID=522990

http://www.cad-manager.com/archives/9

http://gis.cadalyst.com/gis/AutoCAD/The-Visual-LISP-Integrated-Development-Environment/ArticleStandard/Article/detail/106166
Valued Contributor
YankeeSteve
Posts: 70
Registered: ‎02-08-2008
Message 10 of 14 (678 Views)

Re: ; error: bad argument type: stringp nil

03-19-2008 05:16 PM in reply to: andrew_nao
(defun c:newbee ( / CE DS EM ss ent obname nbname ent fname)
(SETQ CE (getvar "cmdecho") DS (GETVAR "DIMSCALE") EM (GETVAR "EXPERT")
ss (ssget "X" (list '(0 . "INSERT") (cons 2 "FMT*")
(cons 67 (if (= (getvar "cvport") 1) 1 0))
))
)
(setvar "cmdecho" 0) (setvar "expert" 5)
(while (and (= (type ss) 'PICKSET) (> (sslength ss) 0))
(setq obname (strcase (cdr (assoc 2 (entget (ssname ss 0)))))
ent nil nbname (strcat (substr obname 1 5) "2K6")
)
(if (member obname '("FMTA1R14" "FMTA1" "FMTA2R14" "FMTA2" "FMTB1R14"
"FMTB1" "FMTC1R14" "FMTC1" "FMTM1R14" "FMTM1"
"FMTM2R14" "FMTM2" "FMTS1R14" "FMTS1" "FMTW1R14"
"FMTW1" "FMTR1R14" "FMTR1" "FMTE1R14" "FMTE1"))
(progn
(if (setq fname (cdr (assoc 1 (tblsearch "block" obname))))
(progn (command "_.-xref" "d" obname) (setq nbname fname))
(setq ent (entdel (ssname ss 0)))
)
(if (or (tblsearch "block" nbname) (findfile nbname))
(command "_.-insert" (strcat obname "=" nbname) "0,0" ds ds "")
(if ent (entdel ent))
)
)
)
(ssdel (ssname ss 0) ss)
)
(command "-purge" "all" "*" "n")
(setvar "cmdecho" CE) (setvar "expert" EM)
(princ)
)

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community