walton10 Posted November 3, 2010 Share Posted November 3, 2010 I am having a problem with this LISP. (defun c:LXSU () (LNSTA_Update)) The program ran fine while I was developing and testing. Now that it is complete, it throws the same error for me every time at the following line of code --- (setq mySta (JWALT_ExtractFirstSta (cdr (assoc 1 (entget (car myXList)))))) As you can see from the code, I have added in a lot of (princ ...) lines to help with debugging, so I know this is exactly the line where the error is occuring. The error I am getting reads --- Error: bad argument type: lentityp nil Error: Resetting User Environment The problem I am having with this is that, if I go back into VLISP and Load Text Into Editor (CTRL+ALT+E), the program runs fine. I tried using a (load ...) command with both a .LSP and a .FAS of just this file, but that doesn't work either. I get the same 'bad argument' error every time I run c:LXSU, unless it has been loaded directly from the VLISP editor in that file's session. I am using AutoCAD 2011 and Windows XP. Please let me know if you need any other information. I greatly appreciate you taking your time to read about my dilemma. ;;; Link Text Stationing (LNSTA_) ;;; The following LISP will ;;; Help the drafter set up and maintain ;;; links from regular stationing to details ;;; ;;; These functions have been written or modified by ;;; Joshua Walton ;;; November 2010 ;;; walton_10@msn.com ;;; ;;; credits: ;;; LISPNAME.lsp by CREDITCREATOR CREDITDATE ;;; --- Version Notes --- ;;; v0010 - Initial Development ;;; v0011 - Colors work ;;; v0012 - ;;; v0013 - start on LNDU_Update ;;; v0015 - working system (ename 0/1 0.???) ;;; v0016 - ;;; v0017 - working on stepping through and updating ;;; v0018 - working version ;;; v0019 - remove wasted foreach ;;; v0020 - smarter link text reference numbers (use "cdate") ;;; v0021 - PWV ;;; v0022 - LXS & LXNSTA_ ;;; v0023 - preloaded error (setvar "cmdecho" 0) (setq lnstaVersionNumber "0023") (setq lnstaPrefix "LNSTA_") (setq jwaltVersionNumbersList (cons (strcat lnstaVersionNumber " (" lnstaPrefix ") - Link Text Stationing") jwaltVersionNumbersList)) ;(princ (strcat "\n Link Text Stationing - Version " lnstaVersionNumber " loaded. Type LXS to run. Type LXSU to update.")) (setvar "cmdecho" 1) (princ) (defun c:LXS () (LNSTA_Main)) (defun c:LXSU () (LNSTA_Update)) (defun LNSTA_Main ( / JWALT_ExtractFirstSta x_data_add x_data_get tmp ename elist econtents ename2 ) ;;; LIST ALL LOCAL VARIABLES (JWALT_StartProgram) (LNTXT_TemporaryFunctions) (LNSTA_TemporaryFunctions) (if (setq elist (entget (setq ename (car (nentsel "\n Select text to link: "))))) (progn (if (and (listp elist) (member (cdr (assoc 0 elist)) (list "TEXT" "MTEXT" "DTEXT" "ATTRIB")) (setq econtents (cdr (assoc 1 elist))) (setq econtents (JWALT_ExtractFirstSta econtents)) );and (progn (if (setq ename2 (LNTXT_Destination econtents)) (progn (setq tmp (strcat "JWALT_" lnstaPrefix)) ;the 1070 . 0 is the source ;the 1070 . 1 is the recipient (x_data_add ename tmp (list '(1070 . 0) (cons 1040 (setq tmp2 (+ (getvar "cdate") (jwalt_random)))))) (x_data_add ename2 tmp (list '(1070 . 1) (cons 1040 tmp2))) ;color the source yellow-orange (LNTXT_ColorObject ename 40) ;color the recipient bright purple (LNTXT_ColorObject ename2 190) );progn ) ) ) ) ) (JWALT_EndProgram) );defun LNSTA_Main (defun LNSTA_Update ( / JWALT_ExtractFirstSta JWALT_ReplaceFirstSta x_data_add x_data_get tmp ename elist myUpdateList my1List my0List myNum myXList mySta ) (JWALT_StartProgram) (LNTXT_TemporaryFunctions) (LNSTA_TemporaryFunctions) (princ "\n** Temps loaded.") ;loop through the drawing database (setq ename (entnext)) (princ "\n** setq ename (entnext))") (while ename (princ "\n** while ename") ;processes (if (member (cdr (assoc 0 (entget ename))) (list "TEXT" "MTEXT" "DTEXT" "ATTRIB")) (progn (if ;if there is xData for this AppID (setq tmp (x_data_get ename (strcat "JWALT_" lnstaPrefix))) (progn (princ "\n** then extract and format for myUpdateList") ;then extract and format for myUpdateList (setq myUpdateList (cons (list ename (cdar tmp) (cdadr tmp)) myUpdateList)) ;sort the list so that source datum occur first (setq my1List (vl-remove-if-not '(lambda (e1) (= 1 (cadr e1))) myUpdateList)) (setq my0List (vl-remove-if-not '(lambda (e1) (= 0 (cadr e1))) myUpdateList)) ) ) );progn );if (princ "\n** setq ename (entnext ename)") (setq ename (entnext ename)) );while (if (listp my1List) (progn (princ "\n** if (listp my1List)") (foreach destinationList my1List (princ "\n** foreach destinationList my1List") (setq myXList nil) (if (and (setq myNum (caddr destinationList)) );and (progn (princ "\n** setq myXList (vel-remove-if-not...") (setq myXList (vl-remove-if-not '(lambda (e) (= myNum (caddr e))) my0List)) ;if matching data was found (if (listp myXList) (progn (princ "\n** setq myXList (car myXList)") (setq myXList (car myXList)) (princ "\n** setq mySta (JWALT_ExtractFirstSta (cdr...") (setq mySta (JWALT_ExtractFirstSta (cdr (assoc 1 (entget (car myXList)))))) (princ "\n** JWALT_ReplaceFirstSta (car destinationList") (JWALT_ReplaceFirstSta (car destinationList) mySta) ) );if (listp myXList) );foreach ) );foreach destinationList my1List );progn );if (listp my1List) (JWALT_EndProgram) );defun LNSTA_Update (defun LNSTA_TemporaryFunctions () (defun x_data_add (ename appID dlist / elist tmp1) (regapp appID) (setq elist (entget ename) tmp1 (list -3 (cons appID dlist)) );setq (if (< (xdsize tmp1) (xdroom ename)) (entmod (append elist (list tmp1)))) );defun x_data_add (defun x_data_get (ename appID / elist) (setq elist (entget ename (list appID))) (if (assoc -3 elist) (cdadr (assoc -3 elist))) );defun x_data_get (defun JWALT_ExtractFirstSta (myStr / myStrLen my+Pos myRS ;my Right Side myLS ;my Left Side cnt tmp myLSStartPos ) ;accepts a string ;returns Station only string or nil ;time invested: 2 hour (if (and myStr (setq myStrLen (strlen myStr)) ;vl- positions are 0-.... so adjust it by immediately adding 1 to it (if (vl-string-search "+" myStr) (setq my+Pos (1+ (vl-string-search "+" myStr))))) (progn (setq myRS (substr myStr (1+ my+Pos) 2)) (setq myLS (substr myStr 1 (1- my+Pos))) (if (and ;count backwards through the LS until non-integer is found or the 0 is reached ; returns the count (setq cnt (strlen myLS)) (while (and (/= 0 cnt) (setq tmp (substr myLS cnt 1)) (= tmp (itoa (atoi tmp))) (if (/= 0 (1- cnt)) (setq cnt (1- cnt)))) cnt) ) ;return the concatenated substring (setq myLS (substr myLS cnt (strlen myLS))) ;and return the Sta only string ) (setq tmp (strcat myLS "+" myRS)) ) ) );defun JWALT_ExtractFirstSta ;;; v0010 - Initial Development (defun JWALT_ReplaceFirstSta ( ename mySta / elist econtents eSta ) ;accepts ename and a station ;returns string with station replace or nil ;time invested: 2 hour (if (and mySta (setq econtents (cdr (assoc 1 (setq elist (entget ename))))) (setq eSta (JWALT_ExtractFirstSta econtents)) );and (progn (setq econtents (vl-string-subst mySta eSta econtents)) (entmod (subst (cons 1 econtents) (assoc 1 elist) elist)) );progn );if );defun JWALT_ReplaceFirstSta );defun LNSTA_TemporaryFunctions Quote Link to comment Share on other sites More sharing options...
Lt Dan's legs Posted November 3, 2010 Share Posted November 3, 2010 maybe (vl-load-com) Quote Link to comment Share on other sites More sharing options...
walton10 Posted November 3, 2010 Author Share Posted November 3, 2010 Thanks for your suggestion. (vl-load-com) is called in my (JWALT_StartProgram) subr, which I did not include in this post. I did try adding that specifically to this routine, but unfortunately it did not solve my problem. Quote Link to comment Share on other sites More sharing options...
walton10 Posted November 3, 2010 Author Share Posted November 3, 2010 Here are my (JWALT_StartProgram) and (JWALT_EndProgram) subrs which are included in a .FAS toolkit that is in my Startup Suite. (defun JWALT_StartProgram () ;init error (setvar "cmdecho" 0) (setvar "savetime" 10) (command "undo" "Mark") (setq jwaltDoNotExecute "execute") (setq jwaltErrorList nil) (setq jwaltUserLayer (getvar "clayer")) ;save settings (setq jwaltUserSnap (getvar "osmode")) (setq jwaltUserPickbox (getvar "pickbox")) (setq jwaltUserBlipmode (getvar "blipmode")) (setq jwaltUserAttreq (getvar "attreq")) (setq jwaltUserCLayer (getvar "clayer")) (setq jwaltUserErrorFunction *error*) ;save *error* (setq *error* JWALT_ErrorTrap) ;reassign *error* (if (null jwaltScale) (setq jwaltScale 30)) (princ) );defun ;;;*=========================================================== (defun JWALT_ErrorTrap (jwaltErrorMessage) ;define trap (command nil nil nil) (if (not (member jwaltErrorMessage '("console break" "Function Cancelled"))) (princ (strcat "\n Error: " jwaltErrorMessage))) ;print message (princ "\n Error: Resetting User Environment") ;inform user (setvar "clayer" jwaltUserLayer) ;reset settings (setvar "blipmode" jwaltUserBlipmode) (setvar "osmode" jwaltUserSnap) (setvar "pickbox" jwaltUserPickbox) (setvar "attreq" jwaltUserAttreq) (setvar "clayer" jwaltUserCLayer) (command "undo" "End") (terpri) (setq *error* jwaltUserErrorFunction) ;restore *error* (princ) );defun ;;;*=========================================================== (defun JWALT_EndProgram () ;define reset (setq *error* jwaltUserErrorFunction) ;restore *error* (setvar "clayer" jwaltUserLayer) ;reset settings (setvar "blipmode" jwaltUserBlipmode) (setvar "osmode" jwaltUserSnap) (setvar "pickbox" jwaltUserPickbox) (setvar "attreq" jwaltUserAttreq) (setvar "clayer" jwaltUserCLayer) (setvar "cmdecho" 1) (princ) );defun Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 3, 2010 Share Posted November 3, 2010 Sounds like myXList is nil, bear in mind: (listp nil) ==> T Better: (if myXList ... Quote Link to comment Share on other sites More sharing options...
walton10 Posted November 3, 2010 Author Share Posted November 3, 2010 Thanks for your suggestion Lee Mac I believe I tried this same idea yesterday, but I double checked by applying that change today and rebuilding the .FAS file. It is true that myXList is returning nil at that point, because changing that line causes the if statement to fail, so while no error is produced, the program doesn't step into the progn statements, so nothing is updated. Quote Link to comment Share on other sites More sharing options...
walton10 Posted November 3, 2010 Author Share Posted November 3, 2010 If i use a (load...) command, combined with a .LSP it works. If I use a (load...) command combined with a .FAS, it does not work... bizarre... Quote Link to comment Share on other sites More sharing options...
BlackBox Posted November 3, 2010 Share Posted November 3, 2010 (edited) If i use a (load...) command, combined with a .LSP it works. If I use a (load...) command combined with a .FAS, it does not work... bizarre... Perhaps you have an incorrect properties setting (for your VLIDE Project), as I have no issue loading .FAS files from ACADDOC.lsp (provided all dependencies are valid)...? Example: (load "FilePath\\FileName.FAS") Edited November 3, 2010 by BlackBox Typo Quote Link to comment Share on other sites More sharing options...
JohnM Posted November 3, 2010 Share Posted November 3, 2010 Try deleting JWALT_ReplaceFirstSta and JWALT_ExtractFirstSta from your localized variables. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.