
! script name: trim.d/globalchamfer
! topic: Sample - construct all corner chamfers

!A
!A NAME:
!A
!A 	Global Chamfer Routine
!A
!A DESCRIPTION:
!A
!A	This is a global function to do three types of chamfers between two
!A	elements.  The types are based on how many of the elements will be
!A	trimmed. 
!A
!A	Both - The two elements picked will be trimmed to the ends of the arc.
!A	Single - The first element picked will be trimmed to the end of the
!A	         arc and the second element will not be trimmed.
!A	None- Both elements will remain as they are and the arc will be added.
!A
!A 	This script assumes that once the chamfer chamfer has been defined.
!A	All subsequent radii will be the same until Chamfer is chosen.
!A
!B INSTRUCTIONS:
!B
!B 	CHAMFER LENGTH: Enter the chamfer that should be constructed between
!B 		the elements picked.
!B
!B	PICK FIRST ELEMENT. Single, Both, Chamfer: 
!B	PICK ELEMENT TO BE TRIMMED. None, Both, Chamfer:
!B	PICK ELEMENT TO BE TRIMMED. None, Single, Chamfer:
!B		Choose the first element to construct the chamfer.
!B		There are three options: Both - Trim both elements
!B		                       Single - Trim the first element picked
!B		                         None - Trim no elements
!B
!B	PICK SECOND ELEMENT: Pick the other element to construct the chamfer.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: global chamfer routine ")

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

DEG
ActivateUndo
Num_trims= 2
IF ARGC>=2 THEN Num_trims= VAL(ARGV(1))


Ask_chamfer:Stat= SetInputFormat("n4","")
Chamfer=GetValue("CHAMFER LENGTH ")
IF (ExitScript(Destination$)) THEN Leave

Ploop:!
Stat= SetInputFormat("a1=",",N,C,B,S,")
SELECT Num_trims
CASE 0
Stat= SetEqualsValue(0,"B")
E1=PickEntity("PICK FIRST ELEMENT. Single, Both, Chamfer",Answer$)
CASE 1
Stat= SetEqualsValue(0,"B")
E1=PickEntity("PICK ELEMENT TO BE TRIMMED. None, Both, Chamfer",Answer$)
CASE 2
Stat= SetEqualsValue(0,"S")
E1=PickEntity("PICK ELEMENT TO BE TRIMMED. None, Single, Chamfer",Answer$)
END SELECT
IF (ExitScript(Destination$)) THEN Leave
IF Answer$= "C" THEN Ask_chamfer
IF Answer$= "B" OR Answer$= "S" OR Answer$= "N" THEN
	Num_trims= (Answer$="S")+2*(Answer$="B")
	GOTO Ploop
END IF
Para1=LastPickPara

Stat= SetInputFormat("n4","")
E2=PickEntity("PICK SECOND ELEMENT ")
IF (ExitScript(Destination$)) THEN Leave
Para2=LastPickPara

SELECT Num_trims
CASE 0
        trim_sw= WsUntrimmed
CASE 1
        trim_sw= WsTrimFirst
CASE 2
        trim_sw= WsTrimmed
END SELECT

ActivateUndo
Stat= AdvanceUndoNumber("chamfer")
Stat= AddItemToUndo(WsUBModifyMode,E1)
Stat= AddItemToUndo(WsUBModifyMode,E2)

L1= ChamferTrim(Chamfer,E1,Para1,E2,Para2,Trim_sw)
Stat= PlotEntity(E1)
Stat= PlotEntity(E2)
Stat= PlotEntity(L1)

Stat= AddItemToUndo(WsUBCreateMode,L1)
GOTO Ploop

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