Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Offset line on equal distances on both sides and join the offset lines

15 REPLIES 15
SOLVED
Reply
Message 1 of 16
robert06
3338 Views, 15 Replies

Offset line on equal distances on both sides and join the offset lines

How to describe multiple selection sets in one script? This one does not work.. how to get the first offset line into second selection set (xxy) to join it with the other one later?

(defun c:offjoin ()
    (setq xxx (entsel))
    (command "offset" pause (car xxx) "99999999999,99999999999" "e")
    (setq xxy (entlast))
    (command "offset" "" (car xxx) "-99999999999,-99999999999" "e")
    (setvar "peditaccept" 1)
    (command "pedit" "m" "l" (car xxy) "" "j" "j" "b" "4" "")
    (princ)
)

thank you!

15 REPLIES 15
Message 2 of 16
hmsilva
in reply to: robert06

Change
(command "pedit" "m" "l" (car xxy) "" "j" "j" "b" "4" "")
to
(command "pedit" "m" "l" xxy "" "j" "j" "b" "4" "")

HTH
Henrique

EESignature

Message 3 of 16
robert06
in reply to: hmsilva

thank you, another bit of lisp is learned Smiley Happy

Message 4 of 16
hmsilva
in reply to: robert06

You're welcome, Robert

and can change also
(command "offset" pause (car xxx) "99999999999,99999999999" "e")
to
(command "offset" (getdist) (car xxx) "99999999999,99999999999" "e")

HTH
Henrique

EESignature

Message 5 of 16
robert06
in reply to: hmsilva

Thanks, but using here 'getdist' user input instead of 'pause' needs probably some additional rewriting of the code, did not work.

Message 6 of 16
hmsilva
in reply to: robert06

Should work

(defun c:offjoin ( / xxx xxy)
    (setq xxx (entsel))
    (command "offset" (getdist) (car xxx) "99999999999,99999999999" "e")
    (setq xxy (entlast))
    (command "offset" "" (car xxx) "-99999999999,-99999999999" "e")
    (setvar "peditaccept" 1)
    (command "pedit" "m" "l" xxy "" "j" "j" "b" "4" "")
    (princ)
)

HTH

Henrique

EESignature

Message 7 of 16
robert06
in reply to: hmsilva

With 'getdist' it did not work, if offset distance is not changed (when enter is pressed to accept current offset distance).

Message 8 of 16
hmsilva
in reply to: robert06


@robert06 wrote:

With 'getdist' it did not work, if offset distance is not changed (when enter is pressed to accept current offset distance).


My bad!

Something like this perhaps. Using your method

