Jump to content

delta lengthen


mbdoyle

Recommended Posts

Hi guys, as I'm pretty new to autolisp I was wondering if anybody could quickly show me a way to do the following:

 

run a lisp or macro that would allow me to pick a bunch of lines, then enter a distance and lengthen these lines ON BOTH SIDES by that distance.

 

I'm guessing this wouldn't be a challenge for a lot of you as I have seen some pretty impressive code written in these forums

 

thanks

matt :)

Link to comment
Share on other sites

Maybe something like this...

(defun c:TEst (/ #SS #Dist)
 (vl-load-com)
 (and (setq #SS (ssget "_:L" '((0 . "LINE,LWPOLYLINE"))))
      (setq #Dist (getdist "\nSpecify length: "))
      (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex #SS)))
        (vl-cmdf "_.lengthen"
                 "_delta"
                 #Dist
                 (list x (vlax-curve-getendpoint x))
                 (list x (vlax-curve-getstartpoint x))
                 ""
        ) ;_ vl-cmdf
      ) ;_ foreach
 ) ;_ and
 (princ)
) ;_ defun

Link to comment
Share on other sites

That works perfectly, thank you very much alanjt!:)

 

matt

 

No problem. I'm not one to give you the fish, but for such a simple question, it's just better to start with the routine. Be sure to go though it so you can understand it; I don't mind answering questions.

Link to comment
Share on other sites

So I've been looking at the code for this lisp and I'm having some trouble with the vlisp @ the following lines:

 

 

1: (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex #SS))) :?

 

2: (list x (vlax-curve-getendpoint x))

 

3: (list x (vlax-curve-getstartpoint x))

 

Maybe I could get some clarification? Especially with that first line. Thank you very much.

 

Matt

Link to comment
Share on other sites

For Question 1:

  • ssnamex returns how each entity in the selection set was created. In this list, all entities are located within sublists.
  • mapcar goes through a given list and performs a specific function on each item and returning a newly processed list.
  • cadr extracts the second item in a list. (mapcar 'cadr #List) will extract the second item in each sublist within #List
  • vl-remove-if 'listp will remove all objects from the newly process list that are of the type LST (a list).

By performing this, I can create a list of just the extracted enames (entities) and from there I can step through the list and perform whatever I need. You can also step through the selection set with while or repeat and ssname. It's even a little faster but in this moment, I felt like going with the above method (more than one way to skin a cat).

Link to comment
Share on other sites

Question 2 & 3:

  • Lengthen and many other similar functions, when selecting an object, will need/use a point, in addition to the ename (entity) to properly know where on the entity the user selected
  • What I did was extract the end and start point of the selected line and combine it with the ename to feed to lenghten. This ensured me that I could extend both lines.

Similarly, feed an ename to a function and many times you will receive a different result, if a point isn't provided - this does not apply to all command functions.

 

For instance:

;;; without point
(defun c:Test (/ e)
 (and (setq e (entsel "\nSelect line: "))
      (command "_.lengthen" "_delta" 10. (car e) "")))

;;; with point
(defun c:Test (/ e)
 (and (setq e (entsel "\nSelect line: "))
      (command "_.lengthen" "_delta" 10. e "")))

 

You'll notice that, with the first function (without point), you may sometimes extend at other end of where you selected the line.

Link to comment
Share on other sites

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...