
! script name: vtrimming.d/chamfertrim
! var_topic: construct corner chamfer

!A
!A NAME:
!A
!A 	Chamfer          VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a corner chamfer between two elements.
!A
!A~ image location - images/cornerchamfer.jpg
!B INSTRUCTIONS:
!B
!B 	CHAMFER LENGTH: This is measured parallel to a line or to a chord
!B 		of a circle.
!B
!B 	PICK FIRST ELEMENT, New Length: Pick one of the elements to
!B 		be chamfered.
!B
!B 		N - Enter N to allow a new chamfer length to be entered.
!B
!B 	PICK NEXT ELEMENT: Pick the other element to be chamfered.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: corner chamfer ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name1$[256]
DIM Name2$[256]
DIM Name$[256]
DIM Chamfer_len$[256]

DEG
Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

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

Ploop:!
Stat=SetInputFormat("a1",",N,")
E1=PickEntity("PICK FIRST ELEMENT,  New length",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="N" THEN Ask_length
IF NOT ValidDependency(E1) THEN Ploop
Para1=LastPickPara
Stat=EntityNameCheck(E1,Name1$)

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


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

Stat=GenerateVarName(WsLineEnt,Name$)
RecordFunctionOn
Stat=RecordDescr("LINE: Chamfer")
IF No_length_var THEN
	V1=FreeParameter("Chamfer",Chamfer_len)
	L1=ChamferTrim(V1,Name1$,Para1,Name2$,Para2)
ELSE
	L1=ChamferTrim(Chamfer_len$,Name1$,Para1,Name2$,Para2)
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

