Somewhat strange request - multiply an entered value by a constant when entering it...

 I am looking for a way to automatically have numerical values multiplied by a constant (0.12) whenever they are entered -- as input on an OFFSET command, or during the PLINE command, or as distance input for a COPY command, etc.

Ideally how this would work is instead of entering SPACE or ENTER to terminate the input, I'd hit a function key (let's assume F1) and then some customized code for F1 would take whatever number was on the command line, multiply it by 0.12, and then pass it along.  So F1 would operate just like SPACE or ENTER, except the multiplication by the constant would happen first.

Is something like this possible?  

Many thanks!

Comments


  • Hi John,

    Your request is not strange. I have encountered requests like this from users.

    Here are two small functions that you can call off the command line when a CAD command is in progress.

    (fn val) will scale any real value multiplied by a factor and send it to the command in question.

    (ptfn) will scale the X, Y and Z of a picked point multiplied by a factor and send it to the command in question.

    You can modify the functions to apply any complex transformation, not just a simple multiplication arithmetic as shown here.

    Hope thsi helps

    - Rakesh Rao
    http://rakeshrao.typepad.com

    [code]
    ; Function 'fn' will process any value and apply a multiplication factor
    (defun fn ( val / fac )
    (setq fac 1.1)
    ( * val fac)
    )

    ; Function 'ptfn' will process any point input and apply a multiplication factor
    (defun ptfn ( / pt fac )
    (initget 1)
    (setq
     fac 1.1
     pt  (getpoint)
     pt  (list (* (car pt) fac) (* (cadr pt) fac) (* (caddr pt) fac))
    )
    pt
    )
    [/code]

  •  Thank you for this suggestion.  As I understand it (and as I've tried this solution just now) it seems that to enter my value in the offset command, for instance, I would type:

    OFFSET
    (fn 6)

    and that would use 6x the constant defined in FN as my input.

    The downside of this is that is requires a lot of extra typing for each entry -- I have to type out the parenthesis, etc. each time.  I'm entering a lot of numbers, so I was hoping to find a solution that did not use more keystrokes than the usual method of typing SPACE or ENTER to terminate the entry.

    Is there any way to accomplish this with a redefined command key or something?  It would be nice if there were an Autocad system variable that applied a scale factor to all input like this, but I can't find such a thing.

  • Try the code below and use a keyboard shortcut with the command 'SI (note the apostrophe). I am also attaching the code.
    [code](defun c:SI ( / input scale)
      (setq *ScaleInput*
        (cond
          (*ScaleInput*
          )
          (1.0
          )
        )
      )
      (while (not input)
        (initget "Scale eXit")
        (setq input (getdist (strcat "\nCurrent scale=" (rtos *ScaleInput*) ": Scale/eXit/<Input>: ")))
        (if (= input "Scale")
          (progn
            (if (numberp (setq scale (getdist (strcat "\nCurrent scale=" (rtos *ScaleInput*) ": New scale: "))))
              (setq *ScaleInput* scale)
            )
            (setq input nil)
          )
        )
      )
      (if (numberp input)
        (* input *ScaleInput*)
      )
    )[/code]

    ScaleInput.lsp

  • ... Of course you have to enter the keyboard shortcut BEFORE entering the numerical value and then finish with enter or space. So ScaleInput minimizes extra keystrokes but does not do away with them.
  • Hi John,

    depending what you are trying to do, you could draw the complete object first and then apply the scaling afterwards, such as an component detailed in inches that you want to draw in a metric drawing.

    Regards,

    Jason Bourhill

    CAD Concepts


  •  Roy,

    That helps!  I'm very close now.  One more question -- how do I assign a function key to something that is not already listed in the "keyboard" tab in the customize dialog box.  I can assign this to something already there (like the Page Down key) but I don't see how to add a key that is not listed (such as the Right Arrow key) and then assign to that.

    Thanks.
  •  Roy,

    That helps!  I'm very close now.  One more question -- how do I assign a function key to something that is not already listed in the "keyboard" tab in the customize dialog box.  I can assign this to something already there (like the Page Down key) but I don't see how to add a key that is not listed (such as the Right Arrow key) and then assign to that.

    Thanks.

    have a look autohotkey  @ www.autohotkey.com

    it's the coolest thing since sliced bread!  a must have tool for the cad user.

     

  • @ John:
    You just append a shortcut, select a command and finish by typing your key combination. See attached image. You may want to check if your key combination is not already being used.

    @ Daniel:
    You are right, you could use www.autohotkey.com (or www.autoitscript.com) to accomplish this.
    Love your new avatar!
    imageAdd_Keyboard_Shortcut.png
  • Thanks for all your help!  That worked great.


This discussion has been closed.