
! script name: points.d/offsetinter
! topic: create point at the offset intersection of two entities

!A
!A NAME:
!A
!A 	Offset Intersect
!A
!A DESCRIPTION:
!A
!A 	This script creates a point at the offset intersection of two
!A 	entities.
!A
!A~ image location - images/offsetintersectpt.jpg
!B INSTRUCTIONS:
!B
!B 	PICK FIRST ELEMENT: Pick the first  element.
!B
!B 	PICK NEXT ELEMENT: Pick the second element.
!B

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

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

Forward_color=3
Reverse_color=4

ActivateUndo
Pick_entity1:!
Stat= SetInputFormat("n4","")
Element1=PickEntity("PICK FIRST ELEMENT")
IF (ExitScript(Destination$)) THEN Leave
Selectpt=LastPickPoint
Para_value1= LastPickPara

Stat=SetInputFormat("n4=","")
Stat= SetEqualsValue(ABS(Offset1))
Offset1=GetValue("OFFSET FOR ELEMENT #1")
IF (ExitScript(Destination$)) THEN Leave
Offset1= ABS(Offset1)

IF Offset1 > 0.0 THEN
	Element= Element1
	Para_value= Para_value1
	Normal_len= ABS(Offset1)
	GOSUB Which_side
	Offset1= Offset1*Norm_sign
END IF

Pick_entity2:!
Stat= SetInputFormat("n4","")
Element2=PickEntity("PICK NEXT ELEMENT")
IF (ExitScript(Destination$)) THEN Leave
Para_value2= LastPickPara

Stat=SetInputFormat("n4=","")
Stat= SetEqualsValue(ABS(Offset2))
Offset2=GetValue("OFFSET FOR ELEMENT #2")
IF (ExitScript(Destination$)) THEN Leave
Offset2= ABS(Offset2)

IF Offset2 > 0.0 THEN
	Element= Element2
	Para_value= Para_value2
	Normal_len= ABS(Offset2)
	GOSUB Which_side
	Offset2= Offset2*Norm_sign
END IF


Offset_pt=OffsetIntersect(Element1,Offset1,Element2,Offset2,Selectpt)

Stat=DeleteEntity(Selectpt)

ActivateUndo
Stat= AdvanceUndoNumber("point")
Stat= AddItemToUndo(WsUBCreateMode,Offset_pt)
GOTO Pick_entity1



ShowNormalDir:!
        Forward_normal= ParameterLine(Element,Para_value,Normal_len,WsNormal)
        Pforward=ParameterPt(Forward_normal,1.0)
        Stat=SetColor(Forward_normal,Forward_color)
        Stat=SetColor(Pforward,Forward_color)

        Reverse_normal= ParameterLine(Element,Para_value,-Normal_len,WsNormal)
        Preverse=ParameterPt(Reverse_normal,1.0)
        Stat=SetColor(Reverse_normal,Reverse_color)
        Stat=SetColor(Preverse,Reverse_color)
RETURN

Which_side:!
        GOSUB ShowNormalDir
Pick_normal: L1=PickSpecificEnt("PICK WHICH SIDE OF ELEMENT",WsPickLines)
        IF ExitScript(Destination$) THEN Leave
        IF NOT ValidGeometry(L1) THEN Line_loop
        T1= LastPickPara
        Norm_sign=0
        Pc=ParameterPt(Forward_normal,0.0)
        Pt=ParameterPt(L1,T1)
        D1=DistTwoPts(Pt,Pforward)
        D2=DistTwoPts(Pt,Preverse)
        D3=DistTwoPts(Pt,Pc)
        IF D1<= D2 THEN
                Norm_sign=-1
                Norm_dir= WsInside
                IF D1< D3 THEN Norm_dir= WsOutside
        ELSE
                Norm_sign=1
                Norm_dir= WsInside
                IF D2< D3 THEN Norm_dir= WsOutside
        END IF
Stat=DeleteEntity(Forward_normal)
Stat=DeleteEntity(Reverse_normal)
Stat=DeleteEntity(Pt)
Stat=DeleteEntity(Pc)
Stat=DeleteEntity(Pforward)
Stat=DeleteEntity(Preverse)
RETURN


Leave:!
Stat=DeleteEntity(Forward_normal)
Stat=DeleteEntity(Reverse_normal)
Stat=DeleteEntity(Pt)
Stat=DeleteEntity(Pc)
Stat=DeleteEntity(Pforward)
Stat=DeleteEntity(Preverse)
Stat= SetInputFormat("n4","")
Stat=DeleteEntity(Selectpt)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

