Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

; error: bad argument type: stringp nil

13 REPLIES 13
Reply
Message 1 of 14
andrew_nao
1875 Views, 13 Replies

; error: bad argument type: stringp nil

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)


)
13 REPLIES 13
Message 2 of 14
Anonymous
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
==================================
....
Message 3 of 14
Tom Smith
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.
Message 4 of 14
andrew_nao
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.
Message 5 of 14
shawndoe
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
Message 6 of 14
Tom Smith
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?
Message 7 of 14
andrew_nao
in reply to: andrew_nao

i dont really know how to use vlide
Message 8 of 14
andrew_nao
in reply to: andrew_nao

by setting expert mode to 1 that really doesnt fix the problem
cause i know its still there
Message 9 of 14
Tom Smith
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
Message 10 of 14
YankeeSteve
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)
)
Message 11 of 14
andrew_nao
in reply to: andrew_nao

thanks for the recode/help, however it doesnt work on the formats
FMTA1, FMTB1, etc.

it erases them but doesnt insert the new one.


wrote in message news:5880729@discussion.autodesk.com...
(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)
)
Message 12 of 14
EC-CAD
in reply to: andrew_nao

Andrew,
For 'inserting' a new Title-Block (which probably has
attributes), you will need to set the variable "ATTREQ"
to 0, insert the block, then return the variable to a 1.
e.g.
(setvar "ATTREQ" 0)
.. insert your block
(setvar "ATTREQ" 1)

Bob
Message 13 of 14
andrew_nao
in reply to: andrew_nao

Bob,
Thanks for the reply however there are no attributes with these formats


wrote in message news:5883726@discussion.autodesk.com...
Andrew,
For 'inserting' a new Title-Block (which probably has
attributes), you will need to set the variable "ATTREQ"
to 0, insert the block, then return the variable to a 1.
e.g.
(setvar "ATTREQ" 0)
.. insert your block
(setvar "ATTREQ" 1)

Bob
Message 14 of 14
EC-CAD
in reply to: andrew_nao

Andrew,
You (should) take a little time to play with VLide.. having
said that.. you can debug your 'string' variables in a couple
of ways.
1) Since you don't localize your variables.. you can 'see' which string variable is 'nil' by examining them at the command
prompt. Just type a ! followed by that variable name.. e.g. !fmtx
and you will either get a 'value' .. or 'nil'. Do each variable, until
you find one that (should) be set to (something), but is nil.
2) In your code add alert statements like:
(if (= fmtx nil)(alert "fmtx is nil"))
Then when you find the culprit, fix the problem and remove
the alert statements.

Bob

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost