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

Modify LISP to add line offsets

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
2750 Views, 5 Replies

Modify LISP to add line offsets

The following code is modified slightly from a LISP written by hmsilva. It does the exact same thing except it uses a different block, and then offsets the selected polyline 1' to either side onto the appropriate layer. It works, but only when I am zoomed in on the polyline when I pick it. If I am zoomed out, then it offsets 1' to one side, but then it seems to offset the new line back 1' to be on top of the other line. In the attached .dwg file, you can see two examples. The top line was picked when zoomed out, and the bottom line was picked when zoomed into one end of the line. The code below is attached in a LISP file as well. Just wondering if there is something I can do to make it offset properly every time.

 

Thanks!

 

(defun c:KRAIL2
       (/ ANG CUR_LAY DIST1 ENDPT INSPT LEN PATH PICKPT SEL STARTPT)
  (vl-load-com)
;; user-input select path and for KRAIL spacing
  (if (and (setq sel (entsel "\nSelect a LwPolyline to Insert KRail: "))
	   (setq dist1 "20")
      );; and
;; if the test expressions are true
;; start the insertion process,
;; if not, exits the code...
    (progn
      (setvar "CMDECHO" 0)
;remember current layer and set the current layer to CONE
      (setq cur_lay (getvar "clayer"))
      (setvar "clayer" "KRAIL")
;; sets the variable pickpt with the second list element from the entsel function
      (setq pickpt  (cadr sel)
;; sets the variable path with the first list element from the entsel function
	    path    (car sel)
;; find the polyline length
	    len	    (vlax-curve-getDistAtParam path (vlax-curve-getEndParam path))
;; find the strat point
	    startpt (vlax-curve-getStartPoint path)
;; find the end point
	    endpt   (vlax-curve-getEndPoint path)
      );; setq
;; test if the pick point is closer from the start
      (if (< (distance startpt pickpt) (distance endpt pickpt))
;; if close to start, stores the startpt as inspt and the insertion angle
	(setq inspt startpt
	      ang   (* (/ (angle inspt (vlax-curve-getPointAtDist path 0.001)) pi) 180))
;; if close to end, stores the endpt as inspt and the insertion angle
	(setq inspt endpt
	      ang   (* (/ (angle (vlax-curve-getPointAtDist path (- len 0.001)) inspt) pi 180)))
      );; if  
;insert the KTICK block
      (command "._insert" "KTICK" "_none" inspt "1" "1" "_none" ang)
;create arraypath with KTICK and polyline
      (command "._arraypath" (entlast) "" (osnap pickpt "NEA")  "" "" "" "F" dist1 "" "")
;offset polyline to create krail sides
      (command "._OFFSET" "layer" "Current" "1" (osnap pickpt "NEA") "10000000000000,10000000000000" "e")
      (command "._offset" "layer" "current" "1" (osnap pickpt "NEA") "-10000000000000,-10000000000000" "e")
;revert layer back to original current layer
      (setvar "clayer" cur_lay)
    );; progn
  );; if
  (princ)
);; KRAIL2

 

5 REPLIES 5
Message 2 of 6
hmsilva
in reply to: Anonymous

Change the offset command to

 

(command "._OFFSET" "layer" "Current" "1" path "10000000000000,10000000000000" "e")
(command "._offset" "layer" "current" "1" path "-10000000000000,-10000000000000" "e")

 

HTH

Henrique

EESignature

Message 3 of 6
Anonymous
in reply to: Anonymous

Spectacular! Thanks once again for your help!

Message 4 of 6
hmsilva
in reply to: Anonymous

You're welcome,
glad i could help

Henrique

EESignature

Message 5 of 6
Kent1Cooper
in reply to: Anonymous

Another similar approach:

 

(command "._OFFSET" "layer" "Current" "1" path (getvar 'extmax) "e")
(command "._offset" "layer" "current" "1" path (getvar 'extmin) "e")

 

However, with either that or the +/- gazillion,gazillion points, I can imagine configurations in which both of those which-side points would be considered on the same side of the original, for instance something far enough to the upper left or lower right of the middle of things [in the use-the-extents case] or of 0,0 [in the gazillions case] and running generally in a lower-left to upper-right [or the opposite] direction, or any closed or just about any close-enough-to-closed object.  One way to ensure that you always get it to both sides is to use (vla-offset) with positive and negative distance arguments, since it doesn't rely on the positional relationship of a picked point to the shape of the source object [untested -- I'm not on an AutoCADdable computer right now]:

 

(vla-offset (vlax-ename->vla-object path) 1)

(...then you'd have to change the Layer of the result, by any of several means...)

(vla-offset (vlax-ename->vla-object path) -1)

(...likewise change the Layer...)

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

Thanks! You were right, that works for closed objects as well! In the use this was created for, that probably won't be relevant, but it is always good for a function to be as flexible as possible.

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

Post to forums  

Forma Design Contest


Autodesk Design & Make Report