Author Topic: Applying a scale  (Read 2890 times)

0 Members and 1 Guest are viewing this topic.

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Applying a scale
« on: January 14, 2021, 03:59:03 AM »
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: [Select]

(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

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
There is no such  thing as a 'silly question' to those who do not know!

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: Applying a scale
« Reply #1 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: [Select]
  1. (defun TB24_FLAG ()
  2.    (setq sca "1")
  3. );end TB24_FLAG
  4.  
to This
Code - Auto/Visual Lisp: [Select]
  1. (defun TB24_FLAG ()
  2.    (setq sca $value)
  3. );end TB24_FLAG
  4.  
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: Applying a scale
« Reply #2 on: January 14, 2021, 12:04:09 PM »
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: [Select]
  1. (defun TB24_FLAG ()
  2.    (setq sca "1")
  3. );end TB24_FLAG
  4.  
to This
Code - Auto/Visual Lisp: [Select]
  1. (defun TB24_FLAG ()
  2.    (setq sca $value)
  3. );end TB24_FLAG
  4.  

Many thanks  :-) that solved the scale reset issue.
Now to resolve the text updating.
There is no such  thing as a 'silly question' to those who do not know!

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: Applying a scale
« Reply #3 on: January 14, 2021, 12:29:40 PM »
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: [Select]
  1. (defun SCA_TO_IMP ()
  2.    (cond ((= SCA "1")(setq scal "0.039370"))
  3.             ((= SCA "0")(setq scal "1.000000"))
  4.    ) ;end of cond
  5. ;
  6. ;from Ron Leigh
  7. ;   (setq num1 12.34)
  8. ;   (setq num2 (* 10 num1))
  9. ;
  10.   (setq
  11.       N1  (* N1 0.03937)
  12.       N2  (* N2 0.03937)
  13.       N3  (* N3 0.03937)
  14.       N4  (* N4 0.03937)
  15.       N5  (* N5 0.03937)
  16.       N6  (* N6 0.03937)
  17.       N7  (* N7 0.03937)
  18.       N8  (* N8 0.03937)
  19.       N9  (* N9 0.03937)
  20.       N10  (* N10 0.03937)
  21.          );end of setq
  22. ;
  23. ) ;End SCA_TO_IMP
  24.  

to This:
Code - Auto/Visual Lisp: [Select]
  1. (defun SCA_TO_IMP ()
  2.    (cond ((= SCA "1")(setq scal "0.039370"))
  3.             ((= SCA "0")(setq scal "1.000000"))
  4.    ) ;end of cond
  5. ;
  6. ;from Ron Leigh
  7. ;   (setq num1 12.34)
  8. ;   (setq num2 (* 10 num1))
  9. ;
  10.   (setq
  11.       N1  (* N1 0.03937)
  12.       N2  (* N2 0.03937)
  13.       N3  (* N3 0.03937)
  14.       N4  (* N4 0.03937)
  15.       N5  (* N5 0.03937)
  16.       N6  (* N6 0.03937)
  17.       N7  (* N7 0.03937)
  18.       N8  (* N8 0.03937)
  19.       N9  (* N9 0.03937)
  20.       N10  (* N10 0.03937)
  21.          );end of setq
  22.   (set_tile "n1" (rtos N1 2 2))
  23.   (set_tile "n2" (rtos N2 2 2))
  24.   (set_tile "n3" (rtos N3 2 2))
  25.   (set_tile "n4" (rtos N4 2 2))
  26.   (set_tile "n5" (rtos N5 2 2))
  27.   (set_tile "n6" (rtos N6 2 2))
  28.   (set_tile "n7" (rtos N7 2 2))
  29.   (set_tile "n8" (rtos N8 2 1))
  30.   (set_tile "n9" (rtos N9 2 2))  
  31.   (set_tile "n10" (rtos N10 2 2))
  32. ;
  33. ) ;End SCA_TO_IMP
  34.  
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: Applying a scale
« Reply #4 on: January 15, 2021, 03:56:29 AM »
@PKENEWELL
Thanks again.
Quote
If i'm am correct that the N1, N2, N3... values are the ones that are updating.
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: [Select]
(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

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
« Last Edit: January 15, 2021, 04:43:52 AM by sln8458 »
There is no such  thing as a 'silly question' to those who do not know!

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: Applying a scale
« Reply #5 on: January 15, 2021, 10:00:17 AM »
Assuming that you are always starting in Millimeters. You need to rescale up the values back up to Metric when unchecking the tile ("tb24 tile returns "0"):

Change This:
Code - Auto/Visual Lisp: [Select]
  1. (cond ((= SCA "1")(setq scal "0.039370"))
  2.                 (T (setq scal "1.000000"))
  3.                 ) ;end of cond
  4.       N1  (* N1 0.03937)
  5.       N2  (* N2 0.03937)
  6.       N3  (* N3 0.03937)
  7.       N4  (* N4 0.03937)
  8.       N5  (* N5 0.03937)
  9.       N6  (* N6 0.03937)
  10.       N7  (* N7 0.03937)
  11.       N8  (* N8 0.03937)
  12.       N9  (* N9 0.03937)
  13.       N10  (* N10 0.03937)
  14.          );end of setq
  15.  
to This:
Code - Auto/Visual Lisp: [Select]
  1. (cond ((= SCA "1")(setq scal "0.039370"))
  2.                 (T (setq scal "25.4"))
  3.                 ) ;end of cond
  4.       N1  (* N1 (atof scal))
  5.       N2  (* N2 (atof scal))
  6.       N3  (* N3 (atof scal))
  7.       N4  (* N4 (atof scal))
  8.       N5  (* N5 (atof scal))
  9.       N6  (* N6 (atof scal))
  10.       N7  (* N7 (atof scal))
  11.       N8  (* N8 (atof scal))
  12.       N9  (* N9 (atof scal))
  13.       N10 (* N10 (atof scal))
  14.          );end of setq
  15.  

