Code Red > AutoLISP (Vanilla / Visual)

Applying a scale

(1/3) > >>

sln8458:
My next problem!
So I've added a 'Metric/Imperial' Scaling toggle to my DCL & LSP files, TB24.
See image below, highlighted red.
This works in part, in that when the 'toggle' is selected (ticked) the scale is applied to the inserted blocks.
It also is applied to the Pipe creation/extrusion.

However, if the toggle is 'de-selected' (ticked in error) the scale is NOT reset.

.

--- Code: ---
(defun TB24_FLAG ()
(setq sca "1") ;store metric / imperial scale
);end TB24_FLAG
;-----------------------------------------------
(defun SET_DIM ()
(setvar 'dimzin 0)
    (setq
    N1 (nth 3 SIZE_DIMS)
    N2 (nth 4 SIZE_DIMS)
    N3 (nth 5 SIZE_DIMS)
    N4 (nth 6 SIZE_DIMS)
    N5 (nth 7 SIZE_DIMS)
    N6 (nth 8 SIZE_DIMS)
    N7 (nth 9 SIZE_DIMS)
    N8 (nth 10 SIZE_DIMS)
    N9 (nth 11 SIZE_DIMS)
    N10 (nth 12 SIZE_DIMS)
    ) ;end setq
;
  (set_tile "n1" (rtos N1 2 2))
  (set_tile "n2" (rtos N2 2 2))
  (set_tile "n3" (rtos N3 2 2))
  (set_tile "n4" (rtos N4 2 2))
  (set_tile "n5" (rtos N5 2 2))
  (set_tile "n6" (rtos N6 2 2))
  (set_tile "n7" (rtos N7 2 2))
  (set_tile "n8" (rtos N8 2 1))
  (set_tile "n9" (rtos N9 2 2)) 
  (set_tile "n10" (rtos N10 2 2))
  (setvar 'dimzin 8)
;
  (if (= SCA "1")(SCA_TO_IMP)) ;_ end of if ;NEW LINE ADDED FOR SCALING
;
) ;End SET_DIM
 ;------------------------------------------------------------------------;
(defun SCA_TO_IMP ()
   (cond ((= SCA "1")(setq scal "0.039370"))
; (T (setq scal "1.000000"))                  ;didn't work !!
            ((= SCA "0")(setq scal "1.000000"))
) ;end of cond
;
      N1  (* N1 0.03937)
      N2  (* N2 0.03937)
      N3  (* N3 0.03937)
      N4  (* N4 0.03937)
      N5  (* N5 0.03937)
      N6  (* N6 0.03937)
      N7  (* N7 0.03937)
      N8  (* N8 0.03937)
      N9  (* N9 0.03937)
      N10  (* N10 0.03937)
);end of setq
) ;End SCA_TO_IMP

--- End code ---

My next goal is to apply the scaling factor to the displayed dimensions, highlighted blue in the image.
I'm struggling with these 2, can anyone give me a few pointers?
Full code attached.
SteveN

PKENEWELL:
As far as I can tell without spending a whole lot of time on it. Your action tile statement for the "tb24" tile goes to the (tb24_flag) function. The (tb24_flag) function always sets the SCA to "1" regardless of the value of the tile. You should set SCA to the tile $value returned by action tile.

Change This:

--- Code - Auto/Visual Lisp: ---(defun TB24_FLAG ()   (setq sca "1"));end TB24_FLAG to This

--- Code - Auto/Visual Lisp: ---(defun TB24_FLAG ()   (setq sca $value));end TB24_FLAG 

sln8458:

--- Quote from: PKENEWELL on January 14, 2021, 10:51:23 AM ---As far as I can tell without spending a whole lot of time on it. Your action tile statement for the "tb24" tile goes to the (tb24_flag) function. The (tb24_flag) function always sets the SCA to "1" regardless of the value of the tile. You should set SCA to the tile $value returned by action tile.

Change This:

--- Code - Auto/Visual Lisp: ---(defun TB24_FLAG ()   (setq sca "1"));end TB24_FLAG to This

--- Code - Auto/Visual Lisp: ---(defun TB24_FLAG ()   (setq sca $value));end TB24_FLAG 
--- End quote ---

Many thanks  :-) that solved the scale reset issue.
Now to resolve the text updating.

PKENEWELL:
You can use the (set_tile) function from within the function (Sca_To_Imp) called by the action_tile for "tb24"

If i'm am correct that the N1, N2, N3... values are the ones that are updating. Change This:

