
! script name: drawings.d/ threeview
! topic: make a drawing entity with three views

!A
!A NAME:
!A
!A 	Three View
!A
!A DESCRIPTION:
!A
!A 	This script makes a drawing entity with three views.
!A
!B INSTRUCTIONS:
!B
!B 	DRAWING NAME: Enter the name to be used for the drawing.
!B
!B 	DRAWING LENGTH  A, B, C, D, E: Enter the correct pzper size.
!B
!B 	VIEW SCALE: Enter the scale to be used for this view.
!B
!B 	REFERENCE X,Y,Z: Enter the X,Y,Z coordinates for the
!B 		reference point of the view.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: make 3 view drawing ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Layers$[256]
DIM Colors$[256]
DIM Model$[256]
DIM Top_layers$[256]
DIM Side_layers$[256]
DIM Front_layers$[256]
DIM Iso_layers$[256]
DIM Assoc_layers$[256]
DIM Title$[256]
DEG

DeActivateUndo
Title$= "SYNERGY DRAWING"

Model$= ",0,1,2,3,4,5,6,7,8,9,10,"
Top_layers$= ",101,"
Side_layers$= ",102,"
Front_layers$= ",103,"
Iso_layers$= ",104,"
Assoc_layers$= ",201,202,"

Units= CurrentUnits
Ask_reference=0
Draw_frame=1
Draw_title=1
IF Units= WsMetric THEN
	Margin= 12
	Xspace= 25
	Yspace= 25
	Xpos= 0
	Ypos= 0
ELSE
	Margin= 0.5
	Xspace= 1
	Yspace= 1
	Xpos= 0
	Ypos= 0
END IF
Frame_layer= 201
Frame_color= 0
Frame_ltype= 0
Title_layer= 202
Title_color= 0
Title_ltype= 0

Right_factor= 0.125
Left_factor= 0.0
Top_factor= 0.0
Bottom_factor= 0.0625


Draw_loop:! 
StdWorkplane

