
! script name: project.d/projectflat
! topic: projects a group of elements

!A
!A NAME:
!A
!A 	Project Flat
!A
!A DESCRIPTION:
!A
!A 	This script allows a group of elements to be projected.  The elements
!A 	may be selected in one of three ways:
!A
!A 		1) SELECTION BOX
!A 		2) PICK INDIVIDUAL ELEMENTS
!A 		3) PICK A GROUP
!A
!A 	The mode may be changed by editing the named variable "pick type".
!A 	To edit a named variable select the "EDIT USER DATA" option in the
!A 	"Edit" subdirectory, then select the "NAMED VARIABLES" option.  The
!A 	variable "pick type" should be one of the choices.  ( The numbers
!A 	above are the ones associated with the variable.)  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 	SELECT VIEW FOR SELECTION BOX: Pick the view that elements are to be
!B 		projected in.  This question is for SELECTION BOX mode only.
!B
!B 	PICK ELEMENT, PROCEED: Pick one of the elements to be projected.
!B 		This question is for PICK INDIVIDUAL ELEMENTS mode only.
!B 		The question will repeat until "PROCEED" is answered.
!B 		All elements picked will then be projected.
!B
!B 	PICK GROUP TO BE PROJECTED: Pick an element on the group to be
!B 		projected.  This question is for a PICK A GROUP mode only.
!B
!B 	Z CONSTANT:
!B
!B 	SCALE FACTOR:
!B
!B 	POSITION:
!B

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

DIM Answer$[256]
DIM Destination$[256]
DEG

stat= SetInputFormat("n4","")
Group=CreateGroup("TEMP")

Pick_type=NamedVarVal("pick type",WsSystemVars,1.0)

Start: !
ActivateUndo

SELECT Pick_type

  CASE 1    ! PICK BOX

    Vnum=PickView("SELECT VIEW FOR SELECTION BOX")
    IF (ExitScript(Destination$)) THEN Leave

    Stat=PickBox(Group,Vnum,WsPickPen)
    IF (ExitScript(Destination$)) THEN Leave

  CASE 2    ! PICK ELEMENTS

    LOOP
      Stat=SetInputFormat("a7",",PROCEED,")
      E1= PickEntity("PICK ELEMENTS, PROCEED",Answer$)
      IF (ExitScript(Destination$)) THEN Leave
      Stat=SetInputFormat("n4"," ")
    EXIT IF Answer$="PROCEED"
      Stat=AddToGroup(Group,E1)
    END LOOP

  CASE 3    ! PICK GROUP

    Grp1=PickGroupEnt("PICK GROUP TO BE PROJECTED")
    IF (ExitScript(Destination$)) THEN Leave
    Stat=AddToGroup(Group,Grp1)

  CASE ELSE

    Pick_type=1
    GOTO Start

END SELECT
IF (NOT ValidGeometry(Group)) THEN Start

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


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

Pz= PointXYZ(0,0,0)

Work=CurrentWorkplane
IF (ValidGeometry(Work)) THEN Active_workplane= 1
StdWorkplane

Pc=XyzInput("POSITION ",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

Delete_scaled=0
IF Scale_factor <> 1 THEN
	G1=ScaleGroup(Group,Pz,Scale_factor)
	Stat= DeleteEntity(Group)
	Delete_scaled=1
	Group= G1
END IF

Stat= DeleteEntity(Pz)

IF Active_workplane THEN
	G1= ProjectEntity(Group,Zconst,Work)
ELSE
	G1= ProjectEntity(Group,Zconst)
END IF
IF (ValidGeometry(G1)) THEN
	stat= DelMatchingEnts(G1)

	IF Delete_scaled THEN
		Stat= DeleteGroup(Group,1)
	END IF

	T1=AngleTransform(Pc,0.0,0.0,0.0,WsRealSpaceVals)
	G2=TransformGroup(G1,T1,"TEMP1")

	ActivateUndo
	Stat= AdvanceUndoNumber("project")
	Stat= AddGroupToUndo(WsUBCreateMode,G2,0,WsTrue)

	Stat= UnLink(G1)
	Stat= DeleteGroup(G1,1)
END IF

Leave:!
IF Active_workplane THEN
        Stat=SetWorkplane(Work)
ELSE
        StdWorkplane
END IF

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


