scale lsp

scale lsp

nychoe1
Advocate Advocate
1,223 Views
7 Replies
Message 1 of 8

scale lsp

nychoe1
Advocate
Advocate

hello. I am writting a lsp. it's scale lsp. It works continuously.

if scale value is 0.8. just enter ---> does not working.  what is the problem. some help plz

always thank you all guys

 

(defun c:saa (/ s1 p1)

(if (= mss nil)
(setq mss 0.8))
(setq dxx (getdist (strcat "\n>> input scale <"(rtos mss 2 2)">: ")))
(if (numberp dxx)(setq mss dxx))

(while

    (setq s1 (ssget ))
    (setq p1 (getpoint "\npick base point:"))
    (command "_.scale" s1 "" p1 dxx )
 (terpri))
(princ)
)

0 Likes
Accepted solutions (2)
1,224 Views
7 Replies
Replies (7)
Message 2 of 8

Sea-Haven
Mentor
Mentor

Just work out the if nil for dxx a press enter. 

 

(if (= dxx nil )(setq  dxx mss)(setq mss dxx))
0 Likes
Message 3 of 8

Moshe-A
Mentor
Mentor
Accepted solution

@nychoe1 ,

 

here is a fix

 

enjoy

moshe

 

 

(defun c:saa (/ mss dxx s1 p1)
 (if (not mss)
  (setq mss 0.8)
 )
  
 (if (not (setq dxx (getdist (strcat "\n>> input scale <<" (rtos mss 2 2)">: "))))
  (setq dxx mss)
 )

 (while (setq s1 (ssget))
  (setq p1 (getpoint "\npick base point:"))
  (command "_.scale" s1 "" p1 dxx)
 )
  
 (princ)
)
0 Likes
Message 4 of 8

ВeekeeCZ
Consultant
Consultant

One step faster version

 

(defun c:saa (/ dxx s1 p1)

  (or *mss*  				; its global variable
      (setq *mss* 0.8))
  
  (setq dxx (cond ((getdist (strcat "\n>> input scale <" (rtos *mss* 2 2)">: ")))
                  (*mss*)))

  (while (and (setq s1 (ssget "_:S"))
              (sssetfirst nil s1)
              (setq p1 (getpoint "\npick base point: "))
              )
    (command "_.scale" s1 "" "_non" p1 dxx))
  
 (princ)
)
0 Likes
Message 5 of 8

Kent1Cooper
Consultant
Consultant

@nychoe1 wrote:

....

    (command "_.scale" s1 "" p1 dxx )
....


 

I think all you need to do is to use mss instead of dxx there:

 

    (command "_.scale" s1 "" p1 mss )

 

Here's the way I like to do the setting of a variable with a default, which eliminates the need to pre-set it if it doesn't exist, and eliminates the temporary variable [in your case, dxx].  Replace this much:

 

(if (= mss nil)
(setq mss 0.8))
(setq dxx (getdist (strcat "\n>> input scale <"(rtos mss 2 2)">: ")))
(if (numberp dxx)(setq mss dxx))

 

with this:

 

(setq mss

  (cond

    ( (getdist

         (strcat "\n>> input scale <" (rtos (cond (mss) (0.8)) 2 2) ">: ")

       ); getdist

    ); User-input condition

    (mss); on Enter with prior value -- keep it

    (0.8); on Enter without prior value [first use]

  ); cond

)' setq

 

[which isn't as much longer as it looks, if you eliminate the commentary]

 

(setq mss

  (cond

    ((getdist (strcat "\n>> input scale <" (rtos (cond (mss) (0.8)) 2 2) ">: ")))

    (mss)

    (0.8)

  ); cond

)' setq

Kent Cooper, AIA
0 Likes
Message 6 of 8

ВeekeeCZ
Consultant
Consultant
Accepted solution

@ВeekeeCZ wrote:

One step faster version

 

(defun c:saa (/ s1 p1)

  (or *mss*  				; its global variable
      (setq *mss* 0.8))
  
  (setq *mss*(cond ((getdist (strcat "\n>> input scale <" (rtos *mss* 2 2)">: ")))
                  (*mss*)))

  (while (and (setq s1 (ssget "_:S"))
              (sssetfirst nil s1)
              (setq p1 (getpoint "\npick base point: "))
              )
    (command "_.scale" s1 "" "_non" p1 *mss*))
  
 (princ)
)

Ou, Kent's right, the variable has to be uniformly *mss*

0 Likes
Message 7 of 8

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

....

)' setq

[which isn't as much longer as it looks ....


 

Whoops -- got the next-door key by accident -- that should be:

); setq

in both places.

 

[And it's actually shorter, just in terms of total code characters.]

Kent Cooper, AIA
0 Likes
Message 8 of 8

nychoe1
Advocate
Advocate

tnank you all. I got a lot of help.

0 Likes