
! script name: circles.d/oriententity
! topic: orients an entity based on Left or Right of a Point

!A
!A NAME:
!A
!A 	Orient Entity
!A
!A DESCRIPTION:
!A
!A 	This script orients an entity based on left or right of a point
!A
!B INSTRUCTIONS:
!B
!B 	PICK ENTITY: Pick the entity to be oriented.
!B
!B 	ORIENT POINT: Select an orientation
!B 		point NOT on the entity.
!B
!B 	WHICH SIDE Left or Right: Which side of
!B 		the element is the point on.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: orient entity ")

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

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

Orient_point:!
Stat=SetInputFormat("n4=","")
Pt=XyzInput("INPUT",WsXyzInput)
IF ExitScript(Destination$) THEN Leave

Stat= SetInputFormat("a1",",L,R,")
Stat=GetValue("WHICH SIDE Left or Right ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "L" THEN
	Which_side= WsLeft
ELSE
	Which_side= WsRight
END IF

ActivateUndo
Stat= AdvanceUndoNumber("orient entity")
Stat= AddItemToUndo(WsUBModifyMode,E1)

Stat= OrientEntity(E1,Pt,Which_side)
Stat= DeleteEntity(Pt)
Stat= PlotEntity(E1)

GOTO Start

Leave:!
Stat=SetInputFormat("n4","")
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END