Num_drawings= EntityTypeCount(WsDrawingEnt)
Stat= SetEqualsValue(0,"Drawing "&VAL$(Num_drawings+1))
stat= SetInputFormat("a99=","")
stat= GetValue("DRAWING NAME ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Name$= Answer$

stat= SetInputFormat("n4a2",",A,B,C,D,E,A0,A1,A2,A3,A4,")
Draw_len= GetValue("DRAWING LENGTH  A, B, C, D, E  ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
SELECT Answer$
CASE "A0"
	Draw_len= 1189
	Draw_width= 841
	IF Units= WsInch THEN
		Draw_len= Draw_len/25.4
		Draw_width= Draw_width/25.4
	END IF
CASE "A1"
	Draw_len= 841
	Draw_width= 594
	IF Units= WsInch THEN
		Draw_len= Draw_len/25.4
		Draw_width= Draw_width/25.4
	END IF
CASE "A2"
	Draw_len= 594
	Draw_width= 420
	IF Units= WsInch THEN
		Draw_len= Draw_len/25.4
		Draw_width= Draw_width/25.4
	END IF
CASE "A3"
	Draw_len= 420
	Draw_width= 297
	IF Units= WsInch THEN
		Draw_len= Draw_len/25.4
		Draw_width= Draw_width/25.4
	END IF
        Xspace= 0
        Yspace= 0
CASE "A4"
	Draw_len= 297
	Draw_width= 210
	IF Units= WsInch THEN
		Draw_len= Draw_len/25.4
		Draw_width= Draw_width/25.4
	END IF
        Xspace= 0
        Yspace= 0
CASE "A"
	Draw_len= 12
	Draw_width= 9
	IF Units= WsMetric THEN
		Draw_len= Draw_len*25.4
		Draw_width= Draw_width*25.4
	END IF
        Xspace= 0
        Yspace= 0
CASE "B"
	Draw_len= 18
	Draw_width= 12
	IF Units= WsMetric THEN
		Draw_len= Draw_len*25.4
		Draw_width= Draw_width*25.4
	END IF
        Xspace= 0
        Yspace= 0
CASE "C"
	Draw_len= 24
	Draw_width= 18
	IF Units= WsMetric THEN
		Draw_len= Draw_len*25.4
		Draw_width= Draw_width*25.4
	END IF
CASE "D"
	Draw_len= 36
	Draw_width= 24
	IF Units= WsMetric THEN
		Draw_len= Draw_len*25.4
		Draw_width= Draw_width*25.4
	END IF
CASE "E"
	Draw_len= 48
	Draw_width= 36
	IF Units= WsMetric THEN
		Draw_len= Draw_len*25.4
		Draw_width= Draw_width*25.4
	END IF
CASE ELSE

	stat= SetInputFormat("n4","")
	Draw_width= GetValue("DRAWING WIDTH ")
	IF (ExitScript(Destination$)) THEN Leave

END SELECT

Draw_len=PROUND(Draw_len,0)
Draw_width=PROUND(Draw_width,0)

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

View_reference:!
IF Ask_reference THEN
	Stat=SetInputFormat("n4","")
	Pref=XyzInput("REFERENCE",WsXyzInput)
	IF (ExitScript(Destination$)) THEN Leave
	IF NOT ValidGeometry(Pref) THEN View_reference
ELSE
	Pref= PointXYZ(0,0,0)
END IF

Make_drawing:!
Pc= PointXYZ(Xpos,Ypos,0)
IF Draw_frame THEN
CALL Drawing_frame(Xpos,Ypos,Draw_len,Draw_width,Margin,Frame_layer,Frame_color,Frame_ltype)
END IF

IF Draw_title THEN
CALL Title_tables(Xpos,Ypos,Draw_len,Draw_width,Margin,Left_factor,Right_factor,Top_factor,Bottom_factor,Title$,Title_layer,Title_color,Title_ltype)
END IF

Drawing= CreateDrawing(Pc,WsLowerLeft,Draw_len,Draw_width,Assoc_layers$,Colors$)
Stat= NameEntity(Drawing,Name$)



View_points:!

CALL Drawing_area(Xc,Yc,Xlen,Ywid,Xpos,Ypos,Draw_len,Draw_width,Margin,Left_factor,Right_factor,Top_factor,Bottom_factor)

Vlength= Xlen/4- 2*Xspace
Vwidth= Ywid/4- 2*Yspace
Vheight= Xlen

IF (Vlength<= 0) OR (Vwidth<=0) THEN 
	Stat= DeleteEntity(Drawing)
	GOTO Leave
END IF

X1= Xc- Vlength- Xspace
Y1= Yc- Vwidth- Yspace

X2= Xc- Vlength- Xspace
Y2= Yc+ Vwidth+ Yspace

X3= Xc+ Vlength+ Xspace
Y3= Yc+ Vwidth+ Yspace

X4= Xc+ Vlength+ Xspace
Y4= Yc- Vwidth- Yspace

Ptopview= PointXYZ(X2,Y2,0)
Pfrontview= PointXYZ(X1,Y1,0)
Psideview= PointXYZ(X3,Y3,0)


Top_view:!
Layers$= Model$&Top_layers$
T1= AngleTransform(Pc,0,0,0)
View1= MakeStoredView("TOP","",T1,-10,10,-10,10,-10,10)
stat= ChangeViewLayers(View1,Layers$)
Stat= AddViewToDrawing(Drawing,View1,Ptopview,Pref,Vscale,-vlength,vlength,-vwidth,vwidth,-vheight,vheight)
Stat=DeleteEntity(T1)
Stat=DeleteEntity(View1)

Side_view:!
Layers$= Model$&Side_layers$
T1= AngleTransform(Pc,0,90,0)
View1= MakeStoredView("SIDE","",T1,-10,10,-10,10,-10,10)
stat= ChangeViewLayers(View1,Layers$)
Stat= AddViewToDrawing(Drawing,View1,Psideview,Pref,Vscale,-vlength,vlength,-vwidth,vwidth,-vheight,vheight)
Stat=DeleteEntity(T1)
Stat=DeleteEntity(View1)


Front_view:!
Layers$= Model$&Front_layers$
T1= AngleTransform(Pc,-90,0,0)
View1= MakeStoredView("FRONT","",T1,-10,10,-10,10,-10,10)
stat= ChangeViewLayers(View1,Layers$)
Stat= AddViewToDrawing(Drawing,View1,Pfrontview,Pref,Vscale,-vlength,vlength,-vwidth,vwidth,-vheight,vheight)
Stat=DeleteEntity(T1)
Stat=DeleteEntity(View1)



Stat=DeleteEntity(Ptopview)
Stat=DeleteEntity(Pfrontview)
Stat=DeleteEntity(Psideview)
Stat=DeleteEntity(Pc)
Stat=DeleteEntity(Pt)

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

GOTO Leave

Leave:!
Stat=DeleteEntity(Ptopview)
Stat=DeleteEntity(Pfrontview)
Stat=DeleteEntity(Psideview)
Stat=DeleteEntity(Pref)
Stat=DeleteEntity(Pc)
Stat=DeleteEntity(Pt)
stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

SUB Drawing_frame(Xpos,Ypos,Length1,Width1,Margin,Frame_layer,Frame_color,Frame_ltype)

Curr_layer= CurrentLayer
Curr_color= CurrentColor
Curr_ltype= CurrentLT
Xcen= Xpos+ Length1/2
Ycen= Ypos+ Width1/2
Stat=SetCurrentColor(Frame_color)
Stat=SetCurrentLayer(Frame_layer)
Stat=SetCurrentLT(Frame_ltype)
Contour1= RectangleContour(Xcen,Ycen,Length1,Width1,0.0,0.0,WsFalse)
Length2= Length1-2*Margin
Width2= Width1-2*Margin
Contour2= RectangleContour(Xcen,Ycen,Length2,Width2,0.0,0.0,WsFalse)

Stat=BlendContours(Contour1,Contour2)
Stat= DeleteEntity(Contour1)
Stat= DeleteEntity(Contour2)

Stat=SetCurrentColor(Curr_color)
Stat=SetCurrentLayer(Curr_layer)
Stat=SetCurrentLT(Curr_ltype)

SUBEND

SUB Drawing_area(Xc,Yc,Xlen,Ywid,Xpos,Ypos,Length1,Width1,Margin,Left_factor,Right_factor,Top_factor,Bottom_factor)

Left_side= Left_factor*Length1
Right_side= Right_factor*Length1
Top_side= Top_factor*Width1
Bottom_side= Bottom_factor*Width1

X1= Xpos+ Margin+ Left_side
Y1= Ypos+ Margin+ Bottom_side

X2= Xpos+ Length1- Margin- Right_side
Y2= Y1

X3= X1
Y3= Ypos+ Width1- Margin- Top_side

X4= X2
Y4= Y3

Xc= (X1+X2)/2
Yc= (Y1+Y3)/2
Xlen= ABS(X2-X1)
Ywid= ABS(Y3-Y1)

SUBEND



SUB Title_tables(Xpos,Ypos,Length1,Width1,Margin,Left_factor,Right_factor,Top_factor,Bottom_factor,Title$,Title_layer,Title_color,Title_ltype)

DEG

Left_side= Left_factor*Length1
Right_side= Right_factor*Length1
Top_side= Top_factor*Width1
Bottom_side= Bottom_factor*Width1

X1= Xpos+Length1-Margin
Y1= Ypos+Margin
X2= Xpos+Length1-Margin-Right_side
Y2= Ypos+Margin+Bottom_side

X3= X1
Y3= Y1+ 0.6*Bottom_side
Height1= 0.6*Bottom_side
Height2= 0.4*Bottom_side

Num_rows= 4
Num_cols= 3

Theight= 0.2*Bottom_side
Tlen= 0.6*Theight
Tslant= TAN(20)


Pc= PointXYZ(X1,Y1,0)
Table1= CreateBlankTable(Pc,"",Num_rows,Num_cols,WsLowerRight,"        ")
Stat= NameEntity(Table1,"Drawing Table")
Stat= DeleteEntity(Pc)
Stat= TableTextOrigin(Table1,WsCenterText)
Stat= SetTableColors(Table1,Title_color)
Stat= SetTableLType(Table1,Title_ltype)
Stat= SetLayer(Table1,Title_layer)
Stat= SetLineType(Table1,Title_ltype)

Pc= PointXYZ(X3,Y3,0)
Table2= CreateBlankTable(Pc,"",1,1,WsLowerRight,"        ")
Stat= NameEntity(Table2,"Drawing Title Bar")
Stat= DeleteEntity(Pc)
Stat= InsertIntoTable(Table2,Title$,1,1)
Stat= TableTextOrigin(Table2,1,1,WsCenterText)
Stat= TableTextSizes(Table2,Tlen,Theight,Tslant)
Stat= SetTableColors(Table2,Title_color)
Stat= SetTableLType(Table2,Title_ltype)
Stat= SetLayer(Table2,Title_layer)
Stat= SetLineType(Table2,Title_ltype)

Stat=AutoSizeTable(Table1)
Stat= SetTableLenWidth(Table1,Right_side,Height1,1)
Stat=AutoSizeTable(Table2)
Stat= SetTableLenWidth(Table2,Right_side,Height2,1)


SUBEND



