
! script name: v3dinter.d/zprojectpt
! var_topic: z project point onto a part.

!A
!A NAME:
!A
!A 	Project Pt On Part	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	Projects a point onto a part in the z direction.
!A
!B INSTRUCTIONS:
!B
!B 	PICK PART GROUP: Pick the part group.
!B
!B 	PICK POINT: Pick the point to project onto a part.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: z project point onto part ")

DIM Destination$[256]
DIM Answer$[256]
DIM Part_group$[256]
DIM Point$[256]
DIM Name$[256]

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


Tol=NamedVarVal("3D Intersect Tol",Ws3DSystemVars,0.005)

ActivateUndo
Start:!
Intersect2:StdWorkplane
Stat= SetPickMask(WsPickSurfOnly)
stat= SetInputFormat("n4","")
Part=PickGroupEnt("PICK PART GROUP ")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Part) THEN Intersect2
Stat= EntityNameCheck(Part,Part_group$)

Stat= SetPickMask(WsPickNoSurf)
Pick_point:stat= SetInputFormat("n4","")
Stat= SetPickMask(WsPickNoSurf)
E1=PickEntity("PICK POINT")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_point
Stat= EntityNameCheck(E1,Point$)
Pick_para= LastPickPara
Pick_return= CurrPickReturn


Stat= GenerateVarName(WsPointEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("POINT: Z Project point onto part")
Stat= SetRecDelLastExec
Stat= NullReference(Part_group$)
Stat= SetWorkplane
SELECT Pick_return
CASE WsGeometryEnd
     Pz= ParameterReturnPt(Point$,Pick_para,WsGeometryEnd)
CASE WsGeometryMid
     Pz= ParameterReturnPt(Point$,Pick_para,WsGeometryMid)
CASE WsGeomCenter
     Pz= ParameterReturnPt(Point$,Pick_para,WsGeomCenter)
END SELECT
V1= FreeParameter("Tolerance",Tol)
Proj_vector= PointXYZ(0.0,0.0,1.0)
Stat= Set3dInterOffset(0.0)
UVPoint= ProjectPtToPart(Pz,Proj_vector,Part_group$,V1,WsReturnUVPoint)
RecordFunctionOff
IF NOT ValidGeometry(UVPoint) THEN
        Stat= DeleteEntity(UVPoint)
        Stat= DeleteEntity(Pz)
        Stat= DeleteEntity(Proj_vector)
        CloseVarRecord
        DelLastVarRecord
        GOTO Pick_point
END IF
RecordFunctionOn
Surface= GroupElement(Part_group$,ZPointValue(UVPoint)+1)
Pt= SurfParameterPt(Surface,XPointValue(UVPoint),YPointValue(UVPoint))
Stat= NameEntity(Pt,Name$)
Stat= DeleteEntityList(UVPoint,Pz,Proj_vector)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(Pt) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("z project pt")
	Stat= AddItemToUndo(WsUBCreateMode,Pt)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Pick_point



Leave:!
stat= SetInputFormat("n4","")
stat= DeleteEntity(Proj_vector)
stat= DeleteEntity(Pt)
stat= DeleteEntity(Point)
Stat= SetPickMask(WsPickGeometry)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
