
! script name: draft.d/alignruler
! topic: align ruler

!A
!A NAME:
!A
!A 	Align Ruler
!A
!A DESCRIPTION:
!A
!A 	This script allows the ruler to be aligned along an element.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ALIGNING ENTITY: Pick the entity to be used as the
!B 		reference for the ruler alignment.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: align ruler ")

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


Ruler_loop:!

Stat=SetInputFormat("n4=","")
E1=PickEntity("PICK ALIGNING ENTITY")
IF (ExitScript(Destination$)) THEN Leave

T1= LastPickPara
T1= (T1> 0.5)
Reverse_ang= (T1> 0.5)

Pc= ParameterPt(E1,T1)
Type_ent= EntityType(E1)

IF Type_ent=WsPointEnt OR Type_ent=WsHoleEnt THEN

	Stat=RulerCenter(Pc,0)
ELSE
	L1=TangentLine(E1,Pc,WsTRIMMED)
	Angle= LineAngle(L1)
	Angle= Angle+ 180*Reverse_ang
	Stat=RulerCenter(Pc,Angle)
	Stat=DeleteEntity(L1)
END IF
	
Stat=DeleteEntity(Pc)
stat= RulerToggle(1)

GOTO Ruler_loop

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