Note - If there are some cases when you start in Inches, then you will have to detect the units before starting up and set the values and the "tb24" toggle value appropriately.
There are 2 possible ways to detect the units:
1) Use the MEASUREMENT system variable: this assumes that this system variable is being set properly in your drawings i.e. 1 = Metric Units, 0 = Imperial Units.
2) use the MEASUREINIT system variable: same as above.
« Last Edit: January 15, 2021, 10:06:42 AM by PKENEWELL »
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: Applying a scale
« Reply #6 on: January 15, 2021, 12:21:32 PM »
(T (setq scal "25.4")) :facepalm:, oh I feel stupid (actually I am)  :uglystupid2:

Thanks again.
It did throw up another issue, I used scal for the scale factor in the Insert command, so I have added another variable insertscal which sorted that.
Also thanks for helping with another issue I was having with using the variable scal when redefining N1 to N10, adding atof solved that one.

here is the code.
Code: [Select]
(defun SCA_TO_IMP ()
  (cond ((= SCA "1")(setq scal "0.039370"))
(T (setq scal "25.40000"))
) ;end of cond
;
  (cond ((= SCA "1")(setq insertscal "0.039370"))
(T (setq insertscal "1.000000"))
) ;end of cond

  (setq
      N1  (* N1 (atof scal))
      N2  (* N2 (atof scal))
      N3  (* N3 (atof scal))
      N4  (* N4 (atof scal))
      N5  (* N5 (atof scal))
      N6  (* N6 (atof scal))
      N7  (* N7 (atof scal))
      N8  (* N8 (atof scal))
      N9  (* N9 (atof scal))
      N10  (* N10 (atof scal))
);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

I seem to be running up a large 'beer' tab :wideeyed2:
Thanks again.
There is no such  thing as a 'silly question' to those who do not know!

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Applying a scale
« Reply #7 on: January 15, 2021, 01:06:23 PM »
Just a quick observation ... you could also set all those tiles like so:
Code - Auto/Visual Lisp: [Select]
  1. ;;;(set_tile "n1" (rtos n1 2 2))
  2. ;;;(set_tile "n2" (rtos n2 2 2))
  3. ;;;(set_tile "n3" (rtos n3 2 2))
  4. ;;;(set_tile "n4" (rtos n4 2 2))
  5. ;;;(set_tile "n5" (rtos n5 2 2))
  6. ;;;(set_tile "n6" (rtos n6 2 2))
  7. ;;;(set_tile "n7" (rtos n7 2 2))
  8. ;;;(set_tile "n8" (rtos n8 2 1))
  9. ;;;(set_tile "n9" (rtos n9 2 2))
  10. ;;;(set_tile "n10" (rtos n10 2 2))
  11.  
  12. (setq n 0)
  13. (repeat 10 (setq n (1+ n)) (set_tile (setq a (strcat "n" (itoa n))) (rtos (eval (read a)) 2 2)))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: Applying a scale
« Reply #8 on: January 15, 2021, 02:45:31 PM »
Just a quick observation ... you could also set all those tiles like so:
Code - Auto/Visual Lisp: [Select]
  1. ;;;(set_tile "n1" (rtos n1 2 2))
  2. ;;;(set_tile "n2" (rtos n2 2 2))
  3. ;;;(set_tile "n3" (rtos n3 2 2))
  4. ;;;(set_tile "n4" (rtos n4 2 2))
  5. ;;;(set_tile "n5" (rtos n5 2 2))
  6. ;;;(set_tile "n6" (rtos n6 2 2))
  7. ;;;(set_tile "n7" (rtos n7 2 2))
  8. ;;;(set_tile "n8" (rtos n8 2 1))
  9. ;;;(set_tile "n9" (rtos n9 2 2))
  10. ;;;(set_tile "n10" (rtos n10 2 2))
  11.  
  12. (setq n 0)
  13. (repeat 10 (setq n (1+ n)) (set_tile (setq a (strcat "n" (itoa n))) (rtos (eval (read a)) 2 2)))

Great Idea ronjonp! That saves the OP a ton of code.

EDIT - you could apply the same reasoning to setting the variables. I dug out this old function, but I'm sure it could be boiled down a bit more:

Code: [Select]
(defun passvar (varnam value / pass)
(set (quote pass) (read varnam))
(set pass value)
)
(setq n 0)
(repeat 10 (setq n (1+ n)) (passvar (strcat "N" n) (atof scal)))
« Last Edit: January 15, 2021, 02:59:06 PM by PKENEWELL »
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: Applying a scale
« Reply #9 on: January 15, 2021, 02:47:25 PM »
(T (setq scal "25.4")) :facepalm:, oh I feel stupid (actually I am)  :uglystupid2:

Thanks again.
It did throw up another issue, I used scal for the scale factor in the Insert command, so I have added another variable insertscal which sorted that.
Also thanks for helping with another issue I was having with using the variable scal when redefining N1 to N10, adding atof solved that one.

...

I seem to be running up a large 'beer' tab :wideeyed2:
Thanks again.

Glad I could help!  :-D Save me a beer.
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: Applying a scale
« Reply #10 on: February 15, 2023, 04:45:17 AM »
Sorry to resurect this old post.

I normally work in metric, so havn't noticed this, but if the Metric/Imperial 'toggle' is NOT selected last any following selection resets the toggle.

Is this normal?

Example:
Following the original image, selecting
Fittings
Reducing Tee
Scaling
Sched 40

When selecting Sched 40 the 'tick' in the scaling toggle is removed.

SteveN
There is no such  thing as a 'silly question' to those who do not know!

PKENEWELL

  • Bull Frog
  • Posts: 317
Re: Applying a scale
« Reply #11 on: March 21, 2023, 01:40:18 PM »
Sorry to resurect this old post.

I normally work in metric, so havn't noticed this, but if the Metric/Imperial 'toggle' is NOT selected last any following selection resets the toggle.

Is this normal?

Example:
Following the original image, selecting
Fittings
Reducing Tee
Scaling
Sched 40

When selecting Sched 40 the 'tick' in the scaling toggle is removed.

SteveN

Hi SteveN,

Sorry, but I have been extremely busy with my day job and never noticed this new post back in February. Looking at it now, I can't help you without a copy of the DCL file. Previously I was able to confer what was going on specifically with the code you specified, but I can't evaluate the whole program function without the DCL file.

If you send me the DCL file I will take a look. I suspect it is a (set_tile) call from within a function called by an (action_tile) statement, or the result of closing and reopening the Dialog, which does not remember it's values.

Regards, - Phil

 
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt