
! script name: macros.d/rect2points
! EXAMPLE: construct rectangle between two points.

!A
!A NAME:
!A
!A 	Rectangle Two Points
!A
!A DESCRIPTION:
!A
!A 	This script constructs a rectangle between two points.
!A
!B INSTRUCTIONS:
!B
!B
!B 	CORNER RADIUS: Enter the radius to be used in all corners of the
!B 		rectangle.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: rectangle ")

DIM Answer$[256]
DIM Destination$[256]
DEG

DeActivateUndo
IF ARGC=2 THEN
	Answer$= UPC$(ARGV(1))
	IF POS(Answer$,"CHAMFER") THEN Chamfer_rect= 1
ELSE
	Chamfer_rect= 0
END IF

Start:!
IF Chamfer_rect THEN
	Chamfer=GetValue("CHAMFER ")
	IF (ExitScript(Destination$)) THEN Leave
ELSE
	Radius=InputRadius("CORNER RADIUS")
	IF (ExitScript(Destination$)) THEN Leave
	Stat=SetRadiusEquals(Radius)
END IF

Pick_loop:!
Vnum= LastPickView
L1=WorkplaneBox(Vnum)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(L1) THEN Pick_loop

Len1= LineLength(L1)
IF Len1< 0.0001 THEN
        Stat= DeleteEntity(L1)
        GOTO Start
END IF

PlotOff
Ps= ParameterPt(L1,0.0)
Pe= ParameterPt(L1,1.0)
Stat= DeleteEntity(L1)
PlotOn

Centerstart= WsFalse
IF Chamfer_rect THEN 
	Contour= RectangleTwoPts(Ps,Pe,Radius,WsCornerChamfer,WsFalse)
ELSE
	Contour= RectangleTwoPts(Ps,Pe,Radius,WsCornerFillet,WsFalse)
END IF
Stat= DeleteEntity(Ps,WsTrue)
Stat= DeleteEntity(Pe,WsTrue)

IF ValidGeometry(Contour) THEN
	Stat=AutoNumberCont(Contour)
END IF

GOTO Pick_loop

Leave:!
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(L1)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
