
! script name: draft.d/textcircle
! topic: construct text along a circular arc

!A
!A NAME:
!A
!A 	Text Line
!A
!A DESCRIPTION:
!A
!A 	This script allows  text to be placed along a circular arc.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CIRCULAR ARC: Pick the circular arc.
!B
!B 	INPUT TEXT LINE: Enter the line of text to be placed starting at the
!B 		specified coordinates.
!B
!B	PICK WHICH SIDE: Pick the side the text points toward.
!B
!C NOTES:
!C	
!C 	The text always has the circle at the bottom of the text.
!C
!C 	The text is laid out in the direction of the circle description.
!C
!C 	EXTENDED CHARACTER SET: Characters may be input by their ascii
!C 		number. Type in \031 for example to use the character in
!C 		the font assigned to the ascii number 31. The code must be
!C 		a three digit number from 001 to 255.  Some of the extended
!C 		characters like the geometric tolerancing symbols take up more
!C 		than one space so they should be bracketed with extra spaces.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: text circle ")

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

DeActivateUndo
Text_centered= 1
Text_loop:!

Ecircle=PickSpecificEnt("PICK CIRCULAR ARC",WsPickCircles)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Ecircle) THEN text_loop

Stat=SetInputFormat("a99","",0)
Stat=GetValue("INPUT TEXT LINE",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Stat= BackSlashChars(Answer$,Text_line$)

Pt=InputFreePoint("PICK WHICH SIDE")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pt) THEN Line_loop

Pcenter= CircleCenter(Ecircle)
Theight= GetDefault(WsTextHeight)
Twidth= GetDefault(WsTextWidth)
Tangle= GetDefault(WsTextAngle)
Radius= CircleRadius(Ecircle)
Radius= ABS(Radius)
Clength= EntityLength(Ecircle)
Tspace= 0.0

R1= DistTwoPts(Pt,Pcenter)

Flip= (R1< Radius)

P1= PointXYZ(-Twidth/2,0,0)

Num1=LEN(Text_line$)

IF Text_centered THEN
	Text_length= Num1*Twidth+ (Num1-1)*Tspace
	Start_length= (Clength- Text_length+ Twidth)/2
ELSE
	Start_length= Twidth/2
END IF
FOR I=1 TO Num1
	C$= Text_line$[I;1]
	Text1=TextLine(P1,C$)
	L1= Start_length+ (I-1)*(Twidth+ Tspace)
	T= L1/Clength
	P2= ParameterPt(Ecircle,T)
	Line1= LineTwoPoints(Pcenter,P2,WsTrimmed)
	Angle= LineAngle(Line1) - 90 + Flip*180
	T1=AngleTransform(P2,0,0,Angle,WsWorkplaneVals)
	Text2=PTransformEntity(Text1,T1)

	Stat=DeleteEntity(P2)
	Stat=DeleteEntity(Text1)
	Stat=DeleteEntity(Line1)


NEXT I
Stat=DeleteEntity(P1)
Stat=DeleteEntity(Pcenter)
Stat=DeleteEntity(Pt)

GOTO Text_loop

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