
! script name: vtrimming.d/angchmfrtrim
! var_topic: construct corner chamfer with arbitrary angle.

!A
!A NAME:
!A
!A 	Angle Chamfer          VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a corner chamfer between two elements.
!A	With the angle measured off the first element picked.
!A
!A~ image location - images/anglechamfer.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: angle chamfer ")

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

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

ActivateUndo
Chamfer_angle= GetDefault(WsChamferAngle)
IF Chamfer_angle<= 0.0 OR Chamfer_angle> 89.999 THEN Chamfer_angle= 45.0

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

Ask_angle: !
Stat= SetAngleEquals(Chamfer_angle)
Stat=SetInputFormat("n4","")
Chamfer_angle=InputAngle("CHAMFER ANGLE")
IF ExitScript(Destination$) THEN Leave
No_angle_var=LastVariableInput(Angle_var$)

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("angle 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)
	IF No_angle_var THEN
		V2=FreeParameter("Chamfer angle",Chamfer_angle)
		L1=AngleChamferTrim(V1,V2,Name1$,Para1,Name2$,Para2)
	ELSE
		L1=AngleChamferTrim(V1,Angle_var$,Name1$,Para1,Name2$,Para2)
	END IF
ELSE
	IF No_angle_var THEN
	  V2=FreeParameter("Chamfer angle",Chamfer_angle)
	  L1=AngleChamferTrim(Chamfer_len$,V2,Name1$,Para1,Name2$,Para2)
	ELSE
	  L1=AngleChamferTrim(Chamfer_len$,Angle_var$,Name1$,Para1,Name2$,Para2)
	END IF
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

