
! script name: drawings.d/ addviewtodraw
! topic: make and add a view to a drawing.

!A
!A NAME:
!A
!A 	Add View
!A
!A DESCRIPTION:
!A
!A 	This script adds a view to a drawing.
!A
!B INSTRUCTIONS:
!B
!B 	DRAWING NAME: Enter the name to be used for the drawing.
!B
!B 	VIEW NAME: Enter the name to be used for the view.
!B
!B 	LAYERS VISIBLE ON THIS VIEW, All: Enter the individual
!B 		layers to be visible on this view or enter "A" for all layers.
!B
!B 	VIEW SCALE: Enter the scale for the view.
!B
!B 	REFERENCE X,Y,Z: Enter the X,Y,Z coordinates for the
!B 		reference point of the view.
!B
!B 	VIEW POSITION X,Y: Enter the X,Y coordinates to position the view.
!B
!C NOTES:
!C
!C 	Orient the data on the screen to the appropriate viewing position
!C 	before adding the view.
!C
!C 	Specify the layers to be visible on this view.
!C
!C 	Specify the view scale.
!C
!C 	Specify the Reference Point for the view.
!C
!C 	The system will now display the drawing. The view may be
!C 	then placed on the drawing.
!C	
!C 	The reference point is the position in X,Y,Z real space that
!C 	the data is transformed about to place at the view position
!C 	on the drawing. View clipping takes place about the X,Y position
!C 	on the drawing.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: add view to drawing ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Layers$[256]
DIM Colors$[256]
DIM Model$[256]
DIM View_name$[256]
DEG


DeActivateUndo
Vscale=1

Start:!

Stat=UserSelectBox("DRAWINGS","selected drawing",WsDrawingSelect,WsDrawingSelect)
IF Stat=1 THEN Leave

Stat=SetInputFormat("a99","")
Stat=GetValue("DRAWING NAME",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Leave
Name$=Answer$

Drawing= FindNamedEntity(Name$)
IF NOT ValidGeometry(Drawing) THEN Start
LowerSelectBox

Num_views= NumberDrawingViews(Drawing)
Stat= SetEqualsValue(0,"View "&VAL$(Num_views+1))
Stat=SetInputFormat("a99=","")
Stat=GetValue("VIEW NAME ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="CANCEL" THEN Leave
View_name$=Answer$

Stat=SetInputFormat("a99",",A,N,",WsFalse)
Stat=GetValue("LAYERS VISIBLE ON THIS VIEW, All ,",Layers$)
IF (ExitScript(Destination$)) THEN Leave
IF Layers$="CANCEL" THEN Leave
IF Layers$="A" OR Layers$="a" THEN Layers$=""
IF Layers$="All" OR Layers$="all" THEN Layers$=""
IF LEN(Layers$) THEN Layers$= ","&Layers$&","

stat= SetInputFormat("n4=","")
Stat= SetEqualsValue(Vscale)
Vscale= GetValue("VIEW SCALE ")
IF (ExitScript(Destination$)) THEN Leave

View_reference:Stat=SetInputFormat("n4","")
Pref=XyzInput("REFERENCE",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pref) THEN View_reference


View_box:!
Vnum= LastPickView
View_trans= ViewTransform(Vnum)

StdWorkplane
Stat= PlotDrawing(Drawing,1,WsTrue)
Stat= SetActiveDrawing(Drawing)

View_position:Stat=SetInputFormat("n4","")
Pcenter=XyzInput("VIEW POSITION",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pcenter) THEN View_position

vlength= 100
vwidth= 100
vheight= 100

View1= MakeStoredView(View_name$,"",View_trans,-10,10,-10,10,-10,10)
stat= ChangeViewLayers(View1,Layers$)
Stat= AddViewToDrawing(Drawing,View1,Pcenter,Pref,Vscale,-vlength,vlength,-vwidth,vwidth,-vheight,vheight)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Pref)
Stat=DeleteEntity(View1)

StdWorkplane
Stat= PlotDrawing(Drawing,1,WsTrue)
Stat= SetActiveDrawing(Drawing)

View_clip_pts:!
View_num= FindClosestView(Drawing,Pcenter)
Vnum=1
L1=WorkplaneBox(Vnum)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(L1) THEN View_clip_pts
Len1= LineLength(L1)
IF Len1<= 0.001 THEN View_clip_pts

Ps= ParameterPt(L1,0.0)
Pe= ParameterPt(L1,1.0)

Stat= SetViewClipPts(Drawing,Ps,Pe,View_num)
Stat=DeleteEntity(Center)
Stat=DeleteEntity(Pt1)
Stat=DeleteEntity(Pt2)
Stat=DeleteEntity(L1)
Stat= PlotDrawing(Drawing,1,WsTrue)
Stat= SetActiveDrawing(Drawing)

GOTO Leave

Leave:!
LowerSelectBox
stat= SetInputFormat("n4","")
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Pcenter)
Stat=DeleteEntity(Pref)
Stat=DeleteEntity(View1)
Stat=DeleteEntity(L1)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
