Author Topic: Sketch...ers  (Read 5352 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
Sketch...ers
« on: January 12, 2007, 05:23:08 PM »
Can someone with ACAD2007 try this lisp for me.
It ran flawlessly in 2006, but since the upgrade to '07, It won't do a thing.
I can't get it to change layers or turn off the ortho.  Surprisingly, it will accept the scale.

Code: [Select]
(DEFUN C:SK (/ lay-prev ort-prev asn-prev scale)
  (setq lay-prev (getvar "clayer")
        ort-prev (getvar "orthomode")
        asn-prev (getvar "autosnap")
        scale (* (getvar "dimscale") 0.125))
  (if (= (tblsearch "layer" "DEFPOINTS") nil)
    (command ".-layer" "new" "DEFPOINTS" "color" "7" "DEFPOINTS" ""))
  (command ".-layer" "thaw" "DEFPOINTS" "on" "DEFPOINTS" "set" "DEFPOINTS" "")
  (setvar "skpoly" 1)
  (setvar "orthomode" 0)
  (command ".SKETCH" scale)
  (setvar "clayer" lay-prev)
  (setvar "orthomode" ort-prev)
  (setvar "autosnap" asn-prev)
  (princ)
)

Thanks.
Hangman  8)

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

hmspe

  • Bull Frog
  • Posts: 362
Re: Sketch...ers
« Reply #1 on: January 12, 2007, 10:08:27 PM »
I can confirm it doesn't change the layer to defpoints.  Not sure why.  The command works from the command line here, but not in a lisp routine. 

What I use in my routines that does work in 2007 is:

Code: [Select]
(defun setpower ()
  (if
    (null (tblsearch "layer" "power"))
     (command "-layer" "make" "power" "color" "cyan" "power" "")
  )
  (setvar "clayer" "power")
)

Martin
"Science is the belief in the ignorance of experts." - Richard Feynman

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Sketch...ers
« Reply #2 on: January 12, 2007, 10:49:09 PM »
Try this ..
Code: [Select]
(defun c:sk (/ lay-prev ort-prev asn-prev scale scalex)
  (setq lay-prev (getvar "clayer")
        ort-prev (getvar "orthomode")
        asn-prev (getvar "autosnap")
  )
  (if (tblsearch "layer" "DEFPOINTS")   
    (command ".-layer" "thaw" "DEFPOINTS" "on" "DEFPOINTS" "set" "DEFPOINTS" "")
    (command ".-layer" "new" "DEFPOINTS" "color" "7" "DEFPOINTS" "")
  )
  (setq scalex (* (getvar "dimscale") 0.125))
  (or (setq scale (getreal (strcat "Scale : " (rtos scalex))))
      (setq scale scalex)
  )
  (setvar "skpoly" 1)
  (setvar "orthomode" 0)
  (command ".SKETCH" scale)
  (setvar "clayer" lay-prev)
  (setvar "orthomode" ort-prev)
  (setvar "autosnap" asn-prev)
  (princ)
)

// kwb
« Last Edit: January 12, 2007, 10:50:19 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Sketch...ers
« Reply #3 on: January 15, 2007, 02:07:45 PM »
Thank you for your comments, I appreciate the help.

I can confirm it doesn't change the layer to defpoints.  Not sure why.  The command works from the command line here, but not in a lisp routine. 

What I use in my routines that does work in 2007 is:

Code: [Select]
(defun setpower ()
  (if
    (null (tblsearch "layer" "power"))
     (command "-layer" "make" "power" "color" "cyan" "power" "")
  )
  (setvar "clayer" "power")
)

Martin


I've tried that too.  In fact, my old routine from 2004 is like that.


