
! script name: offsets.d/offsetentity
! topic: creates an entity offset from a given entity

!A
!A NAME:
!A
!A 	offset entity
!A
!A DESCRIPTION:
!A
!A 	This script creates an element offset to a given entity.
!A
!B INSTRUCTIONS:
!B
!B 	PICK ELEMENT: Pick the element.
!B
!B

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

DIM Destination$[256]
DIM Answer$[256]
DIM Element$[256]
DIM Offset_var$[256]
DIM Name$[256]

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

ActivateUndo
Offset_dist:!
Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Offset_dist)
Offset=GetValue("OFFSET (+ right, - left)",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_offset_var= LastVariableInput(Offset_var$)

Pick_entity:!
Stat= SetInputFormat("n4a1",",O,")
Stat=SetPickMask(WsPickNoSurf)
Element=PickEntity("PICK ELEMENT    Offset ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="O" THEN Offset_dist
IF NOT ValidDependency(Element) THEN Pick_entity
Stat= EntityNameCheck(Element,Element$)

SELECT EntityType(Element)
CASE WsLineEnt
    Stat= GenerateVarName(WsLineEnt,Name$)
CASE WsCircleEnt
    Stat= GenerateVarName(WsCircleEnt,Name$)
CASE ELSE
    Stat= GenerateVarName(WsPtChainEnt,Name$)
END SELECT

RecordFunctionOn
Stat= RecordDescr("ENTITY: Offset")
Stat= SetRecDelLastExec
Stat= NullReference(Element$)
IF No_offset_var THEN
	V1= FreeParameter("Offset",Offset)
ELSE
	V1= FreeParameter("Offset",Offset_var$)
END IF
E1=OffsetEntity(Element$,V1)
Stat= NameEntity(E1,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(E1)  THEN
	DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("offset entity")
	Stat= AddItemToUndo(WsUBCreateMode,E1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
Stat= PlotEntity(E1)
GOTO Pick_entity

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

