
! script name: vpoints.d/intersect
! var_topic: create point at intersection of two elements

!A
!A NAME:
!A
!A 	Intersection -- VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script creates a point at the intersection of two elements.
!A
!A~ image location - images/intersectpt.jpg
!B INSTRUCTIONS:
!B
!B 	PICK FIRST ELEMENT OF INTERSECTION: Pick one of the
!B 		elements that is to be used to determine the point location.
!B
!B 	PICK SECOND ELEMENT OF INTERSECTION: Pick the other
!B 		element that intersects the first element picked.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: intersection ")

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


DEG

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

ActivateUndo
Pick_loop:E1=PickEntity("PICK FIRST ELEMENT OF INTERSECTION")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_loop
T1= LastPickPara
Stat= EntityNameCheck(E1,Name1$)

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


Stat= GenerateVarName(WsPointEnt,Name$)

RecordFunctionOn
Stat= RecordDescr("POINT: Intersect")
Stat= SetRecDelLastExec
P1= ParameterPt(Name1$,T1)
Pt= Intersect(Name1$,Name2$,P1)
Stat= NameEntity(Pt,Name$)
Stat= DeleteEntity(P1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Name1$)
Stat= PlotEntity(Name2$)
Stat= PlotEntity(Name$)

IF NOT ValidGeometry(Pt) THEN
	DelLastVarRecord
ELSE
	Stat=SetLastPoint(Pt,WsXyzInput)
	ActivateUndo
	Stat= AdvanceUndoNumber("intersect pt")
	Stat= AddItemToUndo(WsUBCreateMode,Pt)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

GOTO Pick_loop

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


