@Anonymous wrote:
.... Is there a possibility to get the resulting lines fall on the current layer? if it is not lot of work. ....
Here ya go -- I just removed clayer from the svnames list, and the (setvar 'clayer ... line that was taking it to the Layer of a selected object [and the comment about that in the top notes].
I wish they hadn't removed the Spoiler capability, so these would take up so much vertical space on the webpage [I guess I could put it into a file and attach that], but here we go....
;|
SplitBetween.lsp, to draw Polylines between four selected points, or take
selection of two existing Lines or single-line-segment Polylines, and
draw subdividing Polylines between and paralleling them, or "splaying"
between them if not parallel. Works in 2D or 3D, and in any UCS.
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 whether to do so on
the basis of 2D view in current Coordinate System.
Kent Cooper, last edited 21 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 plinewid blipmode)
svvals (mapcar 'getvar svnames)
); setq
(mapcar 'setvar svnames '(0 0 0)); turn off Osnap, command echoing, Pline width to 0
(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 "_.pline" ptA1 ptA2 "")
(setq linA (entlast)); [will take points from it later in case in non-World UCS]
(command "_.pline" 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
); 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 "_.pline"
(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