TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jlogan02 on December 12, 2022, 04:04:35 PM

Title: Osmode won't set/Line not visible during command
Post by: jlogan02 on December 12, 2022, 04:04:35 PM
Can't seem to set the osmode to 39 during the command. I start by setting it to something other than 39, execute the command and whatever I set it to prior to execution remains.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo ( / *error* osm pt1 pt2)
  2.  
  3.   (defun *error* (msg)
  4.     (if osm (setvar 'osmode osm))
  5.     (if (not (member msg '("Function cancelled" "quit / exit abort")))
  6.       (princ (strcat "\nError: " msg))
  7.     )
  8.     (princ)
  9.   )
  10.  
  11.   (setq osm (getvar 'osmode))
  12.   (setq pt1 (getpoint "\nSpecify first point"))
  13.   (setq pt2 (getpoint "\nSpecify next point"))
  14.  
  15.   (setvar 'osmode 39)
  16.   (command ".line" pt1 pt2)
  17.  
  18.   (setvar 'osmode osm)
  19.   (princ)
  20. )

Also, the line doesn't appear after I pick the first point. It does when typing line at the command line.
Layer is not locked or frozen.
Layer is current.
Layer color does not match background.
Graphics performance turned off.


Title: Re: Osmode won't set/Line not visible during command
Post by: Lee Mac on December 12, 2022, 04:26:17 PM
Note that you are acquiring the points using the getpoint expressions, hence the OSMODE would need to be set prior to these expressions. To display a "preview" you can supply the second getpoint expression with the first point, representing "rubber band" argument.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo ( / *error* osm pt1 pt2)
  2.      
  3.     (defun *error* (msg)
  4.         (if osm (setvar 'osmode osm))
  5.         (if (not (member msg '("Function cancelled" "quit / exit abort")))
  6.             (princ (strcat "\nError: " msg))
  7.         )
  8.         (princ)
  9.     )
  10.      
  11.     (setq osm (getvar 'osmode))
  12.     (setvar 'osmode 39) ;; Set OSMODE here
  13.     (if
  14.         (and
  15.             (setq pt1 (getpoint "\nSpecify first point"))
  16.             (setq pt2 (getpoint "\nSpecify next point" pt1)) ;; Supply rubber band argument
  17.         )
  18.         (command "_.line" "_non" pt1 "_non" pt2)
  19.     )
  20.     (setvar 'osmode osm)
  21.     (princ)
  22. )
Title: Re: Osmode won't set/Line not visible during command
Post by: jlogan02 on December 12, 2022, 04:49:05 PM
My first attempt had
Code - Auto/Visual Lisp: [Select]
  1. (setvar 'osmode 36)
where you have it, and it wasn't working, so I moved it to where the OP shows. Had I added the pt1 for rubber banding, I wouldn't have gotten the results I was getting, which was a fail.

Thanks
Title: Re: Osmode won't set/Line not visible during command
Post by: jlogan02 on December 12, 2022, 04:49:35 PM
36...39...whatever.