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

Need lisp routine to stretch a set distance.

6 REPLIES 6
Reply
Message 1 of 7
ScottMason
1655 Views, 6 Replies

Need lisp routine to stretch a set distance.

I am in search of a LISP routine to strech a selection a pre-set distance. I have many different objects i need to stretch at different places and directions but i often am stretching them the same distance. I would like to input the distance once and use the selection window and click in the direction to stretch similar to the native offset command. i would like the command to remember the last input value when i run it again, and allow continuous operation, (multiple cycles before exiting). 

6 REPLIES 6
Message 2 of 7
marko_ribar
in reply to: ScottMason

Tricky request, but try this... Maybe you'll get used to it... Also worth of trying is MSTRETCH command...

 

(defun c:stretchdist ( / cmd d ss p1 p2 v )

  (defun *error* ( msg )
    (if cmd (setvar 'cmdecho cmd))
    (if msg (prompt msg))
    (princ)
  )

  (setq cmd (getvar 'cmdecho))
  (setvar 'cmdecho 1)
  (initget 7)
  (setq d (getdist "\nPick or specify distance for stretching : "))
  (while
    (setq ss (ssget "_:L"))
    (setq p1 (getpoint "\nPick or specify first point (base point) : "))
    (setq p2 (getpoint p1 "\nPick or specify second point : "))
    (setq v (mapcar '* (mapcar '/ (mapcar '- p2 p1) (list (distance p1 p2) (distance p1 p2) (distance p1 p2))) (list d d d)))
    (command "_.STRETCH" ss "" v "")
  )
  (terpri)
  (*error* nil)
)

 HTH, M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 3 of 7
3wood
in reply to: ScottMason

You can use command MSTRETCH in Express Tools.

Message 4 of 7
ScottMason
in reply to: 3wood

mstretch doesnt account for multiple directions, and doesnt keep the measurement that was stretched from the previous run of the command. mstretch gives multiple selection windows but only one distance and direction. 

Message 5 of 7
Kent1Cooper
in reply to: marko_ribar

Interestingly, marko_ribar's routine works in AutoCAD 2015, but at my other location back on ol' 2004, it doesn't, because Stretch won't accept a mere selection set of entity names, but needs the crossing/polygon selection approach within the command.  But even in newer versions where it works with pre-selection, I would be inclined to do part of it differently:

....

  (while
    (setq ss (ssget "_:L"))
    (setq ang (getangle "\nDirection to Stretch [numerical angle or via two points]: "))
    (command "_.STRETCH" ss "" (polar '(0 0 0) ang d) "")
  ); while

....

 

That way, the User has the option to designate the direction to Stretch in by either picking two points on-screen or typing in an angle [in whatever the current angle format is, or sometimes in more than one format -- for instance, with degrees/minutes/seconds as my setting, I can type either degrees/minutes/seconds or decimal degrees].

Kent Cooper, AIA
Message 6 of 7
marko_ribar
in reply to: Kent1Cooper

Sorry, Kent, I am looking it 3D - proffesional bugger...

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 7 of 7
Kent1Cooper
in reply to: marko_ribar


@marko_ribar wrote:

Sorry, Kent, I am looking it 3D - proffesional bugger...


Oh, I hadn't thought about that.  If multiple directions includes Z as well as XY directions, then my suggestion won't work, because (getangle) won't deal with the Z component.

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