
! script name: vproject.d/projectcont
! var_topic: project contour

!A
!A NAME:
!A
!A 	Project Contour	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows a contour to be projected.  The data selected
!A 	will project the data into the current workplane and then position
!A 	it into the xy plane.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR TO BE PROJECTED: Pick an element on the group to be
!B 		projected.  This question is for a PICK A GROUP mode only.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: project contour ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Cname$[256]
DIM Element$[256]
DIM Z_var$[256]
DIM Scale_var$[256]
DEG

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

Start: !
ActivateUndo
Stat= SetInputFormat("n4","")
Pick_group:Group=PickGroupEnt("PICK CONTOUR TO BE PROJECTED")
IF (ExitScript(Destination$)) THEN Leave
IF (NOT ValidDependency(Group)) THEN Start
Stat= EntityNameCheck(Group,Cname$)
N1= GroupCount(Group)
IF N1<= 0 THEN Start

stat= SetInputFormat("n4=","")
stat= SetEqualsValue(0)
Zconst=GetValue("Z CONSTANT",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_Z_var= LastVariableInput(Z_var$)


stat= SetInputFormat("n4=","")
stat= SetEqualsValue(1.0)
Scale_factor= GetValue("SCALE FACTOR",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_scale_var= LastVariableInput(Scale_var$)


Stat= GenerateVarName(WsVarRecordEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("PROJECT: project contour")
Stat= SetRecDelLastExec
Pz= PointXYZ(0,0,0)
IF No_scale_var THEN
        V1= FreeParameter("Scale",Scale_factor)
        Sgroup=ScaleGroup(Cname$,Pz,V1)
ELSE
        Sgroup=ScaleGroup(Cname$,Pz,Scale_var$)
END IF
Work=CurrentWorkplane
RecordFunctionOff
IF ValidGeometry(Work) THEN
RecordFunctionOn
        IF No_z_var THEN
                V2= FreeParameter("Z Constant",Zconst)
                Pgroup= ProjectEntity(Sgroup,V2,Work)
        ELSE
                Pgroup= ProjectEntity(Sgroup,Z_var$,Work)
        END IF
RecordFunctionOff
ELSE
RecordFunctionOn
        IF No_z_var THEN
                V2= FreeParameter("Z Constant",Zconst)
                Pgroup= ProjectEntity(Sgroup,V2)
        ELSE
                Pgroup= ProjectEntity(Sgroup,Z_var$)
        END IF
RecordFunctionOff
END IF
RecordFunctionOff
IF ValidGeometry(Pgroup) THEN
RecordFunctionOn
	Stat= DelMatchingEnts(Pgroup)
	Stat= AutoNameGroup(Pgroup,Name$)
RecordFunctionOff
END IF
RecordFunctionOn
Stat= DeleteEntity(Pz)
Stat= DeleteGroup(Sgroup,WsTrue)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

ActivateUndo
Stat= AdvanceUndoNumber("project contour")
Stat= AddGroupToUndo(WsUBCreateMode,Pgroup,1,WsTrue)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
Stat= PlotEntity(Cname$)
Stat= PlotEntity(Pgroup)
GOTO Start


Leave:!
stat= SetInputFormat("n4","")
Stat=DeleteEntity(Pz)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END


