
! script name: digitize.d/digitize
! topic: digitize a group of points

!A
!A NAME:
!A
!A 	Digitize
!A
!A DESCRIPTION:
!A
!A 	This script digitizes a group of points.  Synergy allows you to use
!A 	a digital pointing device for fast and easy point creation using a
!A 	tablet or drafting station.  Before you can begin digitizing, you
!A 	must first orient the device.  You must know the Cartesian values of
!A 	at least two points on item you want to digitize in order to orient
!A 	the pointing device.  You must manually leave this script by
!A 	choosing "Leave Script" when you have finished creating your points.
!A
!B INSTRUCTIONS:
!B
!B 	DIGITIZE REFERENCE 1: Digitize the first reference.
!B
!B 	DIGITIZE REFERENCE 2: Digitize the second reference.
!B
!B 	INPUT REFERENCE 1: Enter the absolute Cartesian values of x and y for
!B 		the first reference point.
!B
!B 	INPUT REFERENCE 2: Enter the Cartesian values of x and y for the
!B 		second reference point.
!B
!B 	DIGITIZE POINT: Digitize the point.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: digitize ")

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


DEG

DeActivateUndo

Tabletx= 16.54
Tablety= 11.6
Screenx= 1250
Screeny= 1024

x= Screenx/Tabletx
y= Screeny/Tablety
xscale= 1.0
yscale= x/y

Reference1:!
Stat=SetInputFormat("n4","")
Stat=SetXyzInput(WsXyzInput)
Pt=InputFreePoint("DIGITIZE REFERENCE 1")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pt) THEN reference1
GOSUB Convert_point
Point1=PointXYZ(X,Y,Z)

Reference2:Pt=InputFreePoint("DIGITIZE REFERENCE 2")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pt) THEN reference2
GOSUB Convert_point
Point2=PointXYZ(X,Y,Z)

Dist= DistTwoPts(Point1,Point2)
IF Dist< 0.0001 THEN
        stat= DeleteEntity(Point1)
        stat= DeleteEntity(Point2)
        GOTO Reference1
END IF

Reference1_pos:!
Stat=SetInputFormat("n4=","")
P1=XyzInput("INPUT REFERENCE 1 ",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(P1) THEN Reference1_pos
Stat=SetLastPoint(P1,WsXyzInput)

Reference2_pos:!
Stat=SetInputFormat("n4=","")
P2=XyzInput("INPUT REFERENCE 2 ",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(P2) THEN Reference2_pos
Stat=SetLastPoint(P2,WsXyzInput)

Dist= DistTwoPts(P1,P2)
IF Dist< 0.0001 THEN 
	stat= DeleteEntity(P1)
	stat= DeleteEntity(P2)
	GOTO Reference1_pos
END IF

D_Line= LineTwoPoints(Point1,Point2)
R_Line= LineTwoPoints(P1,P2)

Length1= LineLength(D_line)
Angle1=  LineAngle(D_line)
Length2= LineLength(R_line)
Angle2=  LineAngle(R_line)

Scal= Length2/Length1

PRINT "LENGTH1 =",Length1," ANGLE1 =",Angle1
PRINT "LENGTH2 =",Length2," ANGLE2 =",Angle2
PRINT "SCALE= ",Scal

X=-XPointValue(Point1)
Y=-YPointValue(Point1)
Z=0
Pc1=PointXYZ(X,Y,Z)
T1=AngleTransform(Pc1,0,0,0,WsWorkplaneVals)
Pz=PointXYZ(0,0,0)
T2=AngleTransform(Pz,0,0,-Angle1,WsWorkplaneVals)
T3=AngleTransform(Pz,0,0,Angle2,WsWorkplaneVals)
T4=AngleTransform(P1,0,0,0,WsWorkplaneVals)
T5=MultTransforms(T2,T1)
T6=MultTransforms(T3,T5)
Point_trans=MultTransforms(T4,T6)
Stat= DeleteEntity(T1)
Stat= DeleteEntity(T2)
Stat= DeleteEntity(T3)
Stat= DeleteEntity(T4)
Stat= DeleteEntity(T5)
Stat= DeleteEntity(T6)
Stat= DeleteEntity(D_line)
Stat= DeleteEntity(R_line)
Stat= DeleteEntity(Pc1)

Digitize_points:!

Group=CreateGroup("DIGITIZED POINTS")

Digitize_loop:!

Stat=SetInputFormat("n4","")
Pt=InputFreePoint("DIGITIZE POINT")
IF (ExitScript(Destination$)) THEN Transform_pts
IF NOT ValidGeometry(Pt) THEN Digitize_loop
GOSUB Convert_point
Pt=PointXYZ(X,Y,Z)

stat= AddToGroup(Group,Pt)

GOTO Digitize_loop


Transform_pts:!

Num_pts= GroupCount(Group)

IF Num_pts> 0 THEN
	Group2=TransformGroup(Group,Point_trans,"Digitized Points")
	Group3=ScaleGroup(Group2,P1,Scal)
	stat= DeleteGroup(Group,1)
	stat= DeleteGroup(Group2,1)
	stat= ChangeGrpName(Group3,"Digitized points")


ELSE
	stat= DeleteEntity(Group)
END IF



Stat= DeleteEntity(Point1)
Stat= DeleteEntity(Point2)
Stat= DeleteEntity(P1)
Stat= DeleteEntity(P2)
GOTO Leave

Convert_point:! Differentially scales axes
X=XPointValue(Pt)
Y=YPointValue(Pt)
X= X*Xscale
Y= Y*Yscale
Z=0
stat= DeleteEntity(Pt)
RETURN

Leave:!
Stat= DeleteEntity(T1)
Stat= DeleteEntity(T2)
Stat= DeleteEntity(T3)
Stat= DeleteEntity(T4)
Stat= DeleteEntity(T5)
Stat= DeleteEntity(T6)
Stat= DeleteEntity(Point1)
Stat= DeleteEntity(Point2)
Stat= DeleteEntity(D_line)
Stat= DeleteEntity(R_line)
Stat= DeleteEntity(Pz)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
