Author Topic: 'ReplaceText' lisp errors on first go ...  (Read 6210 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
'ReplaceText' lisp errors on first go ...
« on: July 22, 2010, 04:59:16 PM »
Afternoon everyone.

I am wondering if you gent's here would be good enough to help me troubleshoot a piece of code.
I have been working on this (troubleshooting it) for quite some time, learning VLIDE as I go.  But I can't find my problem.
I know I'm not using VLIDE correctly, so I have to go restudy the help files and such.

But the code I have is interesting in it's error.
The first time it runs, it errors with:
Quote
Application Error: 0 :- bad argument type: numberp: nil
The second time, or if I edit the code with something simple like a comment, save it and reload it, then it works without a hitch.
Here's the code:
Code: [Select]
(defun C:ReplaceText (/ *error* NewTLen             ; Local
                        OldText NewText OldTLen SearchStr NewTLen AllText) ; Global
  (defun *error* (msg /)
    (on-error msg)
    (princ)
  ) ; _EoF
  (setvar "cmdecho" 0)
  (prompt "\nUse quotes for multiple words.")
  (setq OldText (strcase (getstring "\nEnter text being replaced (Press 'Enter' for entire string): "))
        NewText (strcase (getstring "\nEnter new text to replace existing: ")))
  (if (or (= OldText nil) (= OldText ""))           ; if OldText is empty
    (setq OldText "String")                         ; Then replace entire string
    (setq OldTLen (strlen OldText)                  ; Else get Length of OldText
          SearchStr (strcat "*" OldText "*"))       ; create search string
  ) ; _if
  (if (or (= NewText nil) (= NewText ""))           ; if NewText IS empty
    (quit)
    (setq NewTLen (strlen NewText))                 ; Else get Length of NewText
  )
  (if (= OldText "String")                          ; if replacing entire string
    (SelectEachString)                              ; select strings to be replaced
    (SelectAllStrings)                              ; Else optional to select ALL text
  ) ; _if
  (setvar "cmdecho" 1)
  (princ)
) ; _EoF
;
(defun SelectEachString (/ )
  (while (= AllText nil)
    (prompt "\nSelect text to be replaced: ")
    (setq AllText (ssget '((0 . "TEXT,MTEXT"))))    ; ,MULTILEADER
  )
  (ProcessText)
)
;
(defun SelectAllStrings (/ )
  (prompt "\nSelect text to be replaced (Press 'Enter' for all text in drawing): ")
  (setq AllText (ssget '((0 . "TEXT,MTEXT"))))
  (if (or (= AllText nil) (= AllText ""))
    (setq AllText (ssget "_X" '((0 . "TEXT,MTEXT")))); ,MULTILEADER
  )
  (ProcessText)
)
;
(defun ProcessText (/ i TextObj TextStr eList Posi TextChar PreChar PostChar UPDeList)
  (setq i -1)
;  (prompt "\n... 1 ...")
  (while (setq TextObj (ssname AllText (setq i (1+ i))))
    (if (setq TextStr (cdr (assoc 1 (setq eList (entget TextObj)))))
      (progn
;        (prompt "\n... 2 ...")
        (if (= OldText "String")                    ; if replacing entire string
          (setq UPDeList 1 TextStr NewText)         ;
          (progn                                    ; Else
;            (prompt "\nrunning Else ...")
            (if (wcmatch TextStr SearchStr)         ; if SearchStr is found in TextStr
              (progn
                (setq TextLen (strlen TextStr)      ; get length of TextStr
                      Posi 1
                      TextChar (substr TextStr Posi OldTLen) ; set TextChar to first SearchStr
                )                                            ; characters of TextStr
                (while (and (/= TextChar OldText) (>= TextLen Posi)) ; while TextChar does not
                  (setq Posi (1+ Posi)                          ; match, move position up 1
                        TextChar (substr TextStr Posi OldTLen)) ; and try again
                )                                           ; when characters match, continue
                (if (> Posi 1)
                  (setq PreChar (substr TextStr 1 (1- Posi))) ; get everything before SearchStr
                  (setq PreChar "")                           ; Else there is nothing
                )
                (setq UPDeList 1
                      PostChar (substr TextStr (+ Posi OldTLen)) ; get everything after SearchStr
                      TextStr (strcat PreChar NewText PostChar)  ; create new string
                )
              ) ; _progn
            ) ; _if
          ) ; _progn
        ) ; _if
      ) ; _progn
    ) ; _if
    (if (= UPDeList 1)                              ; if there's a new string to be updated,
      (progn                                        ; Then update eList
        (entmod (subst (cons 1 TextStr) (assoc 1 eList) eList))
        (setq UPDeList 0)
      ) ; _progn
    ) ; _if
  ) ; _while
); _EoF
 < ... error catch ... >

I have a few (setq ... functions that are multiples, and I've checked each one and they have a value to them when the program finishes.
Also, I believe it is erroring in the main function area, before it goes to any other function (I have several prompt's that are commented out (I thought I had found the problem but alas, it still errors) that I have used to narrow down where the error is occuring).

Thanks.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: 'ReplaceText' lisp errors on first go ...
« Reply #1 on: July 22, 2010, 05:03:17 PM »
Haven't looked at the code as yet, but Replace Text is a nasty subject area to get into as you run into all sorts of problems (mostly with MText formatting codes)...

Not trying to discourage you, but believe me, I've been through it..

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: 'ReplaceText' lisp errors on first go ...
« Reply #2 on: July 22, 2010, 05:31:17 PM »
Talking of replacing text, perhaps one of the simplest ways would be something like this:

Code: [Select]
(defun StringSubst ( new old str )
  ;; © Lee Mac 2010
  (
    (lambda ( i / nl ) (setq nl (strlen new))
      (while
        (and (< i (strlen str))
          (setq i (vl-string-search old str i))
          (setq str (vl-string-subst new old str i) i (+ i nl))
        )
      )
      str
    )
    0
  )
)

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: 'ReplaceText' lisp errors on first go ...
« Reply #3 on: July 22, 2010, 05:49:57 PM »
Please do not take offence to this but I have at least 8 comments on the first function alone and i only glanced at it (didnt even break the skin of the functions and their use so-to-speak). But in an effort to help teach, here is my first pass at the function.

Again, please, no offence. Just trying to help give direction.

Code: [Select]
(defun C:ReplaceText (/ *error* NewTLen             ; Local
                        OldText NewText OldTLen SearchStr NewTLen AllText) ; Global
[color=red]                 ;; 7: there isnt anything GLOBAL about the localization "( / <blah> )" process so remove that comment.
[/color]  (defun *error* (msg /)
    (on-error msg)
    (princ)
  ) ; _EoF
               [color=red] ;; 7: what is "on-error"? ...either use "*error*" or "on-error"
                ;; 7: this is not the END OF FILE (that tag is typical used to mean END OF FILE not END OF FUNCTION)
                ;;    use the typical syntax instead.  Like: "...);_ end defun"[/color]
  (setvar "cmdecho" 0)
[color=red]                ;; 7: you're not even going to save the users current settings?
[/color]
  (prompt "\nUse quotes for multiple words.")
  (setq OldText (strcase (getstring "\nEnter text being replaced (Press 'Enter' for entire string): "))
        NewText (strcase (getstring "\nEnter new text to replace existing: ")))

  (if (or (= OldText nil) (= OldText ""))           ; if OldText is empty
[color=red]                ;; 7: (or (null Oldtext) ...?
[/color]    (setq OldText "String")                         ; Then replace entire string
    (setq OldTLen (strlen OldText)                  ; Else get Length of OldText
          SearchStr (strcat "*" OldText "*"))       ; create search string
  ) ; _if

  (if (or (= NewText nil) (= NewText ""))           ; if NewText IS empty
[color=red]                ;; 7: (or (null NewText) ...?
[/color]    (quit)
[color=red]                ;; 7: You have already altered the users CMDECHO var, are you setting it back?
                ;;    try and think of a way to NOT use this method.[/color]

    (setq NewTLen (strlen NewText))                 ; Else get Length of NewText
  )
  (if (= OldText "String")                          ; if replacing entire string
    (SelectEachString)                              ; select strings to be replaced
    (SelectAllStrings)                              ; Else optional to select ALL text
  ) ; _if
  (setvar "cmdecho" 1)
  (princ)
) ; _EoF
[color=red]                ;; 7: see above[/color].

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: 'ReplaceText' lisp errors on first go ...
« Reply #4 on: July 22, 2010, 06:40:42 PM »
Hangman,
FYI, First thing you do when debugging is to disable the local error handler.

I ran the routine with out error but it did not replace the text. :-o
« Last Edit: July 22, 2010, 06:52:44 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: 'ReplaceText' lisp errors on first go ...
« Reply #5 on: July 22, 2010, 06:58:50 PM »
Looking at your code I did not see a clear picture of what you are trying to do with (if (= OldText "")

What does your pseudo code look like? 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Hangman

  • Swamp Rat
  • Posts: 566
Re: 'ReplaceText' lisp errors on first go ...
« Reply #6 on: July 23, 2010, 11:10:54 AM »
Please do not take offence to this < ... >.  But in an effort to help teach, here is my first pass at the function.

Again, please, no offence. Just trying to help give direction.

No offense taken Se7en, I really appreciate the constructive feedback.  This is where I can really learn, I thank you.  If you don't mind, I'll try to explain my actions & thoughts here as well.  Please correct me where I may be incorrect as I would really like to get some good programming practices in my work instead of the bad habits we can easily inherit.

Quote from: Se7en
Code: [Select]
(defun C:ReplaceText (/ *error* NewTLen             ; Local
                        OldText NewText OldTLen SearchStr NewTLen AllText) ; Global
[color=red]                 ;; 7: there isnt anything GLOBAL about the localization "( / <blah> )" process so remove that comment.
[/color]
Perhaps I am not yet understanding the difference between the Local and Global variables yet.  These variables, although they are used by this main function, are also used in the other functions.  As this is where the program begins, I figured this is where it would be best to declare the variables.  I know they can't be declared in the other functions as they will be rendered useless in this function.  That is what I was understanding Global to be.  I know declaring them here makes them Local, but they are (to my limited understanding) Global in that they are accessed by the other functions in this routine.

Quote from: Se7en
Code: [Select]
  (defun *error* (msg /)
    (on-error msg)
    (princ)
  ) ; _EoF
               [color=red] ;; 7: what is "on-error"? ...either use "*error*" or "on-error"
                ;; 7: this is not the END OF FILE (that tag is typical used to mean END OF FILE not END OF FUNCTION)
                ;;    use the typical syntax instead.  Like: "...);_ end defun"[/color]
Oops.  I apologize, I forgot I needed the 'on-error' to fully understand it all.  Here it is.
Code: [Select]
(defun on-error (msg / )                            ; borrowed from Kerry - theSwamp
  (while
    (> (getvar "cmdactive") 0)
    (command)
  )
  (setvar "cmdecho" 1)
  (cond ( (not msg))                                ; no error, do nothing
        ( (member
            (strcase msg t)                         ; invoke a cancel
             '("console break" "function cancelled" "quit / exit abort")
          )
          (prompt "\nFunction Cancelled\nFunction Cancelled")
        )
        ( (princ (strcat "\nApplication Error: "    ; else, an error message
                         (itoa (getvar "errno"))
                         " :- "
                         msg "\n"
                 )
          )
        )
  )
  (setq *error* nil)
)
... ; EoF = End of File ...  Got it, thanks.

Quote from: Se7en
Code: [Select]
  (setvar "cmdecho" 0)
[color=red]                ;; 7: you're not even going to save the users current settings?
[/color]
Well umm, ... no I wasn't.  Most of the users don't even read their command line yet, I'm hoping to get them trained to look at it.  I want to force the echo on at the end but I don't see a reason for the echo to be on during the function, so I'm hard coding it in.  I did forget about my little (quit) if there's no text though.   :oops:  I need to fix that.

Quote from: Se7en
Code: [Select]
  (prompt "\nUse quotes for multiple words.")
  (setq OldText (strcase (getstring "\nEnter text being replaced (Press 'Enter' for entire string): "))
        NewText (strcase (getstring "\nEnter new text to replace existing: ")))

  (if (or (= OldText nil) (= OldText ""))           ; if OldText is empty
[color=red]                ;; 7: (or (null Oldtext) ...?
[/color]    (setq OldText "String")                         ; Then replace entire string
    (setq OldTLen (strlen OldText)                  ; Else get Length of OldText
          SearchStr (strcat "*" OldText "*"))       ; create search string
  ) ; _if

  (if (or (= NewText nil) (= NewText ""))           ; if NewText IS empty
[color=red]                ;; 7: (or (null NewText) ...?
[/color]    (quit)
[color=red]                ;; 7: You have already altered the users CMDECHO var, are you setting it back?
                ;;    try and think of a way to NOT use this method.[/color]
Null ...  I forgot about that.  Null does help, I don't like the way I currently have it.
You are correct, (quit) does not work like this.  Instead of using (quit), I can simply send it to the 'on-error' to clean everything up, yes?.

Thank you again Se7en for your eye's & constructive feedback.


Hangman,
FYI, First thing you do when debugging is to disable the local error handler.

I ran the routine with out error but it did not replace the text. :-o
Correct CAB, that's why I came here.  I had it disabled early on.  I also had all the declared variables commented out so I could go through them and see if any one was not being used as they should.  As it does run without the error handler enabled, I re-enabled it and put a bunch of prompts in there to see how far it was going before erroring as well.  Like I mentioned earlier, I was using VLIDE too, but I don't think I was using it correctly.  I need to go re-read the help files on it.

Looking at your code I did not see a clear picture of what you are trying to do with (if (= OldText "")

What does your pseudo code look like? 8-)
Well, ...  I don't actually have any pseudo code for that part.  It was a random thought as I was putting this together and I just ... threw it in there.  Basically all it does is;  If there is no specific text to be replaced, it replaces every piece of text string selected.  So the function forces a specific selection rather than the global (ssget "_X" ... ) selection.


I thank you guys for your help and your instruction.  I love coming to the Swamp just because of people like you guys here.  Thank you.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

psuchewinner

  • Guest
Re: 'ReplaceText' lisp errors on first go ...
« Reply #7 on: July 23, 2010, 11:21:02 AM »
Speaking of MText...Is there a "Change Text" routine for MText entities?

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: 'ReplaceText' lisp errors on first go ...
« Reply #8 on: July 23, 2010, 12:02:15 PM »
Lets tackle this one at a time.

First lets clean up some your use of terms.

As far as variables go there are two things you can do (Im speaking in general programing terms here, not just AutoLisp).

In most programming languages like C/C++ you can declare and define variables you want to use in two steps:
step 1. declare
step 2. define

Declare and Define:

You can declare a variable, that is that you can tell the computer you are going to use a variable with this name.

you can define a variable this is where you tell the computer what to "put into" that variable.

C/C++ variable declare/define example:
Code: [Select]
// declare variables

int myVar;
int myOtherVar;

// define variables

myVar = 1;
myOtherVar = 2;


Now AutoLisp being a high level language doesn't actually let you separate the declaration from the definition so when you see a variable being used in AutoLisp you often see this:
Code: [Select]
(setq myVar 1)that would be Declaration and Definition all in one statement.

I know what your thinking: If we were to try and separate the declaration and definition process in AutoLisp (i.e. be more like C/C++) we could try something like this:

Code: [Select]
(setq myVar '())
(setq myVar 1)

but since the first statement actually "destroys" the variable called myVar it only causes confusion to other readers when you do this.

Now we will touch on the global/local variable problem.

In Lisp we have this syntax to use: ( / ) {open paren, slash, close paren} ...left side and right side if you will.

Suff on the left side is called "formal parameters" or even often called "arguments".

Stuff on the right side is called "localization". This area just does one simple thing; it destroys variables. Remember the bad example of variable declaration I gave above? (setq myVar '()) ...thats essentially whats happening. The variable is just being destroyed.


Localization example:
Code: [Select]
(defun foo ( / var1 var2 var3 )
        (setq var1 1)
        (setq var2 2)
        (setq var3 3)
 )

All vars are localized (destroyed).

Now where does global come into play? Simple, just dont destroy it.

Global example
Code: [Select]
(defun foo ( / var2 var3 )
        (setq var1 1)
        (setq var2 2)
        (setq var3 3)
 )

Now var1 is global. Get it?


OK, now this write up was very broad in nature and loose with explanations. As you get better and have a better understanding of programming in general you will need to expand on these explanations more. -e.g. when I said that a value gets "put into" a variable, that isnt actually what happens. When I said that a variable gets "destroyed"..."variable destruction" doesnt really happen the way that those words imply.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: 'ReplaceText' lisp errors on first go ...
« Reply #9 on: July 23, 2010, 12:12:46 PM »
Quote from: Se7en
Code: [Select]
 (setvar "cmdecho" 0)
[color=red]                ;; 7: you're not even going to save the users current settings?
[/color]
Well umm, ... no I wasn't.  Most of the users don't even read their command line yet, I'm hoping to get them trained to look at it.  I want to force the echo on at the end but I don't see a reason for the echo to be on during the function, so I'm hard coding it in.  I did forget about my little (quit) if there's no text though.   :oops:  I need to fix that.


I dont care. You WILL save the users setting(s) before you set it to what YOU want (i'll show you how, its real easy).

Code: [Select]
(defun foo ( / users-old-cmdecho-value ) [color=green];;<-- we are doing what here?[/color]
        (setq users-old-cmdecho-value (getvar 'CMDECHO)) [color=green];; <-- what is this referred to as again?[/color]
        ;; store the users cmdecho variable so that we can
        ;; set it to something else for now. we will set it
        ;; back later.

        (setvar 'CMDECHO 0)

        ;; do my fancy lisp processing here
        ;; on hundreds of lines
        ;; of this file, resulting in me getting
        ;; a raise and sending Se7en
        ;; money because I think he is the
        ;; greatest person in the whole, wide
        ;; world!
        ;;
        ;;*phew!* that was a good lisp.

        ;; lets reset the users CMDECHO value
        ;; back to what they had before.
        (setvar 'CMDECHO users-old-cmdecho-value)

 )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: 'ReplaceText' lisp errors on first go ...
« Reply #10 on: July 23, 2010, 01:09:31 PM »
Localization example:
Code: [Select]
(defun foo ( / var1 var2 var3 )
        (setq var1 1)
        (setq var2 2)
        (setq var3 3)
 )

All vars are localized (destroyed).

Now where does global come into play? Simple, just dont destroy it.

Global example
Code: [Select]
(defun foo ( / var2 var3 )
        (setq var1 1)
        (setq var2 2)
        (setq var3 3)
 )

Now var1 is global. Get it?

Just to elaborate on this slightly, let us say we have two (or more) functions, and we wish for variables to be accessible in both, eg;

Code: [Select]
(defun foo ( / var1 )
  (setq var1 "Hangman")
  (bar)

  (princ)
)

(defun bar nil
  (princ var1)
)

Here we define (and declare) the variable 'var1' in function foo and reference it in function bar. Notice that the variable is not localised in bar, as this would render it's value null upon calling bar from foo.

Effectively, we can look at it like this, replacing (bar) with all the expressions contained in that definition.

Code: [Select]
(defun foo ( / var1 )
  (setq var1 "Hangman")

  ;; Now evaluate a bunch of statements in 'bar'

  (princ var1)

  ;; Now get back to foo
  (princ)
)

This method of referencing variables between functions is called 'lexical scoping' if I remember from Se7en correctly...

So you can effectively view subfunctions as elegant 'space-savers', instead of duplicating code over and over.

IMO (for what its worth), I prefer to pass arguments where I can, and avoid referencing variables across multiple functions unless I absolutely have to - I feel this makes the intention clearer and easier to understand. Not to mention it makes the subfunction useful as a stand-alone function (or library function if you will).

Lee

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: 'ReplaceText' lisp errors on first go ...
« Reply #11 on: July 23, 2010, 01:16:15 PM »
Be very careful of that phrase: "render it's value null" because thats not what REALLY happens. NULL means zero'ed out, that isnt what happens.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: 'ReplaceText' lisp errors on first go ...
« Reply #12 on: July 23, 2010, 01:18:33 PM »
<snip>
Quote from: Se7en
Code: [Select]
(defun *error* (msg /)
    (on-error msg)
    (princ)
  ) ; _EoF
               [color=red] ;; 7: what is "on-error"? ...either use "*error*" or "on-error"[/color]
Oops.  I apologize, I forgot I needed the 'on-error' to fully understand it all.  Here it is.
<snip>

Here is where things get a bit fuzzy but try and hold on. -i.e. the reason why high level languages are refered to as "high" is because they hide the inner workings from you. When I told you how to declair and define a variable you were actually assigning a NAME to some space in memory which held a THING.

So when you create a function ("abstraction") you are really defining a NAME to a series of process' (hence the term: abstraction. Its abstract, its removed from you. Its a black box of stuff).

Let me demonstrate this by declaring and defining a NAME in several ways (Think of this exercise as: Filling a "variable" with a "function".)

Code: [Select]
(setq a (lambda (n) (+ n 1))) ;; choosen to be first because you are used to seeing SETQ

;; Isn't any different than

(set 'a (lambda (n) (+ n 1)))

;; Isn't any different than

(defun a (n) (+ n 1))

;; give it a try.

(a 1)

Now dont worry if you dont grasp this right away. just let it mull around for a bit.

We didnt actually `fill a ``variable'' with a ``function''" at all. A more acurate description of what we did with either one of those three steps is "DEFINE A NAME". That is UBER important! Think about that phrase.

To use our own error handling routine all we have to do is to "RE-define a name"

(setq the-old-error-function *error*)
;; declare and define a variable (NAME).

(setq *error* my-new-fancy-error-function)
;; now "*ERROR*" "refers to" something else.

Now whenever and/or how ever long "*error*" "refers to" "my-new-fancy-error-function" the STUFF found in "my-new-fancy-error-function" will be executed.

In other words: An execution of "(QUIT)" will then call "*ERROR*" which now refers to "MY-NEW-FANCY-ERROR-FUNCTION".

Does that make sense?

Im giving you a lot of information here that should by all rights take you years to learn. it may not seem like it but these explinations are very general and incomplete only offered up to help you understand how to READ and UNDERSTAND AutoLisp (programming in general) better.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: 'ReplaceText' lisp errors on first go ...
« Reply #13 on: July 23, 2010, 01:23:06 PM »
K, I think thats all the pieces you need so-far. Read what i gave you several times, i was very literal in my wording.

BTW, How are we doing?

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

hermanm

  • Guest
Re: 'ReplaceText' lisp errors on first go ...
« Reply #14 on: July 23, 2010, 04:50:05 PM »
(quit) is an error condition, as John has told you.

You should structure your program to avoid an abnormal end under most conditions.

Example: (picked at random from my own code)
Code: [Select]
(cond
    ((= -2 strdata) (princ "\nUnable to Find Datafile"))
    ((= -1 strdata) (princ (strcat "\nShape not Found: " shapename)))
    ( T (setq realdata (mapcar 'atof (cdr(strtok strdata " ")))))
);cond
(if realdata
  (progn
  <do stuff here>
  );end progn
);end if
(vla-endundomark *THISDWG*)
(princ)
);end defun