Author Topic: Acad2008 and nentsel  (Read 5003 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Acad2008 and nentsel
« Reply #15 on: March 28, 2008, 08:49:45 AM »
Binky,
I fixed the code above so copy it again, thanks.
  Added (vl-load-com), I have this in my ACADdoc.lsp so I sometimes forget to add it to sample code
  fixed the repeat problem, added True to the end of the condition
 
As for the OR, here is an excerpt from this thread:
http://www.theswamp.org/index.php?topic=13046.msg158557#msg158557

The  OR will process each line as long as they are false, it will quit when true is returned
Code: [Select]
(or (a. is true) ; stop here
    (b. does not get this far)
)
Code: [Select]
(or (a. is false) ; keep going
    (b. do this & if false keep going)
    (c. do this if b was false)
)

So this will work as well with a variable with a value or nil
Code: [Select]
(setq var "Some Text")
(or  var ; Stop here if the var has a value, if nil then keep going
     (setq var "Some Text")
)

You can use IF or OR in the situation but I prefer OR as the VLIDE format keeps it in one line.
This is just a personal preference.

Read the thread, link posted, about WHILE and COND.
If you still have questions I'll be glad to try and answer them.
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.

Binky

  • Guest
Re: Acad2008 and nentsel
« Reply #16 on: March 31, 2008, 01:58:01 PM »
CAB, Thanks for the explanation, that helps and will be put to use in the future as well.

Here is the final version.  I added a 'if' statement so that if the user picked something that they shouldn't have they can correct it without having to restart the command.

Code: [Select]
;;;;;;
;
; Swaps color of object between 'bylayer' and specified color
; exclr: specified color to use for existing
; ename: selected entity name
; obj: ename converted to a vba object
; x: junk place holder
; 03.28.2008 revised by CAB(via the Swamp)
;;;;;;


(defun c:toggle (/ ename obj exclr x)
(vl-load-com)
  (setq exclr (getint "\nColor number of existing <Enter for dialog>: "))
  (or exclr (setq exclr (acad_colordlg 9))) ; sets existing color via dialog
  (while
    (cond
      ((null exclr)(prompt "\nUser Quit."))
      ((null (setvar "errno" 0))); resets error number
      ((setq ename (car (nentsel "\nSelect Item: ")))
        (setq obj (vlax-ename->vla-object ename)); converts object to vba
(if (assoc 62 (entget ename))
(vla-put-color obj 256)
(vla-put-color obj exclr))
        (vla-Regen (vla-get-ActiveDocument (vlax-get-acad-object)) acActiveViewport)
t)
      ((= (setq x (getvar "errno")) 7)(princ "Missed")); back to top
      ((= (setq x (getvar "errno")) 52) nil); ENTER KEY kills loop
      (t (princ "Unknown Error, Try again"))
    )
  )
  (princ "\nThank You")
  (princ)
);end_defun

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Acad2008 and nentsel
« Reply #17 on: March 31, 2008, 03:29:39 PM »
You're welcome.

And for the IF I would use this.
Code: [Select]
       (if (= (vla-get-color obj) 256)
         (vla-put-color obj exclr)
         (vla-put-color obj 256)
       )
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.