Jump to content

Recommended Posts

Posted

hello everyone! I am new to autocad, as in a newbie!

I got this job, and they hired me because I know some stuffs on computer. 

anyway... on my searching for ideas on how am i going to simplify the lengthen command on autocad, i stumbled on autolisp. 

is there an easier way to lengthen a line?

its stupid i know. but i do t know anything about autolisp and im still learning around autocad.

 

as of the moment, i am using lengthen command and then dynamic.

 if its possible to just type a command and then select a line and then enter how much you want the line to be extended.

 

but i dont want to displace the line, i just want it to be longer from the startXYZ and endXYZ(end to end). but the position angle and all will be the same.

of it is hard, can someone point me to where and how can i do it?

 thank you in advance!

Posted

Hi there...

 

I didn't want to pronounce your name, so I just wrote "there..." 

 

I'm actually quite impressed that you are able to land yourself a job considering your skill level in AutoCAD is very new.

 

Let's consider a few things:

 

1. Which way do you want the line to extend?

2. Is it only lines? Or are arcs also considered?

3. Are the lines to be extended by a numerical value, or until it reaches a certain point?

 

If you're gonna extend a group of lines until it reaches a certain point (for example, so that they all share the same y-value), you can draw a temporary line (a vertical line), then use the EXTEND command. For this, you don't really need to use LISP. I normally use LISP to automate multiple repetitive tasks.

 

Thanks,

Jonathan Handojo

Posted (edited)
4 hours ago, Jonathan Handojo said:

Hi there...

 

I didn't want to pronounce your name, so I just wrote "there..." 

 

I'm actually quite impressed that you are able to land yourself a job considering your skill level in AutoCAD is very new.

 

Let's consider a few things:

 

1. Which way do you want the line to extend?

2. Is it only lines? Or are arcs also considered?

3. Are the lines to be extended by a numerical value, or until it reaches a certain point?

 

If you're gonna extend a group of lines until it reaches a certain point (for example, so that they all share the same y-value), you can draw a temporary line (a vertical line), then use the EXTEND command. For this, you don't really need to use LISP. I normally use LISP to automate multiple repetitive tasks.

 

Thanks,

Jonathan Handojo

 

hello sir!

ikr?! how awesome is that? i get to learn a new thing and at the same time earn money from it! to answer your questions:

 

i want the line to be extended on both sides.

no, not only line but also polylines to be selected.(though, lines are just fine with me, i just discovered you can explode a polyline do make it into line)

yes, a numerical value is to be typed

 

 

so if i type a value(say 5), i want the selected line to be extended 5 on both ways.

its kind of repetitive because i need to check the lines by eye... because not all are to be extended. also every layer i need to do this, and sometimes im overwhelmed, and typing lengthen and dynamic becomes too long! so i googled if is there a better way to do it.

i havent tried the extend command. 

and the lines arent just vertical or horizontal too.

Edited by Tickles!
Posted (edited)

Try this, Lines and open LWPolylines on unlocked layer only. It will select closed lwpolylines, but won't process them. The extend distance is a real.

 

It uses a selection set so you can make a multiple choice.

 

 

(vl-load-com)

