
! script name: contours.d/joincontours
! topic: join two contours

!A
!A NAME:
!A
!A 	JOIN CONTOURS
!A
!A DESCRIPTION:
!A
!A 	This script joins two contours.  A line will join the start point
!A 	of the first contour to the end point of the other contour.
!A
!B INSTRUCTIONS:
!B
!B 	PICK FIRST CONTOUR: Pick the first contour to be joined, the
!B 		start point of this contour will be used for the joining.
!B
!B 	PICK NEXT CONTOUR: Pick the other contour to be joined, the
!B 		end point of this contour will be used for the joining.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: join contours ")

DIM Answer$[256]
DIM Destination$[256]



ActivateUndo
Join_loop:!
Contour1=PickGroupEnt("PICK FIRST CONTOUR ")
IF (ExitScript(Destination$)) THEN Leave

Contour2=PickGroupEnt("PICK NEXT CONTOUR ")
IF (ExitScript(Destination$)) THEN Leave

C1= CopyGroup(Contour1)
C2= CopyGroup(Contour2)

ActivateUndo
Stat= AdvanceUndoNumber("join contours")
Stat= AddGroupToUndo(WsUBDeleteMode,Contour1,1,WsTrue)
Stat= AddGroupToUndo(WsUBDeleteMode,Contour2,1,WsTrue)

New_contour=JoinContours(C1,C2)

Tool= GetAssocTool(Contour1)
IF ValidGeometry(Tool) THEN
      Stat= AssociateTool(New_contour,Tool)
END IF
Comp_dir=GetDCompDirection(Contour1)
Stat=SetDCompDirection(C3,Comp_dir)

! delete original contour groups 
stat= DeleteGroup(Contour1,WsTrue)
stat= DeleteGroup(Contour2,WsTrue)
stat= DeleteEntity(C1)
stat= DeleteEntity(C2)

Stat= AddGroupToUndo(WsUBCreateMode,New_contour,1,WsTrue)
Stat=Highlight(New_contour,WsAutoseqPen,WsDirArrowOn)


GOTO Join_loop

Leave:!
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
