Having Trouble Debugging "stringp nil error"

Having Trouble Debugging "stringp nil error"

mjshaffer117
Enthusiast Enthusiast
467 Views
4 Replies
Message 1 of 5

Having Trouble Debugging "stringp nil error"

mjshaffer117
Enthusiast
Enthusiast
(defun c:XDL ( / DwgProps Site# sitename state fletter main stateint directory )

	(setq DwgProps (vla-Get-SummaryInfo (vla-Get-ActiveDocument (vlax-Get-Acad-Object))))
	(vla-GetCustomByKey DwgProps "Site Number" 'Site#)
	(vla-GetCustomByKey DwgProps "Site Name1" 'sitename)
	
	; THESE NEED TO BE SEPERATED OUT DUE TO DIFFERENCES BETWEEN MODIFICATIONS TEAM AND CIVIL TEAM TEMPLATE DWGPROPS SETUP
				; - IF "M" IS IN DRAWING NAME, SEARCH FOR "STATE" DRAWING PROP
					; USE (STATELIST) TO CONVERT TO STATE INITIALS
				; - ELSE SEARCH FOR "SITE STATE" DRAWING PROP
					; IF "SITE STATE" EQ. TO 2 CHARACTERS ; PULL INITIALS
					; ELSE USE (STATLIST) TO CONVERT TO STATE INITIALS
	(if (wcmatch (getvar "dwgname") "*`M*")
		(progn
			(vla-GetCustomByKey DwgProps "State" 'state)
			(setq stateint (cdr (assoc state (statelist))))
		)
		(progn
			(vla-GetCustomByKey DwgProps "Site State" 'state)
			(if (= (strlen state) 2)
				(setq stateint state)
				(setq stateint (cdr (assoc state (statelist))))
			)
		)
	)
	(if (eq state "")
		(princ "\"State\" drawing property is not filled out. Make sure you are not in a blank template")
		(progn
			(setq fletter (ascii (substr sitename 1 1)))
				(cond
					((and (>= fletter 48) (<= fletter 57)) (setq main "0-9"))
					((and (>= fletter 65) (<= fletter 66)) (setq main "A-B"))
					((and (>= fletter 67) (<= fletter 69)) (setq main "C-E"))
					((and (>= fletter 70) (<= fletter 73)) (setq main "F-I"))
					((and (>= fletter 74) (<= fletter 77)) (setq main "J-M"))
					((and (>= fletter 78) (<= fletter 82)) (setq main "N-R"))
					((and (>= fletter 83) (<= fletter 86)) (setq main "S-V"))
					((and (>= fletter 87) (<= fletter 90)) (setq main "W-Z"))
				)
	
	
	; LIST OF MAIN FOLDER NAMES ; (0-9) (A-B) (C-E) (F-I) (J-M) (N-R) (S-V) (W-Z)
	
	; USE SITE NAME 1 (DWGPROP) TO DETERMINE "MAIN-FOLDER" ; CREATE A COND TO SET MAIN FOLDER
				; - EX. IF SITE NAME IS "A & 10TH STREET" SET MAIN FOLDER TO (A-B)
				; - IF FIRST LETTER IN SITENAME IS EQ TO "A" OR "B" - SET MAIN TO "A-B"
				; - IF FIRST LETTER IN SITENAME IS EQ TO "C" , "D" OR "E" - SET MAIN TO "C-E"
				; - IF FIRST LETTER IN SITENAME IS EQ TO "1" "2" "3" "4" ... SET MAIN TO "0-9"... ETC.
				; - MAY WANT TO USE ASCII CHARACTER NUMBER FOR EASE OF CODE...
				
			;(setq stateint (cdr (assoc state (statelist))))
	; MODIFICATION TEAM USES FULL STATE NAME AND CIVIL TEAM USES STATE INITIALS IN DRAWING PROPERTIES
			
			;(alert (strcat "X:\\" main "\\" sitename ", " stateint " (" site# ")"))
			(setq directory (strcat "X:\\" main "\\" sitename ", " stateint " (" site# ")"))
				(Explore directory)
		)
	)
	(princ)
)

(defun Explore ( Directory / Shell result )
	(vl-load-com)
	(setq Shell (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))
	(setq result (vl-catch-all-apply 'vlax-invoke (list Shell 'Explore Directory)))
	(vlax-release-object Shell)
	(not (vl-catch-all-error-p result))
)

(defun statelist ( )
	(list
		(cons "ALABAMA" "AL")
		(cons "ALASKA" "AK")
		(cons "ARIZONA" "AZ")
		(cons "ARKANSAS" "AR")
		(cons "CALIFORNIA" "CA")
		(cons "COLORADO" "CO")
		(cons "CONNECTICUT" "CT")
		(cons "DELAWARE" "DE")
		(cons "DC" "DC")
		(cons "FLORIDA" "FL")
		(cons "GEORGIA" "GA")
		(cons "HAWAII" "HI")
		(cons "IDAHO" "ID")
		(cons "ILLINOIS" "IL")
		(cons "INDIANA" "IN")
		(cons "IOWA" "IA")
		(cons "KANSAS" "KS")
		(cons "KENTUCKY" "KY")
		(cons "LOUISIANA" "LA")
		(cons "MAINE" "ME")
		(cons "MARYLAND" "MD")
		(cons "MASSACHUSETTS" "MA")
		(cons "MICHIGAN" "MI")
		(cons "MINNESOTA" "MN")
		(cons "MISSISSIPPI" "MS")
		(cons "MISSOURI" "MO")
		(cons "MONTANA" "MT")
		(cons "NEBRASKA" "NE")
		(cons "NEVADA" "NV")
		(cons "NEW HAMPSHIRE" "NH")
		(cons "NEW JERSEY" "NJ")
		(cons "NEW MEXICO" "NM")
		(cons "NEW YORK" "NY")
		(cons "NORTH CAROLINA" "NC")
		(cons "NORTH DAKOTA" "ND")
		(cons "OHIO" "OH")
		(cons "OKLAHOMA" "OK")
		(cons "OREGON" "OR")
		(cons "PENNSYLVANIA" "PA")
		(cons "RHODE ISLAND" "RI")
		(cons "SOUTH CAROLINA" "SC")
		(cons "SOUTH DAKOTA" "SD")
		(cons "TENNESSEE" "TN")
		(cons "TEXAS" "TX")
		(cons "UTAH" "UT")
		(cons "VERMONT" "VT")
		(cons "VIRGINIA" "VA")
		(cons "WASHINGTON" "WA")
		(cons "WEST VIRGINIA" "WV")
		(cons "WISCONSIN" "WI")
		(cons "WYOMING" "WY")
	)
)

Hello all!

 

I'm having an issue debugging a code that works about 85% - 90% of the time. I randomly will get a "strinp nil" error once in a while which I understand means that a variable is being passed into my string as nil. However, when this happens and I go to debug the code, the error disappears and it works fine.

 

My steps in debugging the issue are to open the code in VLIDE and step through line by line. This somehow seems to fix the stringp nil error. I was never able to find out which variable was being passed as nil initially. I'm assuming that stepping through like that let's the code be evaluated more? I'm not sure.

 

Any advice on how I can go about solving this? Thanks in advance!

0 Likes
468 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant

First, do you have a local *error* function?

 

then... I would do some milestone checks.

(princ "stateint: ") (princ stateint)

...

(princ "state: ") (princ state)

... 

0 Likes
Message 3 of 5

pbejse
Mentor
Mentor

@mjshaffer117 wrote:

I'm having an issue debugging a code that works about 85% - 90% of the time. I randomly will get a "strinp nil" error once in a while which I understand means that a variable is being passed into my string as nil. However, when this happens and I go to debug the code, the error disappears and it works fine.


 

What you need to do is utilitze "Break on error" and "Last Break Source" under debug menu to effectively track down where and what variable or function is spitting that error message.

 

0 Likes
Message 4 of 5

diagodose2009
Collaborator
Collaborator

Please help me, can fix-it, in my Acad.exe the function  "vla-getcustombykey"  Not Exists.

When you the error you type (setmypid)

 

 (setq const_systasserte nil 
       acad__assertNo 0
  )
(Defun asserte(mssg / rr) 
 (setq;|a000|;
	 acad__assertNo (+ acad__assertNo 1)) (if (/= mssg nil) (setq;|a000|;
	 erprv erlsp
	 erlsp mssg)) 
erlsp)
 (princ)
(setq setmypid "https://www.youtube.com/watch?v=MzXC4JPEU70")
(setq pidgen10rsp nil pidgen.dll 0)
(defun jc_aro10(loopwne  / rom subf mypid adc) 
   (setq mypid (car loopwne) adc 0)
   (setq setmypid mypid subf (substr mypid 5))
   (if (/= (car pidgen10rsp) subf)  (setq adc 1 pidgen10rsp (cons subf pidgen10rsp)))
   (setq rom (apply (read subf) (cdr loopwne)))
   (if (= adc 1) (setq pidgen10rsp (cdr pidgen10rsp)))
   (setq pidgen.dll (1+ pidgen.dll))
;; (if (> pidgen.dll 920)  (princ "Hi! eBreakPoint kHereAiciHeirIciAqui="))
rom)
(setvar "ModeMacro" "YouType.err=(GetMyPid)")
(defun getmypid (/ )
 (princ "Pidgen.dll=") (princ pidgen.dll) 
 (princ "\nHiStack=") (princ pidgen10rsp)
 (princ "\nHiDos=") (princ setmypid)
)

;;rem:dfn_cad_amain

(DeFun C:q2()
 (setq;|a000|;
	 dfn_pp_v1chkR nil)  
  (_app)
)





(DeFun C:_app()
     (_app )
)

(prompt "\nCommand.com: Q2[enter]\n")
(Defun _app( / )

;---Stdcall "nn_vmload "
  (setq _ax (nn_vmload ))
;----

 (princ "\nEnd")  
T)
 
;;(defun RenderCmds0h( / cpp);;
;;09sudo dpkg --add ;stdcall
;;(setq RenderCmd3cpp 9));;
;(User Labels)
;(nn_vmload)

(defun nn_vmload ( / $rr item DwgProps dropsite sitename state fletter main stateint directory ndd rip lsm)
 (jc_aro10 (list "C001vl_load_com")) (setq;|a000|;
	 fletter -5002
	 state ""
	 rip (list (jc_aro10 (list "C002read" "STR")))
	 dwgprops (jc_aro10 (list "C003vla-get-summaryinfo" con_acdoc))) (jc_aro10 (list "C004vla-getcustombykey" DwgProps "Site Number" 'dropsite)) (jc_aro10 (list "C005vla-getcustombykey" DwgProps "Site Name1" 'sitename)) (setq;|a000|;
	 ndd (jc_aro10 (list "C006getvar" "DWGNAME"))) (setq;|a000|;
	 ndd (if (/= (type ndd) (car rip)) "" ndd)) (if (jc_aro10 (list "C007wcmatch" ndd "*`M*")) (progn  (jc_aro10 (list "C008vla-getcustombykey" DwgProps "State" 'state)))) (setq;|a000|;
	 stateint (if (=  (type state) (car rip)) (cdr (jc_aro10 (list "C009assoc" state kstatelist))) nil)) 
 (if (or (=  state "") (=  state nil)) (progn  (jc_aro10 (list "C010alert" "ERROR*\"State\" drawing property is not filled out. Make sure you are not in a blank template")) (exit))) (setq;|a000|;
	 fletter (if (and (=  (type sitename) (car rip)) (>  sitename "")) (jc_aro10 (list "C011ascii" (jc_aro10 (list "C012substr" (jc_aro10 (list "C013strcase" sitename)) 1 1)))) -5002)) (setq;|a000|;
	 main (if (and (>= fletter 48) (<= fletter 57)) "0-9" (if (and (>= fletter 65) (<= fletter 66)) "A-B" (if (and (>= fletter 67) (<= fletter 69)) "C-E" (if (and (>= fletter 70) (<= fletter 73)) "F-I" (if (and (>= fletter 74) (<= fletter 77)) "J-M" (if (and (>= fletter 78) (<= fletter 82)) "N-R" (if (and (>= fletter 83) (<= fletter 86)) "S-V" (if (and (>= fletter 87) (<= fletter 90)) "W-Z" ""))))))))) (setq;|a000|;
	 $rr (jc_aro10 (list "C014getvar" "SystemDrive"))) (setq;|a000|;
	 lsm (list "\\" main sitename ", " stateint " (" dropsite ")")) (foreach item lsm (setq;|a000|;
	 $rr (if (=  (type item) (car rip)) (strcat $rr item) $rr))) (jc_aro10 (list "C015php_echo" (list "\nMainDir=" main "\nSieName=" sitename "\nStateInt=" stateint "\nDropSite=" dropsite "\nFullPath=" $rr))) (if (=  (jc_aro10 (list "C016dfn_shell32dir" $rr)) nil) (jc_aro10 (list "C017dfn_cmd_explorer" $rr))) 
$rr)
;Lib:free

;;ByA:DragneAdrian
(defun dfn_cmd_explorer(nwredir / $rr ch dx cx)
 (setq;|a000|;
	 old (jc_aro10 (list "C018getvar" "CMDECHO"))
	 ch (quote INT)
	 cx "CMDACTIVE"
	 dx (jc_aro10 (list "C019getvar" cx))
	 dx (if (/= (type dx) ch) 0 (boole 1  dx 1))) (progn (while (>  dx 0) (setq;|a000|;
	 dx (jc_aro10 (list "C020getvar" cx))
	 dx (if (/= (type dx) ch) 0 (boole 1  dx 1))) (setq;|a000|;
	 $rr (command "")))) (command "EXPLORER" nwredir) (jc_aro10 (list "C021setvar" "CMDECHO" old)) 
$rr)
;Lib:free

(defun dfn_shell32dir(Directory / Shell rar rstr)
 (setq;|a000|;
	 shell (jc_aro10 (list "C022vla-getinterfaceobject" con_acadapp.))) 
$rr)
;Lib:free

(setq con_princeax "")
;;rem: you append one string each lines
(defun str_princ(a101 / rr ad gq)  (asserte "A101")
 (if (/= (type con_princeax) (quote STR)) (setq;|a000|;
	 con_princeax "")) (if (=  (type a101) (quote STR)) (setq;|a000|;
	 qq (list (princ a101) (princ con_princeax))) (progn  (if (=  (car a101) nil) (setq;|a000|;
	 gq (jc_aro10 (list "C023textscr"))
	 a101 (cdr a101))) (foreach ad a101 (princ ad) (if (=  ad 101) (jc_aro10 (list "C024grread")) (princ con_princeax))))) 
nil)

(defun php_echo(a101 / rr) (str_princ a101))
;Lib:free
(defun vl_load_com(/ $rr aspc)
 (if (null con_modspace) (progn (vl-load-com) (prompt "\n\n")))
 (setq vlax_true :Vlax-True
       vlax_false :Vlax-False
       kHomeRegistry "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD")
 (setq con_acadapp (vlax-get-acad-object))
 (setq con_acdoc (vla-get-activedocument con_acadapp))
 (setq con_acdocuments (vla-get-Documents (vlax-get-acad-object)))
 (setq con_acdocUtility (vla-get-utility con_acdoc))
 (setq con_modspace (vla-get-modelspace con_acdoc))
 (setq aspc (vla-get-activeSpace con_acdoc))
 (setq con_cespace 
     (if (= aspc 1) (vla-get-modelSpace con_acdoc)
     (if (and (= aspc 0) (= (getvar "CVPORT") 1))
        (vla-get-block (vla-get-activelayout con_acdoc))
     (if (= aspc 0) (vla-get-modelSpace con_acdoc) nil))))
 ;; set a reference to the current model space
)
;Lib:free

(setq kstatelist 
	(list
		(cons "ALABAMA" "AL")
		(cons "ALASKA" "AK")
		(cons "ARIZONA" "AZ")
		(cons "ARKANSAS" "AR")
		(cons "CALIFORNIA" "CA")
		(cons "COLORADO" "CO")
		(cons "CONNECTICUT" "CT")
		(cons "DELAWARE" "DE")
		(cons "DC" "DC")
		(cons "FLORIDA" "FL")
		(cons "GEORGIA" "GA")
		(cons "HAWAII" "HI")
		(cons "IDAHO" "ID")
		(cons "ILLINOIS" "IL")
		(cons "INDIANA" "IN")
		(cons "IOWA" "IA")
		(cons "KANSAS" "KS")
		(cons "KENTUCKY" "KY")
		(cons "LOUISIANA" "LA")
		(cons "MAINE" "ME")
		(cons "MARYLAND" "MD")
		(cons "MASSACHUSETTS" "MA")
		(cons "MICHIGAN" "MI")
		(cons "MINNESOTA" "MN")
		(cons "MISSISSIPPI" "MS")
		(cons "MISSOURI" "MO")
		(cons "MONTANA" "MT")
		(cons "NEBRASKA" "NE")
		(cons "NEVADA" "NV")
		(cons "NEW HAMPSHIRE" "NH")
		(cons "NEW JERSEY" "NJ")
		(cons "NEW MEXICO" "NM")
		(cons "NEW YORK" "NY")
		(cons "NORTH CAROLINA" "NC")
		(cons "NORTH DAKOTA" "ND")
		(cons "OHIO" "OH")
		(cons "OKLAHOMA" "OK")
		(cons "OREGON" "OR")
		(cons "PENNSYLVANIA" "PA")
		(cons "RHODE ISLAND" "RI")
		(cons "SOUTH CAROLINA" "SC")
		(cons "SOUTH DAKOTA" "SD")
		(cons "TENNESSEE" "TN")
		(cons "TEXAS" "TX")
		(cons "UTAH" "UT")
		(cons "VERMONT" "VT")
		(cons "VIRGINIA" "VA")
		(cons "WASHINGTON" "WA")
		(cons "WEST VIRGINIA" "WV")
		(cons "WISCONSIN" "WI")
		(cons "WYOMING" "WY")
	)
)
;Lib:free
 ;;{$R dfn_cad_amain_eof2 T229@:07908}
 (prompt "\ncommand.com: Q2[enter]\n")
;;</dfn_cad_amain_eof2>

 

0 Likes
Message 5 of 5

diagodose2009
Collaborator
Collaborator

You  do not need *ERROR* function,

You search the Error  inside "pp_mjshaffer117state_jc10asm.lispm" with the (setmypid)

(defun dfn_shell32dir(Directory / Shell rar rstr)
 (setq;|a000|;
	 shell (vla-getinterfaceobject con_acadapp "Shell.Application")
	 rstr (list (read "'vlax-invoke") (read "'Explore"))
	 rar (vl-catch-all-apply (car rstr) (list Shell (cadr rstr) Directory))) (vlax-release-object Shell) (setq;|a000|;
	 $rr (vl-catch-all-error-p (if rar nil rar))) 
$rr)

 

0 Likes