
! script name: draft.d/pointdimension
! var_topic: construct point dimension

!A
!A NAME:
!A
!A 	Point Dimension
!A
!A DESCRIPTION:
!A
!A 	This script constructs a point dimension.
!A
!A~ image location - images/pointdim.gif
!A
!B INSTRUCTIONS:
!B
!B 	POINT LOCATION ABS X,Y: Enter the X,Y coordinates to 
!B 		be used for the start of the leader. An arrow will be
!B 		placed at this point.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	LEADER END ABS X,Y: Enter the X,Y coordinates
!B 		to be used for the end point of the leader.
!B
!# see also - htdocs/help.d/dynamicdim.htm
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: point dimension ")

DIM Answer$[256]
DIM Destination$[256]
DIM Dim_type$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Name$[256]
DIM Textflags$[20]
DEG

Start:!
Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Dynamic_position=1
Dim_type= Ws2DPointDim

Dim_loop:! 
stat= SetInputFormat("n4","")
Element1=PickEntity("POINT LOCATION")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Element1) THEN Dim_loop
T1= LastPickPara
Pick_return1= CurrPickReturn
Stat= EntityNameCheck(Element1,Point1$)
Pstart= ParameterReturnPt(Element1,T1,Pick_return1)

Input_method= CurrInputMethod
IF Input_method= WsLatheInput THEN
        Dim_type= Ws2DLathePointDim
ELSE
        Dim_type= Ws2DPointDim
END IF


IF Dynamic_position THEN
	Pend= PointXYZ(0,0,0)
ELSE
	Input_method= CurrInputMethod
        stat= SetXyzInput(WsFreePoint)
        Stat=SetLastPoint(Pstart)
        Pend=XyzInput("DIM LOCATION",WsXyOnly)
        stat= SetXyzInput(Input_method)
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT ValidGeometry(Pend) THEN Dim_loop
	Last_pick_ent= LastPickEnt
        Pick_para2= LastPickPara
        Pick_return2= CurrPickReturn
        IF NOT ValidDependency(Last_pick_ent) THEN
                 Point_reference=0
        ELSE
                 Stat= EntityNameCheck(Last_pick_ent,Point2$)
                 Point_reference=1
        END IF
END IF

IF Dynamic_position THEN
	PlotOff
	E1= PointDimension(Dim_type,Pstart,Pend,Pstart)
	PlotOn
	Stat=SetLastPoint(Pend)
	Stat=MakeInvisible(Pstart)
	Stat=MakeInvisible(Pend)
	IF NOT ValidGeometry(E1) THEN Dim_loop

        Which_end=1
        Vnum= LastPickView
        Stat= DynamicDimEdit(Vnum,E1,Which_end,"PICK LEADER END LOCATION",WsFalse)
	IF (ExitScript(Destination$)) THEN 
                Stat= DeleteEntity(E1)
                Stat=DeleteEntity(Pstart)
                Stat=DeleteEntity(Pend)
                GOTO Leave
        END IF
	Last_pick_ent= LastPickEnt
        Pick_para2= LastPickPara
        Pick_return2= CurrPickReturn
        IF NOT ValidDependency(Last_pick_ent) THEN
                 Point_reference=0
        ELSE
                 Stat= EntityNameCheck(Last_pick_ent,Point2$)
                 Point_reference=1
        END IF

	PlotOff
        Pend= ParameterPt(E1,1.0)
        Stat= DimTextFlagStr(E1,Textflags$)
        Stat= DeleteEntity(E1)
        PlotOn
ELSE
	Textflags$=""
END IF

P1= SubtractVectors(Pend,Pstart)
Stat= XYZPointValues(P1,X1,Y1,Z1)
Stat=DeleteEntity(P1)
Stat=DeleteEntity(Pstart)
Stat=DeleteEntity(Pend)

Stat= GenerateVarName("D",Name$)
RecordFunctionOn
Stat= RecordDescr("DIM: Point dimension")
Stat= SetRecDelLastExec
SELECT Pick_return1
CASE WsGeometryEnd
        Ps= ParameterReturnPt(Point1$,T1,WsGeometryEnd)
CASE WsGeometryMid
        Ps= ParameterReturnPt(Point1$,T1,WsGeometryMid)
CASE WsGeomCenter
        Ps= ParameterReturnPt(Point1$,T1,WsGeomCenter)
END SELECT
IF Point_reference THEN
        SELECT Pick_return2
        CASE WsGeometryEnd
                 Ploc= ParameterReturnPt(Point2$,Pick_para2,WsGeometryEnd)
        CASE WsGeometryMid
                 Ploc= ParameterReturnPt(Point2$,Pick_para2,WsGeometryMid)
        CASE WsGeomCenter
                 Ploc= ParameterReturnPt(Point2$,Pick_para2,WsGeomCenter)
        END SELECT
ELSE
        V1= FreeParameter("Xloc",X1)
        V2= FreeParameter("Yloc",Y1)
        Ploc= PtIncrXyz(Ps,V1,V2,Z1)
END IF
V4= StringConstant(Textflags$)
IF Input_method= WsLatheInput THEN
	E1= PointDimension(Ws2DLathePointDim,Ps,Ploc,Ps,V4)
ELSE
	E1= PointDimension(Ws2DPointDim,Ps,Ploc,Ps,V4)
END IF
Stat= NameEntity(E1,Name$)
Stat=DeleteEntityList(Ps,Ploc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(E1)
Stat= PlotEntity(Point1$)
IF NOT ValidGeometry(E1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("point dim")
	Stat= AddDimToUndo(WsUBCreateMode,E1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

GOTO Dim_loop

Leave:!
stat= SetInputFormat("n4","")
Stat=DeleteEntity(Pstart)
Stat=DeleteEntity(Pend)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	IF Destination$= "SCRIPTSTART" THEN Start
        IF Destination$= "BACKUP" THEN Start
	LOAD Destination$
END IF
END