(defun c:extendby (/ *error* sv_lst sv_vals e_dst ss cnt ent elst ang spt ept v_lst)

  (defun *error* ( msg )
    (mapcar 'setvar sv_lst sv_vals)
    (if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nAn Error : " msg " occurred.")))
    (princ)
  );_end_*error*_defun

  ;;system/current drawing variables
  (setq sv_lst (list 'cmdecho 'osmode)
        sv_vals (mapcar 'getvar sv_lst)
  );end_setq
  
  (mapcar 'setvar sv_lst '(0 0))
  
  (initget 7)
  (setq e_dst (getreal "\nEnter Extend Distance : "))

  (prompt "\nSelect Lines to Extend")
  (setq ss (ssget ":L" '((0 . "LINE,LWPOLYLINE"))))
  
  (cond (ss
          (repeat (setq cnt (sslength ss))
            (setq ent (ssname ss (setq cnt (1- cnt))))
            (cond ( (= (cdr (assoc 0 (setq elst (entget ent)))) "LINE")
                    (setq ang (angle '(0. 0. 0.) (vlax-curve-getfirstderiv ent 0))
                          spt (polar (vlax-curve-getstartpoint ent) (+ ang pi) e_dst)
                          ept (polar (vlax-curve-getendpoint ent) ang e_dst)
                          elst (subst (cons 10 spt) (assoc 10 elst) elst)
                          elst (subst (cons 11 ept) (assoc 11 elst) elst)
                    );end_setq
                    (entmod elst)
                  )
                  ( (and (= (cdr (assoc 0 elst)) "LWPOLYLINE") (or (= (cdr (assoc 70 elst)) 0) (= (cdr (assoc 70 elst)) 128)))
                    (setq v_lst (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) elst))
                          ang (angle '(0. 0. 0.) (vlax-curve-getfirstderiv ent (- (vlax-curve-getendparam ent) 0.5)))
                          ept (reverse (cdr (reverse (polar (vlax-curve-getendpoint ent) ang e_dst))))
                          v_lst (reverse (cons ept (cdr (reverse v_lst))))
                          ang (angle '(0. 0. 0.) (vlax-curve-getfirstderiv ent 0.5))
                          spt (reverse (cdr (reverse (polar (vlax-curve-getstartpoint ent) (+ ang pi) e_dst))))
                          v_lst (cons spt (cdr v_lst))
                    );end_setq
                    (vlax-put (vlax-ename->vla-object ent) 'coordinates (apply 'append v_lst))
                  )
            );end_cond
          );end_repeat
        )
        (t (alert "NOTHING Selected"))
  );end_cond

  (mapcar 'setvar sv_lst sv_vals)
  (princ)
);end_defun

 

Edited by dlanorh
Posted

Well then, you need to know what distinguishes the lines that are to be extended and those that are not? Dlanorh points those out by ruling out lines on locked layers. What do you think?

Posted

Jonathan

 

(setq ss (ssget ":L" '((0 . "LINE,LWPOLYLINE"))))

 

Rules out those to not be extended. You still have to pick the ones to be changed.

Posted (edited)
On 3/14/2020 at 9:24 AM, Tickles! said:

is there an easier way to lengthen a line?

 

as of the moment, i am using lengthen command and then dynamic.

 

 

---- FOR LINES ----

 

- CUI

- Double Click Actions

- Line

- Type this macro: ^C^C(progn (command "_LENGTHEN" "_DY" (cadr (grread T))) (princ))

 

Edited by GP_
Posted (edited)

I can't insert a gif  😦

Edited by GP_
Posted
On 3/16/2020 at 1:27 PM, GP_ said:

I can't insert a gif  😦

 

This is a test.

giphy.gif

 

Seems to be working. I grabbed the link off Giphy.com and pasted it here. How are you trying to insert your gif?

Posted

I use Sharex and can view GIF's etc I make and have emailed them to people but I can not upload my gif's to here have asked David a couple of times, not sure if software I am using.

 

Interesting just uploaded a gif about stockmarket and it worked so it must be my shareX that is the problem.

giphy[1].gif

Posted
On ‎3‎/‎16‎/‎2020 at 2:27 PM, GP_ said:

I can't insert a gif  😦

Do you get any messages? Hard to say without knowing what you have tried and what procedures already used.

Posted
14 hours ago, Cad64 said:

Seems to be working. I grabbed the link off Giphy.com and pasted it here. How are you trying to insert your gif?

 

1 hour ago, SLW210 said:

Do you get any messages? Hard to say without knowing what you have tried and what procedures already used.

 

Gif created with CAMTASIA 2019,

Other gifs work 🙄
 
626.jpg.fee5e1baaeb7d7aa78c32efa0b67e424.jpg
Posted

I think in CAMTASIA you need to share to Screencast first and/or Giphy should work.

Posted

Here's a version that uses the scale command to lengthen selected lines by a specified amount. It works in 2D or 3D. 

(defun c:longer	(/)
; lengthens selected lines by specifed distance
(setvar "osmode" 0)
  (setq i 0)
  (if (setq ss (ssget '((0 . "LINE"))))
    (progn
      (setq dx (getreal "\nEnter lenght for extension to both ends: "))
      (while (setq en (ssname ss i))
	(setq ed    (entget en)
	      b1    (cdr (assoc 10 ed))
	      b2    (cdr (assoc 11 ed))
	      d	    (distance b1 b2)
	      s	    (/ (+ d (* 2 dx)) d)
	      midpt (mapcar '/ (mapcar '+ b1 b2) '(2. 2. 2.))
	)
	(command "scale" en "" midpt s)
	(setq i (1+ i))
      )					; end while
    )
  )					; end if
  (princ)
)

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...