
! script name: vpoints.d/xentity
! var_topic: create point on entity at known Y

!A
!A NAME:
!A
!A 	Y: Element	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script creates a point on an entity at a known Y.
!A
!A~ image location - images/yentity.jpg
!B INSTRUCTIONS:
!B
!B 	INPUT ABS Y: Enter the Y coordinate of the point.
!B
!B 	PICK INTERSECTING ELEMENT: Pick the element that
!B 		intersects the Y coordinate of the point.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: y: element ")

DIM Answer$[256]
DIM Destination$[256]
DIM Ename$[256]
DIM Name$[256]
DIM Y_var$[256]
DIM Destination$[256]


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

ActivateUndo
Ploop:Stat=SetInputFormat("n4=","")
Stat=SetPickReturn(WsGeometryY)
Yvalue=GetValue("Y COORDINATE",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Stat=SetPickReturn(WsGeometryEnd)

No_y_var= LastVariableInput(Y_var$)

Pick_loop:!
Stat=SetInputFormat("n4","")
E1=PickEntity("PICK ENTITY")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_loop
Para1= LastPickPara
Stat= EntityNameCheck(E1,Ename$)

Stat= GenerateVarName(WsPointEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("POINT: Y entity")
Stat= SetRecDelLastExec
Selectpt= ParameterPt(Ename$,Para1)
IF No_y_var THEN
	V1= FreeParameter("Y",Yvalue)
        Pt=PtYEntity(V1,Ename$,Selectpt)
ELSE
        Pt=PtYEntity(Y_var$,Ename$,Selectpt)
END IF
Stat= NameEntity(Pt,Name$)
Stat= DeleteEntity(Selectpt)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Ename$)
Stat= PlotEntity(Name$)
IF NOT ValidGeometry(Pt) THEN
	DelLastVarRecord
ELSE
	Stat=SetLastPoint(Pt,WsXyzInput)
	ActivateUndo
	Stat= AdvanceUndoNumber("y entity pt")
	Stat= AddItemToUndo(WsUBCreateMode,Pt)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Ploop

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