Kerry, thank you for the code, although I think you missed one little thing,  :wink:
Try this ..
Code: [Select]
(defun c:sk (/ lay-prev ort-prev asn-prev scale scalex)
  (setq lay-prev (getvar "clayer")
        ort-prev (getvar "orthomode")
        asn-prev (getvar "autosnap")
  )
  (if [color=red](= [/color] (tblsearch "layer" "DEFPOINTS") [color=red]nil)[/color]
      ; or ; [color=red](NOT [/color](tblsearch "layer" "DEFPOINTS")[color=red])[/color]
    (command ".-layer" "thaw" "DEFPOINTS" "on" "DEFPOINTS" "set" "DEFPOINTS" "")
    (command ".-layer" "new" "DEFPOINTS" "color" "7" "DEFPOINTS" "")
  )
  (setq scalex (* (getvar "dimscale") 0.125))
  (or (setq scale (getreal (strcat "Scale : " (rtos scalex))))
      (setq scale scalex)
  )
  (setvar "skpoly" 1)
  (setvar "orthomode" 0)
  (command ".SKETCH" scale)
  (setvar "clayer" lay-prev)
  (setvar "orthomode" ort-prev)
  (setvar "autosnap" asn-prev)
  (princ)
)

// kwb

It's all good, but no, that doesn't do the trick.
I don't understand why this is not working.  It isn't turning off the ortho, nor setting the layer properly.
I have other routines that use the same commands & variable settings & they don't screw up like this one.
I've searched all over for a possible overwriting of a command SK but I can't find any so I don't think that's the problem.  In fact I changed the command to SKT and tstSK, but it didn't do me any good.
I don't know what else to do with this thing.    :-(
« Last Edit: January 15, 2007, 02:09:26 PM by Hangman »
Hangman  8)

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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Sketch...ers
« Reply #4 on: January 15, 2007, 06:35:26 PM »
What is the stuff in red ? you've changed the logic, yes ?

What I posted worked for me in AC2007
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Sketch...ers
« Reply #5 on: January 15, 2007, 07:11:22 PM »
What is the stuff in red ? you've changed the logic, yes ?

Uhhh, ... yeah ?.   :oops:

What I posted worked for me in AC2007

Well, ...  I'm a dork !!   :ugly:   I sure mis-read that one.

Hangman  8)

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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Sketch...ers
« Reply #6 on: January 15, 2007, 07:17:15 PM »
now I'm really confused !

. Why are you quoting something that I didn't post ?

. Does it work, or not ?

. If not, where is it failing ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Sketch...ers
« Reply #7 on: January 16, 2007, 01:13:08 PM »
now I'm really confused !

. Why are you quoting something that I didn't post ?

. Does it work, or not ?

. If not, where is it failing ?

Sorry Kerry, didn't mean to do that.

No, the program is not working.
It is failing at the command.
I have found that I can put everything in but the command and it works fine.  Once I implement the command, it fails.
Here's an example of what I have been playing with.
Code: [Select]
(DEFUN C:SK (/ );layr-prv line-prv colr-prv orth-prv asnp-prv scale)
  (setvar "cmdecho" 1)
  (setq layr-prv (getvar "clayer")
        line-prv (getvar "celtype")
        colr-prv (getvar "cecolor")
        orth-prv (getvar "orthomode")
        asnp-prv (getvar "autosnap")
        scale (* (getvar "dimscale") 0.125))
  (if (NOT (tblsearch "layer" "DEFPOINTS"))
    (command ".-layer" "new" "DEFPOINTS" "color" "7" "DEFPOINTS" ""))
  (command ".-layer" "thaw" "DEFPOINTS" "on" "DEFPOINTS" "set" "DEFPOINTS" "")
  (setvar "cecolor" "bylayer")
  (setvar "celtype" "bylayer")
  (setvar "orthomode" 0)
  (setvar "skpoly" 1)
  (setvar "sketchinc" scale)
;[color=red]  (command ".SKETCH" "")[/color]
;[color=red]  (command ".line" "")[/color]
[color=red]  (command ".rectang")[/color]
  (setvar "clayer" layr-prv)
  (setvar "celtype" line-prv)
  (setvar "cecolor" colr-prv)
  (setvar "orthomode" orth-prv)
  (setvar "autosnap" asnp-prv)
  (princ)
)

The commands posted in red.  It doesn't matter what it is, it fails.
Any ideas as to why ??

