/* CMD: ½CreateXPoints                                                  */
/* By Brett Evan Hester      13032 Copenhill Rd. Dallas, Tx. 75240-5302 */
	MacrosName = "CreateXPoints"
/* Macro Type:                                                          */
/* CREATES     * OBJECTS   * SELECTED     * REMEMBERS                   */
/* Description:                                                         */

Info1A = "!Create X Points ©             Information 1 of 2"
Info1B = ""
Info1C = "@This macro creates multiple points between two  "
Info1D = "@selected points. The new points will be divided "
Info1E = "@evenly from point A to point B.                 "
Info1F = ""
Info1G = "þ ADD options defines how many points to add.   "
Info1H = ""
Info1I = ""
Info1J = ""
Info1K = ""
Info1L = ""
Info1M = "P.S. The number of points must be a positive    "
Info1N = "     whole number.                              "

Info2A = "!Create X Points ©             Information 2 of 2"
Info2B = "@               Plug-Ins and Go! ©               "
Info2C = "                           Hester and associates"
Info2D = "                           13032 Copenhill Road "
Info2E = "                           Dallas, Texas 75240  "
Info2F = "@Special Thanks to:                              "
Info2G = "Arnie Cachelin  Henry Ribron    Mark J. Holland "
Info2H = "J. Phil Kelso   Terry Wester    Steven K. Simms "
Info2I = "Kevin DeRita    Greg Glaser     William S. Hawes"
Info2J = "NewTek ©        Commodore ©     INOVAtronics ©  "
Info2K = ""
Info2L = "@This macro represents a lot of time & hard work."
Info2M = "@Encourage people to create new ones and not kill"
Info2N = "@that possibility by stealing those that are out."

/* -------------------------------------------------------------------- */
                                     /* Start Error Detection (See End) */
SIGNAL ON ERROR
SIGNAL ON SYNTAX
                                                   /* Address LightWave */
VT3DLib = ADDLIB("LWModelerARexx.port",0)
ADDRESS "LWModelerARexx.port"

/* -------------------------------------------------------------------- */
                            /* Checking / Verifing, two points selected */
CALL Sel_Mode(USER)

NumberOfPnts = XFrm_Begin()

IF NumberOfPnts ~= 2 THEN DO
	CALL Notify(1,"!Sorry!", "@Select exactly two points for this macro.")
	CALL Exiting
END

VectorA = Xfrm_GetPos(1) ; PARSE var VectorA XA YA ZA
VectorB = Xfrm_GetPos(2) ; PARSE var VectorB XB YB ZB

CALL XFrm_End
                  /* Calculating total distance between selected points */
Width = XB-XA ; Height = YB-YA ; Depth = ZB-ZA

/* -------------------------------------------------------------------- */
                                    /* Reading Global Macro Preferences */
BEHDefaultFilePath = "Sys:"
BEHSettingsSavedTo = "T:"
BEHSpeechAndSound = "1"

IF (EXISTS("S:PlugInPrefs")) THEN DO
	IF (~OPEN(PlugInPrefs, "S:PlugInPrefs", 'R')) THEN BREAK
	IF (READLN(PlugInPrefs) ~= "PlugInPrefs") THEN BREAK
	BEHDefaultFilePath = READLN(PlugInPrefs)
	BEHSettingsSavedTo = READLN(PlugInPrefs)
	BEHSpeechAndSound = READLN(PlugInPrefs)
	CALL CLOSE PlugInPrefs
END

/* -------------------------------------------------------------------- */
                                            /* Recalling Macro Settings */
ReqAdd = 1

PrefsFileName = BEHSettingsSavedTo||MacrosName||".PLUG"

IF (EXISTS(PrefsFileName)) THEN DO
	IF (~OPEN(PrefsFile, PrefsFileName, 'R')) THEN BREAK
	IF (READLN(PrefsFile) ~= MacrosName) THEN BREAK

	ReqAdd = READLN(PrefsFile)

	CALL CLOSE PrefsFile
END

/* -------------------------------------------------------------------- */
                                              /* For Information Window */
