
! script name: vtrimming.d/elementtrim
! var_topic: trim element

!A
!A NAME:
!A
!A 	Element Trim          VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows an element to be trimmed dependent on the
!A 	intersection with another element.
!A
!A~ image location - images/elementtrim.jpg
!B INSTRUCTIONS:
!B
!B 	PICK FIRST ELEMENT TO BE TRIMMED: Pick
!B 		the element that is to be trimmed.
!B
!B 	PICK TRIMMING ELEMENT: Pick the element
!B 		that is the determining factor in
!B 		trimming the other element.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: trim element ")

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

DEG

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Ploop:!
Stat=SetInputFormat("n4","")
E1=PickEntity("PICK FIRST ELEMENT TO BE TRIMMED")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E1) THEN Ploop
Para1=LastPickPara
Stat=EntityNameCheck(E1,Name1$)

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

P1=ParameterPt(E1,Para1)
Pt=Intersect(E1,E2,P1)
Which_end=TrimWhichEnd(E1,Pt,P1)
Stat=DeleteEntity(P1)
Stat=DeleteEntity(Pt)

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

RecordFunctionOn
Stat=RecordDescr("TRIM: Trim to an element")
Selectpt=ParameterPt(Name1$,Para1)
No_trim=CornerTrim(Name1$,Which_end,Name2$,Which_end,Selectpt,WsTrimFirst)
Stat=DeleteEntity(Selectpt)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Name1$)
Stat= PlotEntity(Name2$)
IF No_trim THEN
	DelLastVarRecord
ELSE
	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

