/* @N This Genie will read one of several Avery Label databases contained in the PDraw/Data directory and allow the user to create a variety of labels. */ cr = '0a'x address command msg = PDSetup.rexx(2,0) units = getclip(pds_units) if msg ~= "1" then exit_msg(msg) sourcedir = ReadINI.rexx("FNT", "s:pdraw.ini") if sourcedir = '' then do directory = pdm_GetFileName("Please find Pdraw/Data..", "", "") if directory = '' then exit_msg("Unable to find label databases..") sourcedir = splitfilename.rexx(directory) end if right(sourcedir, 1) = ":" then sourcedir = sourcedir'Data/' else sourcedir = sourcedir'/Data/' labels = '' counter = 0 address command list = getdirlist.rexx(sourcedir, ".db") if list = '' then exit_msg("Unable to find label database. Please reinstall!") selection = pdm_SelectFromList("Select Type of label..", 35, 5, 0, list) if selection = '' then exit_msg() filename = sourcedir || selection".db" if ~open(file, filename, "r") then exit_msg("An error has occured reading database") call pdm_ShowStatus("Reading label database..") line = readln(file) if pos('LASER', line) ~= 0 then labeltype = laser else if pos('MATRIX', line) ~= 0 then labeltype = matrix else exit_msg("Invalid database file") spos = Pos('PAGESIZE', line) if spos ~= 0 then do line = substr(line, spos + 8) opageh = word(line, 2) opagev = word(line, 1) end else do opageh = 0 opagev = 0 end lcounter = 0 do while ~eof(file) line = strip(readln(file)) if line = '' | left(line, 2) = '\*' | left(line, 2) = '*/' then iterate lcounter = lcounter + 1 parse var line code ';' name ';' . code = strip(code) name = strip(name) text = code || copies(" ", max(1,12 - length(code))) || name lines.lcounter.0 = line lines.lcounter.1 = text labels = labels||cr||text end labels = delstr(labels,1,1) label = pdm_SelectFromList("Select Label..", 40, 10, 0, labels) if label = '' then exit_msg() do i = 0 to lcounter - 1 cline = lines.i.1 if cline = label then leave end line = lines.i.0 group = 0 if pdm_SelFirstObj() ~= 0 then group = pdm_Inform(2,"Would you like to tile the current selection to create labels?", "No","Yes") if labeltype = laser then do sline = compress(line) parse var sline pnum ';' type ';' lheight ';' lwid ';' cols ';' rows ';' topmarg ';' sidemarg ';' hpitch ';' vpitch ';' . if ~exists("rexx:TileSelection.pdrx") then exit_msg("Unable to locate Genie named: rexx:TileSelection.pdrx") npages = pdm_GetForm("How many pages will you need?", 8, "Pages:1") if npages = '' then exit_msg() if ~datatype(npages, n) then exit_msg("Invalid entry") newpage = pdm_CreatePage(pdm_CurrentPage() + 1,1,) call pdm_GotoPage(newpage) if opagev ~= 0 then do call pdm_SetPageSize(newpage, opagev, opageh) end if group = 1 then do call ScaleToPage(lwid, lheight, pdm_CurrentPage()) call pdm_GroupObj() call TileSelection.pdrx(sidemarg,topmarg,rows, cols, hpitch, vpitch) end else do obj = pdm_DrawRectangle(sidemarg, topmarg, sidemarg + lwid, topmarg + lheight) call pdm_SelectObj(obj) call TileSelection.pdrx(sidemarg, topmarg, rows, cols, hpitch, vpitch) end message = "Done" end else do sline = compress(line) parse var sline pnum ';' type ';' lheight ';' lwid ';' cols ';' cwidth ';' hpitch ';' vpitch ';' . npages = pdm_GetForm("How many Pages of Dot Matrix Labels?", 18, "Number of labels:"1) if npages = '' then exit_msg() if ~datatype(npages, n) then exit_msg("Invalid input") if vpitch < 1 then vpitch = 1 hspace = hpitch - lwid lmarg = (cwidth - (cols * hpitch - hpitch + lwid)) / 2 tmarg = (vpitch - lheight) / 2 newpage = pdm_CreatePage(pdm_CurrentPage() + 1,1,) call pdm_SetPageSize(newpage, cwidth, vpitch) call pdm_GotoPage(newpage) if group = 1 then do call ScaleToPage(lwid, lheight, pdm_CurrentPage()) call pdm_GroupObj() end else do obj = pdm_DrawRectangle(lmarg, tmarg, lmarg + lwid, tmarg + lheight) call pdm_SelectObj(obj) end call TileSelection.pdrx(lmarg,tmarg,1, cols, hpitch, vpitch) call pdm_SetDMEject(0) call pdm_SetDMPageSize(cwidth, vpitch) cwidth = pdm_ConvertUnits(1, units, cwidth) vpitch = pdm_ConvertUnits(1, units, vpitch) if units = 1 then unit = "inches" else if units = 2 then unit = "CM" else if units = 3 then unit = "Picas" message = "Done. The Dot Matrix Page Eject has been turned off and the output page size has been set to "cwidth" "unit" x "vpitch" "unit end npages = npages - 1 cpage = pdm_CurrentPage() do npages call pdm_CopyPage(cpage, cpage + 1, 1) cpage = cpage + 1 end exit_msg(message) exit_msg: procedure expose units do parse arg message if message ~= '' then call pdm_Inform(1,message,) call pdm_ClearStatus() call pdm_SetUnits(units) call pdm_AutoUpdate(1) exit end ScaleToPage: procedure do parse arg width, height, page objsize = pdm_GetObjVisSize() owidth = word(objsize, 1) oheight = word(objsize, 2) objpos = pdm_GetObjPosn() left = word(objpos, 1) top = word(objpos, 2) wscale = width / owidth hscale = height / oheight /* Want to keep aspect ratio, so use smaller scale factor for both */ if wscale > hscale then wscale = hscale else hscale = wscale call pdm_ScaleObj(, wscale, hscale) call pdm_SetObjPage(,page) return end