Break a line with a preset specified distance

Break a line with a preset specified distance

They_Call_Me_Jake
Advocate Advocate
1,394 Views
3 Replies
Message 1 of 4

Break a line with a preset specified distance

They_Call_Me_Jake
Advocate
Advocate

I am new to AutoLISP so please bare with me. I have to create a .001" break in either the middle of a line or at a specified pick point. can anyone help me make a lsp function to do this. I have tried to write it myself and I get to the point of having the function pick the middle of the line but I can't seem to get it to put the .001 gap in....it breaks the line but without the .001 gap. I need this to work horizontal, vertical and diagonal lines

0 Likes
1,395 Views
3 Replies
Replies (3)
Message 2 of 4

jdiala
Advocate
Advocate

Break at midpoint

 

(defun C:test (/ tol b e p1 p2 a d l)
  (if
    (setq tol 0.001
          b (/ tol 2.0)
          e (car (entsel "\nPick a line to break at mid point: "))
          p1 (cdr (assoc 10 (entget e)))
          p2 (cdr (assoc 11 (entget e)))
          a (angle p1 p2)
          d (- (/ (distance p1 p2) 2) b)
          l (cdr (assoc 8 (entget e)))
    )
    (progn
      (entmake (list (cons 0 "LINE") (cons 8 l) (cons 10 p1) (cons 11 (polar p1 a d))))
      (entmake (list (cons 0 "LINE") (cons 8 l) (cons 10 (polar p1  a (+ d tol))) (cons 11 p2)))
      (entdel e)
    )
  )
)  

Break at specified distance

 

(defun C:test2 (/ tol b e p p1 p2 l)
  (if
    (setq tol 0.001
          b (/ tol 2.0)
          e (entsel "\nPick a line to break: ") 
          p (vlax-curve-getClosestpointTo (vlax-ename->vla-object (car e)) (cadr e) nil)
          p1 (cdr (assoc 10 (entget (car e))))
          p2 (cdr (assoc 11 (entget (car e))))
          l (cdr (assoc 8 (entget (car e))))
    )
    (progn
      (entmake (list (cons 0 "LINE") (cons 8 l) (cons 10 (polar p (angle p p1) b)) (cons 11 p1)))
      (entmake (list (cons 0 "LINE") (cons 8 l) (cons 10 (polar p (angle p p2) b)) (cons 11 p2)))
      (entdel (car e))
    )
  )
)
0 Likes
Message 3 of 4

jdiala
Advocate
Advocate
forgot the (vl-load-com)
0 Likes
Message 4 of 4

Kent1Cooper
Consultant
Consultant

@mrsmithTYTMZ wrote:

I am new to AutoLISP so please bare with me. I have to create a .001" break in either the middle of a line or at a specified pick point. ....


[Do I have to take my clothes off?  (The word you want is "bear with me.")]

 

How about some that are not restricted to Line objects?  The following Gap001M [for a Gap of .001 at the Midpoint] and Gap001S [for the gap at the Selection point] will do it to Lines, Arcs, Circles, Polylines [any variety, at line or arc segments], Ellipses, Splines, and [in only the at-the-selection-point one] Xlines and Rays.

 

It could still use the usual enhancements [error handler, Undo begin/end wrapping, etc.], but see what you think.

 

If you use Gap001M on a Polyline, it puts the gap in the middle of its overall length, but it could be altered to do it at the middle of the segment in which you pick it, if desired.  It could also be altered to ask for a Gap size, including a default, so you wouldn't need separate ones for different sizes.  And it could be altered to operate repeatedly as long as continue to pick objects, and/or for Gap001M, to let you select as many objects as you want all at once.

 

(vl-load-com)

(defun GetForGap (subpr / edata etype)
  (and
    (setq esel (entsel (strcat "\nSelect object to make gap at " subpr "point: ")))
    (setq ent (car esel) edata (entget ent) etype (cdr (assoc 0 edata)))
    (wcmatch etype "*LINE,ARC,CIRCLE,ELLIPSE,RAY")
    (/= etype "MLINE"); accepted by above, but not by (vlax-curve...)
    (if (= subpr "mid") (not (wcmatch etype "XLINE,RAY")) T)
      ; allow only in Gap001S [can't calculate midpoint]
    (= (logand (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 edata))))) 4) 0); unlocked
  ); and
); defun -- GetForGap

(defun Gap001 (loc / osm cir)
  (setq osm (getvar 'osmode))
  (setvar 'osmode 0)
  (command
    "_.circle" loc 0.0005
    "_.zoom" (polar loc 0 0.001) (polar loc pi 0.001)
    "_.regen" ; [because Trim pick at 'loc' can miss if curve is segmented]
    "_.trim" (setq cir (entlast)) "" loc ""
    "_.erase" cir ""
    "_.zoom" "_previous"
  ); command
  (setvar 'osmode osm)
); defun -- Gap001

(defun C:Gap001M (/ esel ent)
  (if (GetForGap "mid")
    (Gap001 ; then
      (vlax-curve-getPointAtDist ent
        (/ (vlax-curve-getDistAtParam ent (vlax-curve-getEndParam ent)) 2)
      ); ...getPoint...
    ); Gap001
    (prompt "\nNothing selected, not a viable object, or on a locked Layer."); else
  ); if
  (princ)
); defun -- C:Gap001M

(defun C:Gap001S (/ esel ent)
  (if (GetForGap "selection ")
    (Gap001 (osnap (cadr esel) "_nea")); then
    (prompt "\nNothing selected, not a viable object, or on a locked Layer."); else
  ); if
  (princ)
); defun -- C:Gap001S
Kent Cooper, AIA
0 Likes