
! script name: vdrawings.d/ fourview
! var_topic: make a drawing entity with four views

!A
!A NAME:
!A
!A 	Four View	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script makes a drawing entity with four 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 reference point
!B 		of the view.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: make 4 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

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

DeActivateUndo
Title$= "SYNERGY DRAWING"

Model$= ",0,1,2,3,4,5,6,7,8,9,10,"
Top_layers$= Model$&",101,"
Side_layers$= Model$&",102,"
Front_layers$= Model$&",103,"
Iso_layers$= Model$&",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)


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  Leave

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



RecordFunctionOn
Stat= RecordDescr("DRAWING: Four view")
Stat= SetWorkplane
V1= FreeParameter("Drawing X position",Xpos)
V2= FreeParameter("Drawing Y position",Xpos)
V3= FreeParameter("Drawing length",Draw_len)
V4= FreeParameter("Drawing width",Draw_width)
V5= StringConstant(Assoc_layers$)
V6= StringConstant(Colors$)
V7= StringConstant(Name$)
Pc= PointXYZ(V1,V2,0)
Drawing= CreateDrawing(Pc,WsLowerLeft,V3,V4,V5,V6)
Stat= NameEntity(Drawing,V7)

Top_view:!
V1= FreeParameter("Top view X position",X2)
V2= FreeParameter("Top view Y position",Y2)
V3= FreeParameter("Top view X reference",0.0)
V4= FreeParameter("Top view Y reference",0.0)
V5= FreeParameter("Top view Z reference",0.0)
V6= FreeParameter("Top view scale",Vscale)
V7= FreeParameter("Top view x min",-Vlength)
V8= FreeParameter("Top view x max",Vlength)
V9= FreeParameter("Top view y min",-Vwidth)
V10= FreeParameter("Top view y max",Vwidth)
V11= FreeParameter("Top view z min",-Vheight)
V12= FreeParameter("Top view z max",Vheight)
V13= StringConstant("TOP VIEW")
V14= StringConstant(Top_layers$)
Ptopview= PointXYZ(V1,V2,0.0)
Pref= PointXYZ(V3,V4,V5)
Trans1= AngleTransform(Pc,0,0,0)
View1= MakeStoredView(V13,"",Trans1,-10,10,-10,10,-10,10)
stat= ChangeViewLayers(View1,V14)
Stat= AddViewToDrawing(Drawing,View1,Ptopview,Pref,V6,V7,V8,V9,V10,V11,V12)
Stat=DeleteEntity(Ptopview)
Stat=DeleteEntity(Pref)
Stat=DeleteEntity(Trans1)
Stat=DeleteEntity(View1)

Side_view:!
V1= FreeParameter("Side view X position",X3)
V2= FreeParameter("Side view Y position",Y3)
V3= FreeParameter("Side view X reference",0.0)
V4= FreeParameter("Side view Y reference",0.0)
V5= FreeParameter("Side view Z reference",0.0)
V6= FreeParameter("Side view scale",Vscale)
V7= FreeParameter("Side view x min",-Vlength)
V8= FreeParameter("Side view x max",Vlength)
V9= FreeParameter("Side view y min",-Vwidth)
V10= FreeParameter("Side view y max",Vwidth)
V11= FreeParameter("Side view z min",-Vheight)
V12= FreeParameter("Side view z max",Vheight)
V13= StringConstant("SIDE VIEW")
V14= StringConstant(Side_layers$)
Psideview= PointXYZ(V1,V2,0.0)
Pref= PointXYZ(V3,V4,V5)
Trans1= AngleTransform(Pc,0,90,0)
View1= MakeStoredView(V13,"",Trans1,-10,10,-10,10,-10,10)
stat= ChangeViewLayers(View1,V14)
Stat= AddViewToDrawing(Drawing,View1,Psideview,Pref,V6,V7,V8,V9,V10,V11,V12)
Stat=DeleteEntity(Psideview)
Stat=DeleteEntity(Pref)
Stat=DeleteEntity(Trans1)
Stat=DeleteEntity(View1)


Front_view:!
V1= FreeParameter("Front view X position",X1)
V2= FreeParameter("Front view Y position",Y1)
V3= FreeParameter("Front view X reference",0.0)
V4= FreeParameter("Front view Y reference",0.0)
V5= FreeParameter("Front view Z reference",0.0)
V6= FreeParameter("Front view scale",Vscale)
V7= FreeParameter("Front view x min",-Vlength)
V8= FreeParameter("Front view x max",Vlength)
V9= FreeParameter("Front view y min",-Vwidth)
V10= FreeParameter("Front view y max",Vwidth)
V11= FreeParameter("Front view z min",-Vheight)
V12= FreeParameter("Front view z max",Vheight)
V13= StringConstant("FRONT VIEW")
V14= StringConstant(Front_layers$)
Pfrontview= PointXYZ(V1,V2,0.0)
Pref= PointXYZ(V3,V4,V5)
Trans1= AngleTransform(Pc,-90,0,0)
View1= MakeStoredView(V13,"",Trans1,-10,10,-10,10,-10,10)
stat= ChangeViewLayers(View1,V14)
Stat= AddViewToDrawing(Drawing,View1,Pfrontview,Pref,V6,V7,V8,V9,V10,V11,V12)
Stat=DeleteEntity(Pfrontview)
Stat=DeleteEntity(Pref)
Stat=DeleteEntity(Trans1)
Stat=DeleteEntity(View1)


Iso_view:!
V1= FreeParameter("Iso view X position",X4)
V2= FreeParameter("Iso view Y position",Y4)
V3= FreeParameter("Iso view X reference",0.0)
V4= FreeParameter("Iso view Y reference",0.0)
V5= FreeParameter("Iso view Z reference",0.0)
V6= FreeParameter("Iso view scale",Vscale)
V7= FreeParameter("Iso view x min",-Vlength)
V8= FreeParameter("Iso view x max",Vlength)
V9= FreeParameter("Iso view y min",-Vwidth)
V10= FreeParameter("Iso view y max",Vwidth)
V11= FreeParameter("Iso view z min",-Vheight)
V12= FreeParameter("Iso view z max",Vheight)
V13= StringConstant("ISOMETRIC VIEW")
V14= StringConstant(Iso_layers$)
Pisoview= PointXYZ(V1,V2,0.0)
Pref= PointXYZ(V3,V4,V5)
Trans1= AngleTransform(Pc,60,0,30)
Trans2= InverseTrans(Trans1)
View1= MakeStoredView(V13,"",Trans2,-10,10,-10,10,-10,10)
stat= ChangeViewLayers(View1,V14)
Stat= AddViewToDrawing(Drawing,View1,Pisoview,Pref,V6,V7,V8,V9,V10,V11,V12)
Stat=DeleteEntity(Pisoview)
Stat=DeleteEntity(Pref)
Stat=DeleteEntity(Trans1)
Stat=DeleteEntity(Trans2)
Stat=DeleteEntity(View1)
Stat= SetActiveDrawing
RecordFunctionOff
CloseVarRecord
Stat= PlotDrawing(Drawing,1,WsTrue)
Stat= SetActiveDrawing(Drawing)

GOTO Leave

Leave:!
Stat=DeleteEntity(Ptopview)
Stat=DeleteEntity(Pfrontview)
Stat=DeleteEntity(Psideview)
Stat=DeleteEntity(Pisoview)
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_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






