
! script name: vstretch.d/aboxstretch
! var_topic: stretch elements along an angular direction

!A
!A NAME:
!A
!A 	Angle Stretch          VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will stretch elements along an angular direction.
!A
!B INSTRUCTIONS:
!B
!B 	PICK FIRST CORNER OF PICK ZONE: Pick a
!B 		corner of the box to be used.
!B
!B 	PICK SECOND CORNER OF PICK ZONE: Pick
!B 		the other corner of the box.
!B
!B 	ANGLE OF STRETCH: Enter the angle
!B 		to specify the direction to stretch.
!B
!B 	ORIGIN POINT ABS X,Y: Pick or input
!B 		the X,Y coordinates of the origin point.
!B
!B 	DESTINATION POINT ABS X,Y: Pick or input
!B 		the X,Y coordinates of the destination point.
!B 		The distance between the origin and the destination
!B 		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 work properly
!C 	with trimmed spline entities.
!C
!C 	Stretching currently is only active on wire frame 3D elements; it does
!C 	not function with surfaces.
!C

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

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

Stat=SetInputFormat("n4","")

DeActivateUndo

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)

Stat=LineNumberIncr(1)
Output_script=0
Start_obj=0
Stat= DisplayMessage("CALCULATING CHANGES")
Stat=OutputAllObjects("tempscript","vstretch.d/aboxstretch",Start_obj,Output_script)
IF Stat=1 THEN Pick_loop

LOAD "tempscript"

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

