Jump to content

why will 2010 execute one routine and not another?


Recommended Posts

Posted

I have been trying to decipher and update lisp routines from the 90's to be compatible with 2010, but not having much success. would there be a logical explanation as to why this routine will function....

 

[b][size=4](defun c:26 ()                                                     ;ECN MC26 ADD MTG HOLES TO CENTER (5/6/08)[/size][/b]
[b][size=4](setvar "cmdecho" 0)[/size][/b]
[b][size=4](setq obj (entsel "\nPick Location :"))[/size][/b]
[b][size=4](setq a "MC26" )[/size][/b]
[b][size=4](setq j (strcat a))[/size][/b]
[b][size=4](command "change" obj "" "" "" "" "" "" j))[/size][/b]
(defun c:AM ()                                                     ;FOR MC26 NOTE 'ADD MTG HOLES' (5/6/08)
 (setvar "cmdecho" 0)
 (setq obj (entsel "\nPick Location :"))
 (setq a "ADD MTG HOLES" )
 (setq j (strcat a))
 (command "change" obj "" "" "" "" "" "" j))
(defun c:27 ()                               ;ECN MC27 REV BENDS ADD DECIMALS (6/9/08)
 (setvar "cmdecho" 0)
 (setq obj (entsel "\nPick Location: "))
 (setq a ("MC27" )
 (setq j (strcat a))
 (command "change" obj "" "" "" "" "" "" j))

 

and this one will not ...

 

(defun c:26 () ;ECN MC26 ADD MTG HOLES TO CENTER (5/6/08)

(setvar "cmdecho" 0)

(setq obj (entsel "\nPick Location :"))

(setq a "MC26" )

(setq j (strcat a))

(command "change" obj "" "" "" "" "" "" j))

(defun c:AM () ;FOR MC26 NOTE 'ADD MTG HOLES' (5/6/08)

(setvar "cmdecho" 0)

(setq obj (entsel "\nPick Location :"))

(setq a "ADD MTG HOLES" )

(setq j (strcat a))

(command "change" obj "" "" "" "" "" "" j))

[b][size=4](defun c:27 () ;ECN MC27 REV BENDS ADD DECIMALS (6/9/08)[/size][/b]

[b][size=4](setvar "cmdecho" 0)[/size][/b]

[b][size=4](setq obj (entsel "\nPick Location: "))[/size][/b]

[b][size=4](setq a ("MC27" )[/size][/b]

[b][size=4](setq j (strcat a))[/size][/b]

[b][size=4](command "change" obj "" "" "" "" "" "" j))[/[/size][/b]CODE]

 

 

I have tried making alterations in the visual lisp editor, will that prehaps cause corruption to the file?

Posted

Hello.

I noticed the line in c:27

(setq a ("MC27" ) is odd.

Try: (setq a "MC27") instead.

Posted

one parenthesis wow that's all it takes to mess everything up.

 

that was unique, I missed it.

 

that fixed it

Posted

Your welcome. By the way a better method if you are simply changing text is:

(defun c:[b][color=Red]26[/color][/b] (/ ent)
 (if (setq ent (car(entsel "\nSelect Text: ")))
   (if (wcmatch (cdr (assoc 0 (entget ent))) "*TEXT")
     (entmod (subst (cons 1 [b][color=Red]"MC26"[/color][/b])(assoc 1 (entget ent)) (entget ent)))
     (princ "Selection Not Text.\n"))
   (princ "Nothing Selected.\n"))
 (princ)
 )

And for AM & 27 just copy the code and change the highlighted parts.

Posted
Did you not take anything from that thread?
it would seem not.
Posted

You can lead a horse to water but you can't rip his lips off. At least that's what my great-grandfather used to say.

Posted

Your proposed routine looks more complicated, let me ask you just how many ways can you write this thread?

Posted

My proposed routine:

 

(defun c:27 (/ ent)
 (if (and (setq ent (car (entsel "\nPick Text: ")))
          (wcmatch (cdr (assoc 0 (entget ent))) "*TEXT"))
   (entmod
     (subst
       (cons 1 "MC27") (assoc 1 (entget ent))
         (entget ent)))
   (princ "\n** Object is not Text **"))
 (princ))

Is much better programming practice and would be much more stable. You should avoid using "(command..." where possible, as this is a slow method and can be troublesome.

 

Read up on my method here:

 

http://www.afralisp.net/lispa/lisp18.htm

Posted
let me ask you just how many ways can you write this thread?

 

There are many, many ways to do the same thing in programming... :)

Posted

Thank you for the message AAONCAD, I am happy to help you understand the code that I have posted. I have annotated it the best I can explain, but if you are still confused, just ask.

 

[b][color=RED]([/color][/b][b][color=BLUE]defun[/color][/b] c:27 [b][color=RED]([/color][/b][b][color=BLUE]/[/color][/b] ent[b][color=RED])[/color][/b]

 [i][color=#990099];; Here we are defining the function. We use "(defun c:"[/color][/i]
 [i][color=#990099];; as opposed to just "(defun" as we want the user to be[/color][/i]
 [i][color=#990099];; able to invoke the function from the command line.[/color][/i]
 [i][color=#990099];; In the brackets after the function definition, we are localising[/color][/i]
 [i][color=#990099];; the variables used in the program. This sets their values to nil[/color][/i]
 [i][color=#990099];; as the program is invoked and after the program has completed.[/color][/i]
 [i][color=#990099];; If you read up in the VLIDE help about the function "defun" you[/color][/i]
 [i][color=#990099];; will see the difference between an argument and a variable.[/color][/i]

 
 [b][color=RED]([/color][/b][b][color=BLUE]if[/color][/b]  [i][color=#990099];; IF the following test statement returns True (anything non-nil).[/color][/i]

   [b][color=RED]([/color][/b][b][color=BLUE]and[/color][/b]  [i][color=#990099];; Both the following statements must return true for the IF[/color][/i]
         [i][color=#990099];; Statement to be satisfied.[/color][/i]

     [b][color=RED]([/color][/b][b][color=BLUE]setq[/color][/b] ent  [i][color=#990099];; Bound the value of the following to the symbol "ent"[/color][/i]
                [i][color=#990099];; hence making it a variable of the function. And, as[/color][/i]
                [i][color=#990099];; we have declared it in our function definition, "ent"[/color][/i]
                [i][color=#990099];; is known as a "local variable" (as opposed to a "global variable").[/color][/i]

            [b][color=RED]([/color][/b][b][color=BLUE]car[/color][/b]  [i][color=#990099];; Return the first item in the following list...[/color][/i]

              [b][color=RED]([/color][/b][b][color=BLUE]entsel[/color][/b] [b][color=#ff00ff]"\nPick Text: "[/color][/b][b][color=RED])[/color][/b]

              [i][color=#990099];; Entsel prompts the user for a selection and returns a list with[/color][/i]
              [i][color=#990099];; 2 items - the first being the entity name of the selected object,[/color][/i]
              [i][color=#990099];; and the second is the point that was selected (a list of 3 elements).[/color][/i]
              [i][color=#990099];; If the user doesn't pick something, entsel returns nil.[/color][/i]

            [b][color=RED])[/color][/b]  [i][color=#990099];; End CAR[/color][/i]
           
       [b][color=RED])[/color][/b] [i][color=#990099];; End SETQ[/color][/i]

     [b][color=RED]([/color][/b][b][color=BLUE]wcmatch[/color][/b]  [i][color=#990099];; We are going to use this function to match two strings using a wildcard.[/color][/i]
               [i][color=#990099];; Read up on this function in the VLIDE help - there is a lot to learn from it.[/color][/i]

       [b][color=RED]([/color][/b][b][color=BLUE]cdr[/color][/b]  [i][color=#990099];; We want to get the second item of the following dotted pair.[/color][/i]

         [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]0[/color][/b]  [i][color=#990099];; We are using this to retrieve the list (a dotted pair) with the first[/color][/i]
                   [i][color=#990099];; element of the dotted pair being 0. The zero entry in the entget data list[/color][/i]
                   [i][color=#990099];; is the DXF code for the entity TYPE, which we are retrieving so that we[/color][/i]
                   [i][color=#990099];; can check we have Text![/color][/i]

                [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] ent[b][color=RED])[/color][/b]  [i][color=#990099];; Retrieve the definition data list for the entity name returned[/color][/i]
                              [i][color=#990099];; from "entsel". This list contains all the information associated with[/color][/i]
                              [i][color=#990099];; the entity selected.[/color][/i]

         [b][color=RED])[/color][/b] [i][color=#990099];; End ASSOC[/color][/i]

       [b][color=RED])[/color][/b] [i][color=#990099];; End CD[/color][/i]

       [b][color=#ff00ff]"*TEXT"[/color][/b][b][color=RED])[/color][/b]  [i][color=#990099];; This is the String we are using with the "wcmatch" function. WcMatch (Wildcard Match)[/color][/i]
                 [i][color=#990099];; will return true in this instance if the Entity Type ends with "TEXT", hence we will[/color][/i]
                 [i][color=#990099];; allow "MTEXT" and "TEXT" (but also "RTEXT" unfortunately).[/color][/i]

   [b][color=RED])[/color][/b] [i][color=#990099];; End AND[/color][/i]

   [i][color=#990099];; IF the user has both picked an entity AND the entity type returns T in the wildcard match, i.e. it is[/color][/i]
   [i][color=#990099];; either TEXT or MTEXT, then the following statement is evaluated by the IF statement. Otherwise, the[/color][/i]
   [i][color=#990099];; "Else" statement is evaluated (if there is one).[/color][/i]
   
   [b][color=RED]([/color][/b][b][color=BLUE]entmod[/color][/b]  [i][color=#990099];; Modify the following Definition data list (the list returned from "entget")[/color][/i]
     
     [b][color=RED]([/color][/b][b][color=BLUE]subst[/color][/b]  [i][color=#990099];; Substitute the following list for every[/color][/i]
             [i][color=#990099];; instance of a list in the Definition Data list.[/color][/i]
       
       [b][color=RED]([/color][/b][b][color=BLUE]cons[/color][/b] [b][color=#009900]1[/color][/b] [b][color=#ff00ff]"MC27"[/color][/b][b][color=RED])[/color][/b]  [i][color=#990099];; The list to be substituted - this is a dotted pair, as[/color][/i]
                        [i][color=#990099];; "cons" has been used to form a dotted pair from the two[/color][/i]
                        [i][color=#990099];; atoms provided, hence will return: (1 . "MC27").[/color][/i]

         [b][color=RED]([/color][/b][b][color=BLUE]assoc[/color][/b] [b][color=#009900]1[/color][/b]  [i][color=#990099];; Retrieve the dotted pair with 1 as the first element in the provided list.[/color][/i]
                   [i][color=#990099];; The DXF code 1 is the TextString held by the Text/MText Object.[/color][/i]

                [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] ent[b][color=RED])[/color][/b]  [i][color=#990099];; The list provided to "assoc" from which the TextString dotted pair[/color][/i]
                              [i][color=#990099];; is retrieved.[/color][/i]

         [b][color=RED])[/color][/b] [i][color=#990099];; End ASSOC[/color][/i]

       [b][color=RED]([/color][/b][b][color=BLUE]entget[/color][/b] ent[b][color=RED])[/color][/b] [i][color=#990099];; The List provided to "subst" into which the lists will be substituted[/color][/i]
                    [i][color=#990099];; for all instances (there will be only one in this case) of the list to be[/color][/i]
                    [i][color=#990099];; replaced.[/color][/i]

     [b][color=RED])[/color][/b] [i][color=#990099];; End SUBST[/color][/i]

   [b][color=RED])[/color][/b] [i][color=#990099];; End ENTMOD[/color][/i]

   [i][color=#990099];; IF the test statement provided to the IF function returns nil, then the[/color][/i]
   [i][color=#990099];; following statement, (known as the "Else" statement), is evaluated.[/color][/i]
   
   [b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b] [b][color=#ff00ff]"\n** Object is not Text **"[/color][/b][b][color=RED])[/color][/b]  [i][color=#990099];; Print this message to the command line.[/color][/i]

 [b][color=RED])[/color][/b] [i][color=#990099];; End IF[/color][/i]
 
[b][color=RED]([/color][/b][b][color=BLUE]princ[/color][/b][b][color=RED])[/color][/b] [i][color=#990099];; Exit Cleanly (Hence suppress the last return of the previous function[/color][/i]
       [i][color=#990099];; evaluated.) Princ on its own will return a "null" character, and hence[/color][/i]
       [i][color=#990099];; will have no return (as an aside, "prin1" could also be used).[/color][/i]

[b][color=RED])[/color][/b] [i][color=#990099];; End DEFUN[/color][/i]

 

Also, if anyone else feels that I have missed something, feel free to chime in.

 

Regards,

 

Lee

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...