Split Lines

From Vectorlab
Jump to: navigation, search


This Procedure takes all selected lines on the active layer and splits them in half, returning 2 lines, and deletes the original. By Frank Brault

Procedure SplitLines;
{
©2003, VectorExpress,Inc.
Developed by Frank Brault
Last modified: 10/31/03

This Procedure takes all selected lines
on the active layer and splits them in half,
returning 2 lines, and deletes the original.
}

Const
	kLineType = 2; {** The returned type ID for line objects.}
Var
	curHan, han2BDeleted : Handle;
	pX1, pY1, pX2, pY2 : Real;

Begin
	curHan := LSActLayer;
	While curHan <> nil Do
	Begin
		If GetType(curHan) = kLineType Then
		Begin
			GetSegPt1(curHan, pX1, pY1);
			GetSegPt2(curHan, pX2, pY2);
			MoveTo(pX1, pY1);
			LineTo((pX2+pX1)/2,(pY2+pY1)/2);
			LineTo(pX2, pY2);
			han2BDeleted := curHan;
			curHan := PrevSObj(curHan);
			If (han2BDeleted <> Nil) Then DelObject(han2BDeleted);
		End
	Else
		Begin
			SetDSelect(curHan);
			curHan := PrevSObj(curHan);
		End;
	End;
End;
Run(SplitLines);