@Kent1Cooper wrote:
.... It will be easy enough to adjust the code to accept Polylines, as well as for the other things you mention -- I just have to get around to it....
Try this out [lightly tested]. Note that you can specify the points without having the Lines/Polylines already there, so in your sample drawing, you don't need those red section boundaries already in place -- this can draw them for you. But when they are already in place, you can choose the Existing-line-selection option.
;|
SplitBetween.lsp, to draw Lines between four selected points, or take
selection of two existing Lines or single-line-segment Polylines, and
draw subdividing Lines between and paralleling them or "splaying"
between them if not parallel. Works in 3D, and in any UCS.
If selecting existing lines, draws subdividing Lines on Layer of second
selected line; if picking four points, draws on current Layer.
Accounts for lines drawn in opposite directions, by reading second line
the other way; if lines are not co-planar, decides that on the basis of 2D
view in current Coordinate System.
Kent Cooper, 20 December 2016
|;
(defun C:SLB ; = Split Lines Between
(/ *error* var ev doc svnames svvals ptA1 ptA2 ptB1
ptB2 linA linB edata parts partno delta1 delta2 inc1 inc2)
(defun *error* (errmsg)
(if (wcmatch errmsg "Function cancelled,quit / exit abort,console break")
(princ (strcat "\nError: " errmsg))
); if
(mapcar 'setvar svnames svvals); reset
(vla-endundomark doc)
(princ)
); defun -- *error*
(defun var (ltr); build variable name
(read (strcat "lin" ltr))
); defun -- var
(defun ev (ltr); get contents of variable name
(eval (var ltr))
); defun -- ev
(vla-startundomark (setq doc (vla-get-activedocument (vlax-get-acad-object))))
(setq ; System Variable saving/resetting without separate variables for each:
svnames '(osmode cmdecho blipmode clayer)
svvals (mapcar 'getvar svnames)
); setq
(mapcar 'setvar svnames '(0 0)); turn off Osnap, command echoing
(initget 1 "Existing")
(setq ptA1 (getpoint "First Line's start point [or select Existing lines]: "))
(if (listp ptA1); if User picked a point
(progn ; then
(initget 1)
(setq ptA2 (getpoint ptA1 "First Line's end point: "))
(initget 1)
(setq ptB1 (getpoint "Second Line's start point: "))
(initget 1)
(setq ptB2 (getpoint ptB1 "Second Line's end point: "))
(command "_.line" ptA1 ptA2 "")
(setq linA (entlast)); [will take points from it later in case in non-World UCS]
(command "_.line" ptB1 ptB2 "")
(setq linB (entlast))
); progn
(progn ; else [if User typed E]
(foreach ind '("A" "B")
(while
(not
(and
(set (var ind) (car (entsel (strcat "\nSelect line " ind ": ")))); linA or linB
(setq edata (entget (ev ind)))
(wcmatch (setq etype (cdr (assoc 0 edata))) "LINE,*POLYLINE")
(if (= etype "LINE") T (= (vlax-curve-getEndParam (ev ind)) 1)); single segment
(cond ; not arc segment
((= (cdr (assoc 100 (reverse edata))) "AcDb3dPolyline"))
((= etype "LWPOLYLINE") (= (cdr (assoc 42 edata)) 0.0))
((= etype "POLYLINE") (= (cdr (assoc 42 (entget (entnext (ev ind))))) 0.0))
(T) ; for Line
); if
); and
); not
(prompt "\nNothing selected, or not a Line or single-line-segment Polyline.")
); while
(redraw (ev ind) 3); highlight
); foreach
(setvar 'clayer (cdr (assoc 8 edata)))
); progn -- else
); if [pick point vs. select Existing lines]
(setq
ptA1 (vlax-curve-getStartPoint linA)
ptA2 (vlax-curve-getEndPoint linA)
ptB1 (vlax-curve-getStartPoint linB)
ptB2 (vlax-curve-getEndPoint linB)
); setq
(if
(inters ; if it would make 'butterfly' lines in 2D view,
(list (car ptA1) (cadr ptA1) 0)
(list (car ptB1) (cadr ptB1) 0)
(list (car ptA2) (cadr ptA2) 0)
(list (car ptB2) (cadr ptB2) 0)
); inters
(setq ptB1 ptB2 ptB2 (vlax-curve-getStartPoint linB)); reverse direction for line B
); if
(initget 7); no Enter, no zero, no negative
(setq
parts (getint "\nDivide intervening space into how many equal segments? ")
partno 1
delta1 (mapcar '- ptB1 ptA1)
delta2 (mapcar '- ptB2 ptA2)
inc1 (mapcar '/ delta1 (list parts parts parts))
inc2 (mapcar '/ delta2 (list parts parts parts))
); setq
(redraw linA 4) (redraw linB 4); un-highlight
(setvar 'blipmode 0)
(setq partno 1)
(while (< partno parts)
(command "_.line"
(trans (mapcar '+ ptA1 (mapcar '* inc1 (list partno partno partno))) 0 1)
(trans (mapcar '+ ptA2 (mapcar '* inc2 (list partno partno partno))) 0 1)
""
); command
(setq partno (1+ partno))
); while
(mapcar 'setvar svnames svvals); reset
(vla-endundomark doc)
(princ)
); defun
(prompt "Type SLB to Split Lines Between lines defined by 4 points or selected.")
Kent Cooper, AIA