
! script name: contours.d/addcornerrad
! topic: add radius to contour corner

!A
!A NAME:
!A
!A 	Add Radius to Contour Corner
!A
!A DESCRIPTION:
!A
!A 	This script allows a corner radius on a contour to be
!A 	changed.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR ELEMENT : Pick an corner element on the contour.
!B
!B 	CORNER RADIUS: Input the radius to be used on the corner.
!B
!B
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: add corner radius")

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

ActivateUndo
Radius_ques:!
Radius= InputRadius("CORNER RADIUS ")
IF (ExitScript(Destination$)) THEN Leave

Pick_loop:!
Stat= SetInputFormat("n4a1",",N,")
E1=PickEntity("PICK CONTOUR ELEMENT, New radius ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="N" THEN Radius_ques
IF NOT ValidGeometry(E1) THEN Pick_loop
IF IsTypeElement(E1) THEN Pick_loop

Tlast= LastPickPara
Contour= ParentGroup(E1,0)
IF NOT ValidGeometry(Contour) THEN Pick_loop
Element_num=ElementGrpNum(Contour,E1)
IF NOT Element_num THEN Pick_loop

Closed= IsContClosed(Contour)
Reversed= IsDirReversed(E1)
IF ((Tlast< 0.5) AND (NOT Reversed)) OR ((Tlast> 0.5) AND (Reversed)) THEN
	Element_num= Element_num-1
	IF Element_num<= 0 THEN
		IF NOT Closed THEN Pick_loop
		Element_num= GroupCount(Contour)
	END IF
END IF

Contour1= CopyGroup(Contour)
ActivateUndo
Stat= AdvanceUndoNumber("add corner radius")
Stat= AddGroupToUndo(WsUBDeleteMode,Contour,1,WsTrue)

C1= AddCornerRadius(Contour1,Radius,Element_num)
stat= GroupName(Contour,Name$)
Stat= DeleteGroup(Contour,WsTrue)
stat= ChangeGrpName(Contour1,Name$)

Stat= AddGroupToUndo(WsUBCreateMode,Contour1,1,WsTrue)

Stat= PlotEntity(Contour1)


GOTO Pick_loop

Leave:!
Stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
