
! script name: vtrimming.d/globalchamfer
! var_topic: Sample - construct all corner chamfers

!A
!A NAME:
!A
!A 	Global Chamfer Routine        VARIATIONAL
!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~ image location - images/cornerchamfer.jpg
!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 chamfers 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]
DIM Descr$[256]
DIM Chamfer_len$[256]

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

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

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

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
IF NOT ValidDependency(E1) THEN Ploop
Para1=LastPickPara
Stat=EntityNameCheck(E1,Name1$)

Pick2:Stat= SetInputFormat("n4","")
E2=PickEntity("PICK SECOND ELEMENT ")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E2) THEN Pick2
Para2=LastPickPara
Stat=EntityNameCheck(E2,Name2$)

SELECT Num_trims
CASE 0
	trim_sw= WsUntrimmed
	Descr$= "LINE: Chamfer - No Trimming"
CASE 1
	trim_sw= WsTrimFirst
	Descr$= "LINE: Chamfer - Single Trimming"
CASE 2
	trim_sw= WsTrimmed
	Descr$= "LINE: Chamfer - Both Trimmed"
END SELECT

ActivateUndo
Stat= AdvanceUndoNumber("chamfer")
Stat= AddItemToUndo(WsUBModifyMode,Name1$)
Stat= AddItemToUndo(WsUBModifyMode,Name2$)

Stat=GenerateVarName(WsLineEnt,Name$)
RecordFunctionOn
Stat=RecordDescr(Descr$)
V0=FreeParameter("Trim switch",trim_sw)
IF No_length_var THEN
	V1=FreeParameter("Chamfer",Chamfer)
	L1=ChamferTrim(V1,Name1$,Para1,Name2$,Para2,V0)
ELSE
	L1=ChamferTrim(Chamfer_len$,Name1$,Para1,Name2$,Para2,V0)
END IF
Stat=NameEntity(L1,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(L1)
Stat= PlotEntity(Name1$)
Stat= PlotEntity(Name2$)
IF NOT ValidGeometry(L1) THEN 
	DelLastVarRecord
ELSE
	Stat= AddItemToUndo(WsUBCreateMode,L1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Ploop

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