
! script name: trim.d/trimtopoint
! topic: trim element to a point

!A
!A NAME:
!A
!A 	Trim Element to a Point
!A
!A DESCRIPTION:
!A
!A 	This script allows an element to be trimmed  to a point. The point
!A	does not need to be on the element. It will trim to the closest
!A	perpendicular point on the element.
!A
!A~ image location - images/trimtopoint.jpg
!B INSTRUCTIONS:
!B
!B 	PICK ELEMENT TO BE TRIMMED: Pick the element that is to be trimmed.
!B
!B 	PICK TRIMMING POINT: Pick the point to be trimmed to.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: trim to a point ")

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

ActivateUndo
Pick_entity:!

Stat= SetInputFormat("n4","")
E1= PickEntity("PICK ELEMENT TO BE TRIMMED")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E1) THEN Pick_entity
T1= LastPickPara

Pt=XyzInput("INPUT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

T2= IntParameter(E1,Pt)
IF T1<= T2 THEN
        Which_end= WsStart
ELSE
        Which_end= WsEnd
END IF

ActivateUndo
Stat= AdvanceUndoNumber("trim")
Stat= AddItemToUndo(WsUBModifyMode,E1)

Stat= TrimEntity(E1,Pt,Which_end)

Stat=DeleteEntity(Pt)
GOTO Pick_entity

Leave:!
Stat=DeleteEntity(Pt)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
