
! script name: plot.d/plottoiges
! topic: create an iges file from a plotfile

!A
!A NAME:
!A
!A 	Create an IGES file from a plotfile
!A
!A DESCRIPTION:
!A
!A 	This script is for creating an IGES file from a view thru a plotfile.
!A
!B INSTRUCTIONS:
!B
!B 	IGES FILE NAME: Enter the name of the IGES file to be created.
!B
!C NOTES:
!C
!C 	The E size is the default paper.  The data files for the different
!C 	size paper are in:
!C
!C 		"/usr/weber/util/tooldata/plotconfig"
!C
!C 	The files may need to be modified depending on the type of plotter
!C 	being used.  New files may be added by following the format of the
!C 	other files.  If a new file is added, make sure the option is added
!C 	to the question and answer selections.
!C


OPTION BASE 1
DIM Arg$[256]
DIM Destination$[256]
DIM Answer$[256]
DIM Filename$[256]
DIM C$[256]
DIM Igs_fullname$[256]
DIM Igs_name$[256]
DIM Todir$[256]
DIM Map$[256]

!C The default paper size can be changed to any value from "A" to "E"
!C By using a larger paper size and smaller scale, we can force interpolated
!C entities to be smooth at high magnifications.
Papersize$="E" 

!C The scal variable is used to shrink or enlarge the paper size
Scal=.25

!C The Map$ controls the mapping of plotter pens to IGES colors
!C The default map is one to one. (e.g. Plot pen 8 = IGES pen 8 )
!C If the map was set to 8:7:6:5:4:3:2:1:0, Plot pen 8 = IGES pen 0
!C The map can contain up to 256 entries.
Map$="0:1:2:3:4:5:6:7:8"

stat=ChangeLabelStr("ScriptNameStatus","Function: Create IGES from plotdata")

!C
!C 	Todir$ points to the default iges file directory
Stat= NamedVarStr("iges storage dir",WsSystemVars,"/usr/weber/ST/iges/",Todir$)
Iges_name:C$="IGES FILE NAME"
Stat=SetInputFormat("a99","",WsFalse)
Stat=GetValue(C$,Answer$)
IF (ExitScript(Destination$)) THEN Leave

Igs_name$=Answer$
Igs_fullname$=RPT$(Todir$,NOT POS(Igs_name$,"/"))&Igs_name$

ON ERROR GOTO Start_file
ASSIGN @File TO Igs_fullname$
ASSIGN @File TO *

Stat=GeneralListBox("EXPORT IGES INFO","SELECTION","STORE ANYWAY,NEW NAME,")
C$=Igs_name$&" ALREADY EXISTS IN "&Todir$
Stat=SetInputFormat("a99","",WsFalse)
Stat=GetValue(C$,Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="STORE ANYWAY" THEN 
	ON ERROR GOTO Skip_purge
	PURGE Igs_fullname$
Skip_purge:OFF ERROR
	GOTO Start_file
END IF
GOTO Iges_name

Start_file:ON ERROR GOTO Leave

P1x= -4500
P1y= -2790
P2x= 4500
P2y= 2790

Filename$="/usr/weber/util/tooldata/plotconfig"

!Stat= GetValue("INPUT PAPER SIZE A B C D E ",Answer$)
!IF (ExitScript(Destination$)) THEN Leave
Answer$=Papersize$

Filename$=FileNameString(Filename$,Answer$&"size")
Plot_config=ReadUserData(2013,"PLOT CONFIG",Filename$)
IF (NOT (ValidGeometry(Plot_config))) THEN Start
P1x=GetUserValue(Plot_config,"P1x:")
P1y=GetUserValue(Plot_config,"P1y:")
P2x=GetUserValue(Plot_config,"P2x:")
P2y=GetUserValue(Plot_config,"P2y:")

Start:Plotter_view= FindView("PLOTTER")
IF NOT Plotter_view THEN
	xmin= -10
	xmax= 10
	ymin= -10
	ymax= 10
	stat= MakePlotterView("PLOTTER","plotfile",xmin,xmax,ymin,ymax,p1x,p1y,p2x,p2y)
	GOTO Start
END IF
stat= ChangeP1_P2(Plotter_view,p1x,p1y,p2x,p2y)

Source_view= 1
stat= OutputString("plotfile",CHR$(10),WsNewFile)
stat= CopyViewTrans(Plotter_view,Source_view)
stat= CopyViewScale(Plotter_view,Source_view)
stat= TurnViewOn(Plotter_view)
Drawing= ActiveDrawing
IF ValidGeometry(Drawing) THEN 
	Stat= SetActiveDrawing(Drawing,Plotter_view)
	Stat= PlotView(Plotter_view)
	Stat= SetActiveDrawing(Drawing)
ELSE
	Stat= PlotView(Plotter_view)
END IF
stat= TurnViewOff(Plotter_view)
stat= OutputString("plotfile",CHR$(10),WsAppend)

Arg$="-s "&VAL$(scal)&" -i plotfile -o "&Igs_fullname$&" -c "&Map$&" &"
print Arg$
stat= StartProcess("plt2igs "&Arg$)

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