(defun c:demo ( / a b d)
  (if (setq d (getdist (strcat "\nSpecify offset distance, <" (rtos (getvar 'OFFSETDIST) 2 2) ">:")))
    (setvar 'OFFSETDIST d)
    (setq d (getvar 'OFFSETDIST))
  );; if
  (if (setq a (entsel "\nSelect object to offset, <Exit>:"))
    (progn
      (command "offset" d (car a) "99999999999,99999999999" "e")
      (setq b (entlast))
      (command "offset" d (car a) "-99999999999,-99999999999" "e")
      (setvar "peditaccept" 1)
      (command "pedit" "m" "l" b "" "j" "j" "b" "4" "")
    );; progn
  );; if
  (princ)
);; demo

 

Or

 

(defun c:demo1 (/ a b d o)
  (vl-load-com)
  (if (setq d (getdist (strcat "\nSpecify offset distance, <" (rtos (getvar 'OFFSETDIST) 2 2) ">:")))
    (setvar 'OFFSETDIST d)
    (setq d (getvar 'OFFSETDIST))
  );; if
  (if (setq a (car (entsel "\nSelect object to offset, <Exit>:")))
    (progn
      (setq o (vlax-ename->vla-object a))
      (vla-offset o d)
      (setq b (entlast))
      (vla-offset o (- d))
      (setvar "peditaccept" 1)
      (command "pedit" "m" "l" b "" "j" "j" "b" "4" "")
    );; progn
  );; if
  (princ)
);; demo1

 

HTH

Henrique

EESignature

Message 9 of 16
Kent1Cooper
in reply to: robert06

Better, I think, to not use the plus-or-minus gazillions points for Offset which-side designators -- there are circumstances in which they would both be on the same side of the selected object, e.g. a Line running at 45 degrees [or 225].  Here's something I edited quickly from a routine I have [which Offsets to both sides without the joining part] to add the joining -- OffsetBothSidesJoin.lsp with its OBSJ command.

 

It uses (vla-offset) with positive and negative values, to guarantee that the thing gets Offset to both sides.  And it uses a fuzz factor for PEDIT/Joining that's a multiple of the Offset distance, rather than a fixed value of 4, so you can use any size distance and it will always be able to Join things.

 

It gets the distance first, not within an Offset command, so you can set that and go around picking a bunch of things [as many as you want in one running of the command] to do it to without needing to answer that prompt for each one.  It remembers that distance [separately from regular Offset's] and offers it as the default on subsequent use.  It works on any Offsettable entity type, though it could use some control features added, to prevent selection of non-Offsettable entities, and to keep it from trying to PEDIT/Join the entity types that can't be [maybe later].  If you pick a closed object, it will still Offset it to both sides, but won't try to Join the results.

 

It could also use some further refinements I have used in more recent routines [e.g. Enter/space to end it, rather than requiring Escape].  And it will have trouble with certain peculiar situations, like self-intersecting Polylines, or Arcs if the offset distance is greater than the radius.  But if you pick any Offsettable and PEDITable entity using an appropriate distance, it seems to work, in limited testing.

Kent Cooper, AIA
Message 10 of 16
robert06
in reply to: hmsilva

Great Henrique, i like the VL version (demo 1) of your two proposals  better, as Kent Kooper also stated, offset side should not be described via absolute coords, like i did.

 

Thank you!

Message 11 of 16
robert06
in reply to: Kent1Cooper

Thank you, Kent!

 

Message 12 of 16
hmsilva
in reply to: robert06


@robert06 wrote:

Great Henrique, i like the VL version (demo 1) of your two proposals  better, as Kent Kooper also stated, offset side should not be described via absolute coords, like i did.

 

Thank you!


You're welcome, Robert

 

Henrique

EESignature

Message 13 of 16
Anonymous
in reply to: Kent1Cooper

Thanks for the lisp, I find it very useful. But I wish to tweak some of the codes (hope Kent don't mind) so that it allows me to select multiple entities and offset and join the selection at once. Can someone help me ?
Message 14 of 16
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:
....I wish to tweak some of the codes ... so that it allows me to select multiple entities and offset and join the selection at once. Can someone help me ?

Try replacing this part:

 

  (while T
    (if
      (setq obj
        (vlax-ename->vla-object
          (car (entsel "\nSelect object to Offset to Both Sides [Esc to exit]: "))
        ); end vlax-...
      ); end setq
      (progn

        (vla-offset obj *obsjdist)
        (setq ent1 (entlast))
        (vla-offset obj (- *obsjdist))
        (if (not (vlax-curve-isClosed obj)); e.g. Line, Arc, open Polyline
          (command "_.pedit" "_m" ent1 (entlast) "" "_j" "_j" "_b" (* *obsjdist 2.5) "")
        ); if
      ); end progn
    ); end if
  ); end while

 

with this [untested]:

 

  (if

    (setq ss (ssget ":L"))

    (repeat (setq n (sslength ss)); then

      (setq obj (vlax-ename->vla-object (ssname ss (setq n (1- n)))))
      (vla-offset obj *obsjdist)
      (setq ent1 (entlast))
      (vla-offset obj (- *obsjdist))
      (if (not (vlax-curve-isClosed obj)); e.g. Line, Arc, open Polyline
        (command "_.pedit" "_m" ent1 (entlast) "" "_j" "_j" "_b" (* *obsjdist 2.5) "")
      ); if
    ); end repeat
  ); end if

 

It could add filtering for offsettable object types in the selection, as well as some of the other "it could use" things already mentioned.

Kent Cooper, AIA
Message 15 of 16
Anonymous
in reply to: Kent1Cooper

Thanks Kent.
Message 16 of 16
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:
Thanks Kent.

You're welcome, and welcome to these Forums!  I guess it actually must have worked [always a risk when untested]....  And I'm glad to see people finding things from past threads here that they can use.

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost