
! script name: vproject.d/projobjflat
! var_topic: Sample - project object and lay flat

!A
!A NAME:
!A
!A 	Project Object Flat   VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script allows an object to be projected and layed flat.
!A 	The object selected will be projected flat into the current workplane
!A 	and then transfered into the XY plane.
!A
!B INSTRUCTIONS:
!B
!B 	Z CONSTANT:
!B
!B 	SCALE FACTOR:
!B
!B 	POSITION:
!B

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

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

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

stat= SetInputFormat("n4","")

DeActivateUndo
Start: !
Pick_object:!
Stat=SetInputFormat("n4a1",",N,")
E1=PickEntity("PICK VARIATIONAL OBJECT, Name ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="N" THEN
        Stat=SetInputFormat("a99","")
        Stat=GetValue("OBJECT NAME",Answer$)
        IF ExitScript(Destination$) THEN Leave
        Object_name$=Answer$
	Var_object=FindNamedObject(Object_name$)
        IF NOT ValidGeometry(Var_object) THEN Pick_object
ELSE
        IF NOT ValidGeometry(E1) THEN Pick_object
        Var_object=VarObjectParent(E1)
        IF NOT ValidGeometry(Var_object) THEN Pick_object
        Stat=VarObjectName(Var_object,Object_name$)
END IF
N1= VarObjectNumber(Var_object)
Curr_object= CurrentVarObject
N2= VarObjectNumber(Curr_object)
IF N1>= N2 THEN
	Stat=SetInputFormat("a1",",P,")
	Stat=GetValue("POSSIBLE CIRCULAR DEPENDENCY, Proceed",Answer$)
	IF ExitScript(Destination$) THEN Leave
	GOTO Pick_object
END IF



Stat=Highlight(Var_object,Highlight_color,0)


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$)

Ref_point:E2=PickEntity("POSITION")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E2) THEN Ref_point
T= LastPickPara
Pick_return= CurrPickReturn
Stat= EntityNameCheck(E2,Center$)
Pc= ParameterReturnPt(E2,T,Pick_return)


Stat= GenerateVarName(WsVarRecordEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("PROJECT: project object view")
Var_object=FindNamedObject(Object_name$)
Egroup= VObjectGeomGroup(Var_object,WsFalse)

Pz= PointXYZ(0,0,0)
Work=CurrentWorkplane
Stat= SetWorkplane(0)
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,T,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,T,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,T,WsGeomCenter)
END SELECT
IF No_scale_var THEN
	V1= FreeParameter("Scale",Scale_factor)
	Sgroup=ScaleGroup(Egroup,Pz,V1)
ELSE
	Sgroup=ScaleGroup(Egroup,Pz,Scale_var$)
END IF
Stat= DeleteEntity(Egroup)
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
RecordFunctionOn
Stat= DelMatchingEnts(Pgroup)
Stat= DeleteGroup(Sgroup,WsTrue)
Trans1=AngleTransform(Pc,0.0,0.0,0.0,WsRealSpaceVals)
G1=TransformGroup(Pgroup,Trans1,"TEMP")
Stat= DeleteGroup(Pgroup,WsTrue)
Stat= AutoNameGroup(G1,Name$)
Stat= SetNoPathFlag(G1,WsTrue)
Stat= DeleteEntity(Pc)
Stat= DeleteEntity(G1)
Stat= SetWorkplane(Work)
RecordFunctionOff
CloseVarRecord

Stat= DeleteEntity(Group)

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