BEHInfo = 1
                      /* For Coming Back to Main Menu after Info Window */
DO WHILE BEHInfo

/* -------------------------------------------------------------------- */
                                                      /* User Interface */
	CALL Req_Begin("Create X Points ©")

	CALL Req_AddControl("",'T',"by Brett Hester","")
	ReqA = Req_AddControl("Add",'N',0)
	ReqB = Req_AddControl("",'CH', "Information")

	CALL Req_SetVal(ReqA, ReqAdd)
	CALL Req_SetVal(ReqB, 0)

	OKorCancel = Req_Post() ; IF OKorCancel = 0 THEN CALL Exiting

	ReqAdd = Req_GetVal(ReqA)
	BEHInfo = Req_GetVal(ReqB)

	CALL Req_End()

	IF BEHInfo = 1 THEN CALL InformationWindows

END

/* -------------------------------------------------------------------- */

IF ReqAdd < 0 THEN ReqAdd = 0
ReqAdd = TRUNC(ReqAdd)
BEHAdd = ReqAdd + 1

SegmentX = Width / BEHAdd
SegmentY = Height / BEHAdd
SegmentZ = Depth / BEHAdd

DX = XA ; DY = YA ; DZ = ZA

CALL Add_Begin

DO i=1 TO ReqAdd
	DX = DX + SegmentX ; DY = DY + SegmentY ; DZ = DZ + SegmentZ
	CALL Add_Point(DX DY DZ)
END

CALL Add_End

/* -------------------------------------------------------------------- */
                                            /* Recording Macro Settings */
IF (OPEN(PrefsFile, PrefsFileName, 'W')) THEN DO
	CALL WRITELN(PrefsFile, MacrosName)

	CALL WRITELN(PrefsFile, ReqAdd)

	CALL CLOSE PrefsFile
END

CALL Exiting

/* -------------------------------------------------------------------- */
                                                              /* Ending */
Exiting:

	IF (VT3DLib) THEN CALL remlib("LWModelerARexx.port")
	EXIT

RETURN

/* -------------------------------------------------------------------- */
                                                 /* Information Windows */
InformationWindows:

	OKorCancel = Notify(2, Info1A, Info1B, Info1C, Info1D, Info1E, Info1F, Info1G, Info1H, Info1I, Info1J, Info1K, Info1L, Info1M, Info1N)
	IF OKorCancel = 1 THEN CALL Notify(1, Info2A, Info2B, Info2C, Info2D, Info2E, Info2F, Info2G, Info2H, Info2I, Info2J, Info2K, Info2L, Info2M, Info2N)

RETURN

/* -------------------------------------------------------------------- */
                                                      /* Error Handling */
SYNTAX:
ERROR:

	ErrCode = RC
	ErrLine = SIGL
	ErrInfo = ERRORTEXT(ErrCode)

	Err1 = "!Sorry!"
	Err2 = "An Error has been detected"
	Err3 = "@þ Macro -            "
	Err4 = "@þ Line Number -      "
	Err5 = "@þ Error Code -       "
	Err6 = "@þ Error Description -"
	Err7 = "@¤ Please Inform -    "
	Err8 = '  "Error Notice"     '
	Err9 = "  13032 Copenhill Rd."
	Err10 = "  Dallas, TX. 75240  "

	Call Notify(1,Err1,Err2,Err3,MacrosName,Err4,ErrLine,Err5,ErrCode,Err6,ErrInfo,Err7,Err8,Err9,Err10)

/* -------------------------------------------------------------------- */
                                             /* Advanced Error Handling */
	CALL SETCLIP("ErrorMacro",MacrosName)
	CALL SETCLIP("ErrorLine",ErrLine)
	CALL SETCLIP("ErrorCode",ErrCode)
	CALL SETCLIP("ErrorDesc",ErrInfo)

	PARSE SOURCE TempA TempB ErrFile TempC TempD TempE

	CALL SETCLIP("ErrorFile",ErrFile)

/* -------------------------------------------------------------------- */

	IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
	EXIT
