OFFSET command with metric input but imperial output

OFFSET command with metric input but imperial output

akitchensZEZPR
Enthusiast Enthusiast
1,410 Views
8 Replies
Message 1 of 9

OFFSET command with metric input but imperial output

akitchensZEZPR
Enthusiast
Enthusiast

All of our drawings are set up in Imperial units. However, sometimes we receive asbuilt drawings with metric measurements.

 

I'm trying to figure out how to create a new OFFSET command so that I can enter an offset distance in metric units. The command will convert that distance into imperial units so that the resulting offset distance is correct for an imperial drawing.

 

I thought I could find the raw lisp code for the default OFFSET command, so that I can do the conversion on the input number, but all I can find is this:

 

(command "OFFSET")

 

This doesn't work because I need to dig into this command so that I can make the calculation after the offset distance is entered.

 

So for example, if I need to offset a line by 15 meters, I would run my new command and enter "15". At that point, the command will multiply that number by 3.28084, then finish the command by offsetting the line 49.2126 FEET.  I'm pretty sure this would be relatively easy but I need the raw code for OFFSET to give me something to work with.

0 Likes
1,411 Views
8 Replies
Replies (8)
Message 2 of 9

akitchensZEZPR
Enthusiast
Enthusiast

I figured it out! Here's the command if anybody wants to use it.

 

(defun c:OM()
    (setq MDIST
        (getdist
            "\nENTER OFFSET DISTANCE IN METRIC UNITS : "
        )
    )

    (setq IDIST (* MDIST 3.28084)
    )

    (command "OFFSET" IDIST pause pause "")
)

0 Likes
Message 3 of 9

Sea-Haven
Mentor
Mentor

So if mm or m ? 300 / 25.4.

 

You can use VLA-offset which supports +- value for left right.

 

I would wrapper the offset dist in a while so can keep going say press Enter or type 0.

 

 

 

 

0 Likes
Message 4 of 9

pbejse
Mentor
Mentor
(defun c:OM ()
      
(initget 6 "Through")
(if (setq MDIST
               (getdist
                     (strcat
                           "\nENTER OFFSET DISTANCE IN METRIC UNITS : [Through] <"
                           (if (< (getvar "OFFSETDIST") 0)
                                 "Through"
                                 (rtos (getvar "OFFSETDIST"))
                                 )
                           ">: "
                           )
                   )
          )
      (if (= MDIST "Through")
            (setvar "OFFSETDIST" -1)
            (setvar "OFFSETDIST" MDIST)
            )
      (setq MDIST (getvar "OFFSETDIST"))
      )

    (setq IDIST (* MDIST 3.28084))
    (command "OFFSET" IDIST )
      (while (eq (logand 1 (getvar 'CMDACTIVE)) 1) (command pause))
    (setvar "OFFSETDIST" MDIST)  
)
0 Likes
Message 5 of 9

ВeekeeCZ
Consultant
Consultant

My version, with considering options:

1) with "" - it's quicker, but while the Erase/Layer options are honored, their setting is only possible in the original command. 

1) without "" (remove them) - a bit slower, all options are available, but distance is precalculated under <enter> which you need to confirm by an extra step.

 

(defun c:OffsetMetric ( / off)

  (setq off (getvar 'offsetdist))
  
  (or *offsetdistmetric*
      (setq *offsetdistmetric* (abs (/ off 3.28084))))
  
  (if (setq *offsetdistmetric* (cond ((getreal (strcat "\nSpecify offset distance in meters <" (rtos *offsetdistmetric*) ">: ")))
				     (*offsetdistmetric*)))
    (progn
      (setvar 'offsetdist (* *offsetdistmetric* 3.28084))
      (command-s "_.offset" "")))  ; try to remove them.

  (setvar 'offsetdist off)
  (princ)
  )

 

0 Likes
Message 6 of 9

Kent1Cooper
Consultant
Consultant

Will something as simple as this do?

 

(defun C:OMF (); = Offset Meters input Feet usage
  (command "_.offset" (cvunit (getreal "\nOffset distance in meters: ") "meter" "foot"))
)

 

It just leaves you in the regular command, with multiple Offsets and the Undo/Exit options available.

 

EDIT:

The snazzier version, which offers your prior value [if any] or the current Offset distance setting [if not "Through"], in meters, as default, and uses the regular setting without the need for a dedicated-to-this-command variable:

 

(defun C:OMF (/ ofd); = Offset Meters input Feet usage
  (setq ofd (getvar 'offsetdist))
  (initget (if (> ofd 0) 6 7)); no zero, no negative, no Enter if "Through"
  (command "_.offset"
    (cvunit
      (cond
        ( (getreal
            (strcat
              "\nOffset distance in meters"
              (if (> ofd 0) (strcat " <" (rtos (cvunit ofd "foot" "meter") 2) ">") "")
              ": "
            ); strcat
          ); getreal
        ); User-input condition
        ((cvunit ofd "foot" "meter")); on Enter when allowed
      ); cond
      "meter" "foot"
    ); cvunit
  ); command
); defun

 

It uses whatever your current Units precision is for the decimal places in showing the default -- if you want that different, add a precision argument to the (rtos) function, for example:

 

.... (rtos (cvunit ofd "foot" "meter") 2 3) ....

 

It seems pointless for the purpose to allow "Through" as an option, so this does not account for that possibility, except to require a numerical input if that's current [no Enter to accept the current setting].

Kent Cooper, AIA
0 Likes
Message 7 of 9

DanielPaulinFerraro
Community Visitor
Community Visitor

Hello @akitchensZEZPR ! This command is exactly what i am looking for! however i have no experience with code or lisp. 

Would you mind sharing the .lsp file or explaining how to use that code? 

 

It would really help me. Thanks! 

 

0 Likes
Message 8 of 9

akitchensZEZPR
Enthusiast
Enthusiast

Here you go. Just import this file into your drawing by dragging it into model space. To run it type OM (offset metric) and it will ask you to enter the offset distance in metric units. The resulting line will be offset by the correct distance in your imperial drawing. Hope this helps!

0 Likes
Message 9 of 9

DanielPaulinFerraro
Community Visitor
Community Visitor

It worked like a charm! I cannot THANK YOU enough!