Thanks.
Hangman  8)

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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Sketch...ers
« Reply #8 on: January 16, 2007, 05:33:46 PM »
Did you try the code I posted ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Sketch...ers
« Reply #9 on: January 16, 2007, 06:02:04 PM »
Did you try the code I posted ?

Yes I did.  I found it to be the command line for some reason.  I took the command line out and it ran perfectly.  So I replaced the SKETCH command with LINE and it failed.  I replaced LINE with RECTANG and it failed.
But I can put an ALERT in it and it works beautifully.  The Layer changes, the linetype, the color, the ortho, ...  everything works if I take out the command line.

I've rewritten this lisp routine from scratch, but it did not change a thing, it still will not run properly.
Hangman  8)

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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Sketch...ers
« Reply #10 on: January 16, 2007, 06:40:44 PM »
Try this ..
Code: [Select]
(defun c:sk-1 (/ lay-prev ort-prev asn-prev scale scalex)
  (setq lay-prev (getvar "clayer")
        ort-prev (getvar "orthomode")
        asn-prev (getvar "autosnap")
  )
  (setvar "skpoly" 1)
  (setvar "orthomode" 0)
  (if (tblsearch "layer" "DEFPOINTS")
    (command ".-layer" "thaw" "DEFPOINTS" "on" "DEFPOINTS" "set" "DEFPOINTS" "")
    (command ".-layer" "new" "DEFPOINTS" "color" "7" "DEFPOINTS" "")
  )
  (setq scalex (* (getvar "dimscale") 0.125))
  (or (setq scale (getreal (strcat "Scale : " (rtos scalex)))) (setq scale scalex))
  ;;
  (vl-cmdf ".SKETCH" scale) 
    (while (= 1 (logand (getvar "cmdactive") 1))
    (command pause)
  )
  (getreal (strcat "Enter a number : " (rtos 10)))
  ;;
  (command ".rectang" )
    (while (= 1 (logand (getvar "cmdactive") 1))
    (command pause)
  ) 
  (getreal (strcat "Enter a number : " (rtos 20)))
  ;;
  (setvar "clayer" lay-prev)
  (setvar "orthomode" ort-prev)
  (setvar "autosnap" asn-prev)
  (princ)
)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Sketch...ers
« Reply #11 on: January 16, 2007, 07:25:15 PM »
Kerry,  THAT WORKED !!!
Thank you !!!

Now, can you help me understand how ??
Code: [Select]
(vl-cmdf ".SKETCH" scale) 
    (while (= 1 (logand (getvar "cmdactive") 1))
    (command pause)
  )

This is an interesting piece of code.  I can't find the vl-cmdf in the help files.  I see its taking the place of the (command ".SKE... ) line, and obviously from the VL side of life.  Is it different than the old (command ". ...) line ??  Obviously this is what did the trick, but I don't understand how or why it did the trick.

The 'while' statement I don't understand either.
Correct me if I'm wrong, what this is saying (my interpretation anyway)
While  1 is equal to 1 AND the variable "cmdactive" (mine is currently at 33)
Then  continue the command.

How does this work ??
Hangman  8)

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

MickD

  • King Gator
  • Posts: 3637
  • (x-in)->[process]->(y-out) ... simples!
Re: Sketch...ers
« Reply #12 on: January 16, 2007, 07:40:04 PM »
my guess, it's a 'logical' and which AND's 2 values together, if they're the same it evaluates to TRUE.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Sketch...ers
« Reply #13 on: January 16, 2007, 07:47:04 PM »
The vl-cmdf is irrelevant.

The fix is the use of
Code: [Select]
(while (= 1 (logand (getvar "cmdactive") 1))
    (command pause)
)

basically the SKETCH, LINE, RECTANGLE commands you tried require additional input from the user.
The (while .. construct just tests if the COMMAND is still active and continues to PAUSE inside that command while you are providing input to it.


« Last Edit: January 16, 2007, 07:51:56 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Sketch...ers
« Reply #14 on: January 16, 2007, 07:48:59 PM »
Regarding the possible values for CMDACTIVE refer to the help files, it is reasonably well documented.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.