
! script name: stretch.d/aboxstretch
! topic: stretch elements along the angular direction

!A
!A NAME:
!A
!A 	Stretch Elements along the angular direction.
!A
!A DESCRIPTION:
!A
!A 	Stretch Elements along the angular direction.
!A
!B INSTRUCTIONS:
!B
!B 	PICK FIRST CORNER OF PICK ZONE: Pick a corner of the box to be used.
!B
!B 	PICK SECOND CORNER OF PICK ZONE: Pick the other corner of the box.
!B
!B 	ANGLE OF STRETCH:  Input angle to specify direction to stretch.
!B
!B 	ORIGIN POINT: Pick or input the origin point.
!B
!B 	DESTINATION POINT: Pick or input the destination point.  The distance
!B 		between these points projected along the angle direction will
!B 		determine the amount of stretch.
!B
!C NOTES:
!C
!C 	Stretching does not work with Types Geometry nor will it
!C 	work properly with trimmed spline entities.
!C
!C 	Stretching currently is only active on wire frame 3D elements.
!C 	it does not function with surfaces.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: stretch along a direction ")

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


DeActivateUndo
Stat= SetInputFormat("n4","")
Pick_loop:!
Stat=SetInputFormat("n4","")
Vnum=PickView("SELECT VIEW FOR SELECTION BOX")
IF (ExitScript(Destination$)) THEN Leave

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

Pt1= ParameterPt(L1,0.0)
Pt2= ParameterPt(L1,1.0)

Dist= DistTwoPts(Pt1,Pt2)
IF Dist< 0.0001 THEN Pick_loop

Angle=InputAngle("ANGLE OF STRETCH")
IF (ExitScript(Destination$)) THEN Leave

P1= XyzInput("ORIGIN POINT",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave

P2= XyzInput("DESTINATION POINT",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave

DEG
V1= PointXYZ(COS(Angle),SIN(Angle),0.0)
V2= VectorTwoPts(P1,P2)
D1= DotVectors(V1,V2)
Move_vector= ScaleVector(V1,D1)

Stat= BoxMoveEntities(pt1,pt2,Move_vector,WsXyOnly)

Stat= DeleteEntity(Pt1)
Stat= DeleteEntity(Pt2)
Stat= DeleteEntity(P1)
Stat= DeleteEntity(P2)
Stat= DeleteEntity(L1)
Stat= DeleteEntity(V1)
Stat= DeleteEntity(V2)
Stat= DeleteEntity(Move_vector)

GOTO Pick_loop

Leave:!
Stat= DeleteEntity(V1)
Stat= DeleteEntity(V2)
Stat= DeleteEntity(Pt1)
Stat= DeleteEntity(Pt2)
Stat= DeleteEntity(P1)
Stat= DeleteEntity(P2)
Stat= DeleteEntity(L1)
Stat= DeleteEntity(Move_vector)
Stat= SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