--- Code - Auto/Visual Lisp: ---(defun SCA_TO_IMP ()   (cond ((= SCA "1")(setq scal "0.039370"))            ((= SCA "0")(setq scal "1.000000"))   ) ;end of cond;;from Ron Leigh ;   (setq num1 12.34);   (setq num2 (* 10 num1)) ;  (setq      N1  (* N1 0.03937)      N2  (* N2 0.03937)      N3  (* N3 0.03937)      N4  (* N4 0.03937)      N5  (* N5 0.03937)      N6  (* N6 0.03937)      N7  (* N7 0.03937)      N8  (* N8 0.03937)      N9  (* N9 0.03937)      N10  (* N10 0.03937)         );end of setq;) ;End SCA_TO_IMP 
to This:

--- Code - Auto/Visual Lisp: ---(defun SCA_TO_IMP ()   (cond ((= SCA "1")(setq scal "0.039370"))            ((= SCA "0")(setq scal "1.000000"))   ) ;end of cond;;from Ron Leigh ;   (setq num1 12.34);   (setq num2 (* 10 num1)) ;  (setq      N1  (* N1 0.03937)      N2  (* N2 0.03937)      N3  (* N3 0.03937)      N4  (* N4 0.03937)      N5  (* N5 0.03937)      N6  (* N6 0.03937)      N7  (* N7 0.03937)      N8  (* N8 0.03937)      N9  (* N9 0.03937)      N10  (* N10 0.03937)         );end of setq  (set_tile "n1" (rtos N1 2 2))  (set_tile "n2" (rtos N2 2 2))  (set_tile "n3" (rtos N3 2 2))  (set_tile "n4" (rtos N4 2 2))  (set_tile "n5" (rtos N5 2 2))  (set_tile "n6" (rtos N6 2 2))  (set_tile "n7" (rtos N7 2 2))  (set_tile "n8" (rtos N8 2 1))  (set_tile "n9" (rtos N9 2 2))    (set_tile "n10" (rtos N10 2 2));) ;End SCA_TO_IMP 

sln8458:
@PKENEWELL
Thanks again.

--- Quote ---If i'm am correct that the N1, N2, N3... values are the ones that are updating.
--- End quote ---
Yes that is correct :)
I was testing your suggestion just before you posted, it does work, but........
when de-selecting the scale toggle the dimensions are again multiplied by the scale factor of 0.03937 ?(mm to inch) rather than being reset to their original values.

I've just tried adding this:   
(if (= SCA "0")(SET_DIM)) ;_ end of if
into SCA_TO_IMP (see below)


--- Code: ---(defun SCA_TO_IMP ()
  (cond ((= SCA "1")(setq scal "0.039370"))
(T (setq scal "1.000000"))
) ;end of cond
;
;from Ron Leigh
;   (setq num1 12.34)(setq num2 (* 10 num1))
;
  (if (= SCA "0")(SET_DIM)) ;_ end of if

  (setq
      N1  (* N1 0.03937)
      N2  (* N2 0.03937)
      N3  (* N3 0.03937)
      N4  (* N4 0.03937)
      N5  (* N5 0.03937)
      N6  (* N6 0.03937)
      N7  (* N7 0.03937)
      N8  (* N8 0.03937)
      N9  (* N9 0.03937)
      N10  (* N10 0.03937)
);end of setq
;
  (set_tile "n1" (rtos N1 2 2))
  (set_tile "n2" (rtos N2 2 2))
  (set_tile "n3" (rtos N3 2 2))
  (set_tile "n4" (rtos N4 2 2))
  (set_tile "n5" (rtos N5 2 2))
  (set_tile "n6" (rtos N6 2 2))
  (set_tile "n7" (rtos N7 2 2))
  (set_tile "n8" (rtos N8 2 1))
  (set_tile "n9" (rtos N9 2 2)) 
  (set_tile "n10" (rtos N10 2 2))
;
) ;End SCA_TO_IMP

--- End code ---

This works in part. I have attached a pdf of images as it's long to explain without.
following this sequence:
Load dialogue
select fitting type including size (dimensions displayed)
select mm to inch results in dimensions being reduced by 0.03937
de-select mm to inch results in NO change to displayed dimensions!!
re-select mm to inch results in dimensions being reduced by 0.03937 again!!
de-select mm to inch results in dimensions being reset to the values after first application of 0.03937

Navigation

[0] Message Index

[#] Next page

Go to full version