
! script name: filing.d/placeclamp
! topic: read clamp file into group and place at several locations

!A
!A NAME:
!A
!A 	Place Clamp
!A
!A DESCRIPTION:
!A
!A 	This script allows a file to be read into a group and placed at several
!A 	locations.  This script will not permanently place a file until "Place"
!A 	is selected.
!A 	
!B INSTRUCTIONS:
!B
!B 	SELECT EXISTING FILE: The selection box will appear at this time for a
!B 		selection to be made.
!B
!B 	GROUP NAME: Enter the name to be associated with the file to be placed.
!B 		The group name will have a number appended to it in sequential
!B 		order each additional time the file is placed.
!B
!B 	LOCATION ABS X,Y,Z: Enter the X,Y,Z coordinates to be used as the
!B 		reference point in placing the file.  
!B 		NOTE: See XYZ INPUT OPTIONS.
!B 	
!B 	ORIENTATION ANGLE: Enter the angle to be used for orienting the file to
!B 		be placed.
!B
!B 	Undo or Place: Enter "U" to undo (delete) the file placement.  Enter
!B 		"P" to finalize the placement of the file.  Place must be
!B 		selected to finalize the process, exiting the script works like
!B 		Undo.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: place clamp ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Dir$[256]
DIM D_label$[256]
DIM Sub_label$[256]
DIM F_label$[256]
DIM Choice$[256]
DIM Mask$[32]
DIM Group_name$[256]
DIM Gname$[256]
DIM Decision$[256]

!C 	If Ask_undo$="Y" the "Undo, Restore, Delete" options will be present.
!C
!C 	If Ask_undo$="N" the script will automatically delete the elements
!C 	when they are picked.  NO CHANCE to change the selection.

DeActivateUndo
Ask_undo$="Y"

Component_group= 30999
Group_type= Component_group


Stat= NamedVarStr("retrieve dir",WsSystemVars,"/usr/weber/ST/",Dir$)
D_label$="DIRECTORY"
Sub_label$="SUB DIRECTORIES"
F_label$="FILES"
Choice$="FILE TO OPEN"
Mask$="[A-Za-z0-9]*"

Name$="/usr/weber/ST/clamp.syn"

Stat=SetInputFormat("a99","")
Stat=GetValue("GROUP NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Group_name$= Answer$
Gname$= Answer$

Group_num= 0

New_location: !

  Path_num=CurrPathNum
  Cont_num=CurrContourNum
  Hole_num=CurrHoleNum
  Path_grp_num=CurrPathGrpNum
  Hole_grp_num=CurrHoleGrpNum

Decision$=""
Stat=SetInputFormat("n4","")
Pc= XyzInput("LOCATION",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

Angle= InputAngle("ORIENTATION ANGLE")
IF (ExitScript(Destination$)) THEN Leave


PlotOff
Group=ReadGroupFile(Group_name$,Group_type,Name$)
PlotOn

T1=AngleTransform(Pc,0,0,Angle)
stat= TransGroupTrans(Group,T1)
stat= DeleteEntity(Pc)

Stat= ResolveNames(Group)

PlotAll

IF Ask_undo$="Y" THEN
   Decision$="U"
   Stat=SetInputFormat("a1=",",U,P,")
   Stat=SetEqualsValue(0,"P")
   Stat=GetValue("Undo or Place",Answer$)
   IF (ExitScript(Destination$)) THEN Leave
   Decision$=Answer$
END IF

SELECT Decision$

  CASE "P"

    Group_num= Group_num+1
    Group_name$= Gname$&VAL$(Group_num)

  CASE "U"

    Temp_group=Group
    IF NOT ValidGeometry(Temp_group) THEN New_location
    Stat=UnLink(Temp_group)
    Stat=DeleteGroup(Temp_group,1)
    Stat=DeleteEntity(Temp_group)
    GOSUB Reset_counters

END SELECT

TransformCleanup

GOTO New_location

Reset_counters: !

  Stat=SetCurrPathNum(Path_num)
  Stat=SetCurrContNum(Cont_num)
  Stat=SetCurrHoleNum(Hole_num)
  Stat=SetPathGrpNum(Path_grp_num)
  Stat=SetHoleGrpNum(Hole_grp_num)

RETURN

Leave:!

IF Ask_undo$="Y" AND Decision$="U" THEN
   Temp_group=Group
   IF NOT ValidGeometry(Temp_group) THEN Leave_1
   Stat=UnLink(Temp_group)
   Stat=DeleteGroup(Temp_group,1)
   Stat=DeleteEntity(Temp_group)
   TransformCleanUp
   GOSUB Reset_counters
END IF

Leave_1: !

LowerFileBox
Stat=SetInputFormat("n4","")
stat= DeleteEntity(Pc)

IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END


