Simple LISP Program

Simple LISP Program

jmartt
Collaborator Collaborator
802 Views
10 Replies
Message 1 of 11

Simple LISP Program

jmartt
Collaborator
Collaborator

The following is going to be laughable, I'm sure. I don't speak this language, but I gave it a try.

 

I need to do this:

 

(defun c: SwitchAnnoQuick (/ MyAnno)     
  (setq MyAnno (getvar "cannoscale"))
  (if (MyAnno=1:1)
    (command cannoscale 1:2)
    (command cannoscale 1:1)
    (command cannoscale MyAnno))

 

In English: Change my cannoscale to 1:1 and back unless it is already 1:1, in which case change it to 1:2 and back.

 

Any help is appreciated. Thanks!

0 Likes
Accepted solutions (1)
803 Views
10 Replies
Replies (10)
Message 2 of 11

Ajilal.Vijayan
Advisor
Advisor
Accepted solution

Hi,

Try with this.

Do you want to do something in between the switch ?

Can I ask what is the use of this switch ?

The lines in Orange color is to show the status of switch, you can delete those lines if you dont want them.

Spoiler
;function to print the current CANNOSCALE value
(defun printvar (txt)
(princ (strcat txt(getvar var)"|"))
);defun
(defun c:SwitchAnnoQuick (/ MyAnno var) (setq var "CANNOSCALE") (setq MyAnno (getvar var)) (cond ((= MyAnno "1:1") (printvar "was ") (setvar var "1:2") (printvar "set to ") (setvar var "1:1") (printvar "and set back to ")) ((= MyAnno "1:2") (printvar "was ") (setvar var "1:1") (printvar "set to ") (setvar var "1:2") (printvar "and set back to ")) );cond (princ) );defun

 

Message 3 of 11

dbroad
Mentor
Mentor

@Ajilal.Vijayan has given you a rewritten form that works but your only real mistakes were:

1. Space between c: and command name

2. failure to use double quotes at several locations.

3. failure to put test function first

4. failure to wrap the then expression in a progn.

5. missing end parenthesis.

(defun c:SwitchAnnoQuick (/ MyAnno)     
  (setq MyAnno (getvar "cannoscale"))
  (if (= MyAnno "1:1")
    (progn
    (command "cannoscale" "1:2")
    (command "cannoscale" "1:1")
    (command "cannoscale" MyAnno)
    )
    ))

 

Architect, Registered NC, VA, SC, & GA.
Message 4 of 11

Kent1Cooper
Consultant
Consultant

Another refinement you could make:

 

Any time I see several lines of code that are mostly the same [in this case your first two (command) functions], I suspect there may be a way to do whatever it is with only one pass at that code content, by structuring things differently.  You can do that if you put the (if) test inside the setting of the System Variable.  And you may as well set that in the same kind of function as you get it with, rather than by the (command) approach [and technically (setvar) would be faster, though you'd never notice the difference in this case].  One other small thing: both (getvar) and (setvar) will take the System Variable name with either double-quotes at both ends or just an apostrophe at the beginning.

 

(defun c:SwitchAnnoQuick (/ MyAnno)     
  (setq MyAnno (getvar 'cannoscale))

  (setvar 'cannoscale (if (= MyAnno "1:1") "1:2" "1:1"))

; ... whatever you want to do while it's changed ...
  (setvar 'cannoscale MyAnno)

)

Kent Cooper, AIA
Message 5 of 11

jmartt
Collaborator
Collaborator

Hey, thanks a lot. I got that routine to work and I learned a bit in the process. I'm no coder.

 

I put that space there to stop seeing the smiley face: (defun cSmiley FrustratedwitchAnnoQuick (/ MyAnno)     

I bet there's an easy fix for that, but I got no time to track down how to make your computer believe you don't want to speak in emojis.

 

Since you asked, I wasn't trying to do anything while the scale was changed. I was just trying to get this block inserted right:

 

http://forums.autodesk.com/t5/dynamic-blocks/selectively-annotative-power-pole/m-p/5907614#M19341

 

It kinda works and kinda doesn't. One problem is that everytime I insert it, it'll come in really small...Really small until I flip the annotation scale. My plan was to make a button that inserted the block and then ran SwitchAnnoQuick. But now that block by itself isn't behaving at all and I have deadlines.

 

Someday I'll have a working power pole.

 

0 Likes
Message 6 of 11

Ajilal.Vijayan
Advisor
Advisor

Hi @jmartt,

Like @dbroad mentioned, your code was almost there except some errors.

Please note that the code mentioned by Kent1Cooper & dbroad are the right changes to fix your original code.

I thought you may need to add more switches, that's why I used a different approach.

Message 7 of 11

Kent1Cooper
Consultant
Consultant

@jmartt wrote:

.... 

I put that space there to stop seeing the smiley face: (defun cSmiley FrustratedwitchAnnoQuick (/ MyAnno)     

I bet there's an easy fix for that.....

 


Here is your easy fix.

Kent Cooper, AIA
Message 8 of 11

jmartt
Collaborator
Collaborator

Heee-eey! No more smiley faces! Thanks.

 

Also, thanks to Libbya over in the dynamic blocks forum, I now have a working power pole (that is annotative but remembers where the anchors are, woohoo).

I've attached the drawing if you're at all interested.

But I'm posting here because I have overestimated my abilities yet again:

I now have this DYNA_PP block and I have the LISP SwitchAnnoQuick. I want to make a button on my tool palette which inserts that block, pausing for me to pick where, and then runs that LISP routine so it snaps to scale. (There might be an easier way to go about this scale business, and if so I'm all ears, but I'm under the impression that this behavior is compulsory for a nonannotative block with annotative blocks within it.)

 

I wonder should I write a LISP routine (maybe called PPInsandScale.lsp) that loads that block, inserts it, pauses, and then runs the SwitchAnnoQuick...and so that'd be the LISP routine that my button calls? Or can I do this all in the command string? I tried the latter, thinking it would be cleanest, but I haven't had much luck.

0 Likes
Message 9 of 11

jmartt
Collaborator
Collaborator

Well, after much trial and error, I think this works:

 

^C^C_insert;dynapp.dwg;\;;;(command "explode" "l");;^C^C ^C^C_switchannoquick;

 

That probably hurts your eyes. But I'm pretty happy. Thanks for the help.

0 Likes
Message 10 of 11

ВeekeeCZ
Consultant
Consultant

@jmartt wrote:

Well, after much trial and error, I think this works:

 

^C^C_insert;dynapp.dwg;\;;;(command "explode" "l");;^C^C ^C^C_switchannoquick;

 

That probably hurts your eyes. But I'm pretty happy. Thanks for the help.


Not bad... some unnecessary characters, maybe command you don't need...

 

^C^C_insert;dynapp.dwg;\;;;_explode;_l;switchannoquick;
Message 11 of 11

Kent1Cooper
Consultant
Consultant

@ВeekeeCZ wrote:
....

Not bad... some unnecessary characters, maybe command you don't need...

 

^C^C_insert;dynapp.dwg;\;;;_explode;_l;switchannoquick;

But don't put spaces in a command macro that don't belong [in AutoLisp, you can spread them around liberally, but not in a macro, where they behave just as if typed in], and you don't need to but you can omit the semicolon/Enter at the end [Enter is automatic there unless the macro ends with certain control characters]:

 

^C^C_insert;dynapp.dwg;\;;;explode;l;switchannoquick

 

Kent Cooper, AIA