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

!A
!A NAME:
!A
!A 	Orients an entity based on Left or Right of a Point VARIATIONAL
!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 point NOT on the entity.
!B
!B	WHICH SIDE Left or Right:  Which side of 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

Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

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

Orient_point:!
stat= SetInputFormat("n4","")
E1=PickEntity("ORIENT POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Orient_point
Stat= EntityNameCheck(E1,Point$)
Pick_para= LastPickPara
Pick_return= CurrPickReturn

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,Element$)

RecordFunctionOn
Stat= RecordDescr("ORIENT: orient entity")
SELECT Pick_return
CASE WsGeometryEnd
        Pt= ParameterReturnPt(Point$,Pick_para,WsGeometryEnd)
CASE WsGeometryMid
        Pt= ParameterReturnPt(Point$,Pick_para,WsGeometryMid)
CASE WsGeomCenter
        Pt= ParameterReturnPt(Point$,Pick_para,WsGeomCenter)
END SELECT
V1= FreeParameter("Side",Which_side)
Stat= OrientEntity(Element$,Pt,V1)
Stat= DeleteEntity(Pt)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Point$)
Stat= PlotEntity(Element$)

Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Start

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

