'Simple Mass Printing '================================================ '=== The Script prepares and sends to printer === '=== a number of layouts using user template. === '================================================ '=== Core: Alexey Petrintchouk === 17/08/00 ===== '=== Checks and strings : A. Levin 30/05/02 ===== '================================================ '======================================================= '=== Any View for plotting must be an active Document == '=== In the View we have to have some polygon type ===== '=== theme that describes sheets of map. =============== '======================================================= '=== SCRIPT IS SENSITIVE TO SHEET THEME SELECTION!!! === '======================================================= '=== You can use fields of this theme as special ======= '=== layout labels storage. ============================ '=== The script is looking by default for fields:======= '=== ID, IDs, Region, Tot_Sh =========================== '=== Also you should have a layout that will be used === '=== as template. This one can include number of ======= '=== graphic texts. These texts will be replaced with == '=== contents of specified sheet theme fields while ==== '=== current sheet will be ============================= '=== processing. ======================================= '======================================================= '=== Use the following contents for the texts those ============================ '=== have to be substituted from special fields: ============================ '=== @#Sheet#@ - is replacing with ID field "Sheet number field" value ====== '=== @#IDs#@ - is replacing with IDs field ("Sheet Number String" field) === '=== @#Rs#@ - is replacing with Region field ("Region Russian" field) ====== '=== @#Tot_Sh#@ - is replacing with Tot_Sh field ("Total sheets" field) ==== '=== If the layout template contains no such text, no one will ================= '=== be replaced. You have to define View frame in the layout template ========= '=== with user specified scale, you need, and "Live link" ====================== '=== to the View. Then use the "Printer setup" command to ====================== '=== get printer settings you need. Turn on/off themes. ======================== '=============================================================================== '=== In the last of the script dialogs -"Printer Options" === '=== you can specify common folder and file name template === '=== for new print files. Don't use an extension in this === '=== file name template to get better result. A value of === '=== "Sheet Number" field and ".prt" extension will be added === '=== to file name template for each of sheets. ============== '=== In case you have no secified file name in the last ==== '=== dialog all number of processed sheets will be sent ==== '=== to the current printer directly.======================== '============================================================ theView = av.GetActiveDoc PHalt=False '================================= '=== Asking Input data we need === '================================= '=== Frames theme ================ fr = MsgBox.ChoiceAsString (theView.GetThemes,"Choose a Layout frames theme","") if(fr = nil)then Return nil end fr = fr.GetFtab if(fr.GetShapeClass.GetClassName <> "Polygon")then MsgBox.Info("this theme must be type of Polygon","Try again") Return nil end '=== Fields of the frames theme === '----- Looks for ID field --------- Num=fr.FindField("ID") if (Num=nil) then MsgBox.Info("ID field don't exist","NO FIELD") Num = MsgBox.ChoiceAsString (fr.GetFields,"Choose a field with Sheets Numbers",fr.asString) if(Num = nil)then PHalt = True end end if(Num <> nil)then FType = Num.GetType if (FType <> #FIELD_DECIMAL) then MsgBox.Info(Num.GetName++"="++FType.AsString,"WRONG FIELD TYPE") PHalt = True end end if (PHalt = True) then return nil end '----- Looks for IDs field --------- DSe=fr.FindField("IDs") if (DSe=nil) then MsgBox.Info("IDs field don't exist","NO FIELD") DSe = MsgBox.ChoiceAsString (fr.GetFields,"Choose a field with Sheet Number string",fr.asString) if(DSe = nil)then PHalt = True end end if(DSe <> nil)then FType = DSe.GetType if (FType <> #FIELD_CHAR) then MsgBox.Info(DSe.GetName++"="++FType.AsString,"WRONG FIELD TYPE") PHalt = True else FWidth = DSe.GetWidth if(FWidth > 16) then MsgBox.Info("Warning!"++DSe.GetName++"width > 16 ("+FWidth.AsString+"!)","FIELD WIDTH TOO BIG") end end end if (PHalt = True) then return nil end '----- Looks for Region field --------- DSr=fr.FindField("Region") if (DSr=nil) then MsgBox.Info("Region field don't exist","NO FIELD") DSr = MsgBox.ChoiceAsString (fr.GetFields,"Choose a field with Region",fr.asString) if(DSr = nil)then PHalt = True end end if(DSr <> nil)then FType = DSr.GetType if (FType <> #FIELD_CHAR) then MsgBox.Info(DSr.GetName++"="++FType.AsString,"WRONG FIELD TYPE") PHalt = True else FWidth = DSr.GetWidth if(FWidth > 58) then MsgBox.Info("Warning!"++DSr.GetName++"width > 58 ("+FWidth.AsString+"!)","FIELD WIDTH TOO BIG") end end end if (PHalt = True) then return nil end '----- Looks for Tot_Sh field --------- GPe=fr.FindField("Tot_Sh") if (GPe=nil) then MsgBox.Info("Tot_Sh field don't exist","NO FIELD") GPe = MsgBox.ChoiceAsString (fr.GetFields,"Choose a field with Total Sheets",fr.asString) if(GPe = nil)then PHalt = True end end if(GPe <> nil)then FType = GPe.GetType if (FType <> #FIELD_CHAR) then MsgBox.Info(GPe.GetName++"="++FType.AsString,"WRONG FIELD TYPE") PHalt = True else FWidth = GPe.GetWidth if(FWidth > 16) then MsgBox.Info("Warning!"++GPe.GetName++"width > 16 ("+FWidth.AsString+"!)","FIELD WIDTH TOO BIG") end end end if (PHalt = True) then return nil end '=== Layout template selecting === TMP = av.GetProject.FindGUI("Layout") if(TMP = nil)then MsgBox.Warning("This project doesn't contain any `Layout` GUI","") Return nil end TMP = av.GetProject.GetDocsWithGUI(TMP) if(TMP.Count = 0)then MsgBox.Warning("This project doesn't contain any Layouts!"+NL+"We have to have not less than one layout document to use that as a template.","") Return nil end Lay = MsgBox.ChoiceAsString (TMP,"Choose a Layout template","") if(Lay = nil)then Return nil end '=== Page/printer/print options setup === pr = Printer.The pr.SetFileName ("J:\Rus-China\printouts\theme_reg_") TMP = pr.Edit({Lay.GetName}) if((0 <= TMP).Not)then Return nil end pr_fn = pr.GetFileName.Clone '=== Getting the special text graphics from Layout template === Sheets = {} dr = {} gres = {} dses = {} dsrs = {} for each r in Lay.GetGraphics if(r.Is(GraphicText))then if(r.GetText = "@#Sheet#@")then Sheets.Add(r) elseif(r.GetText = "@#DrNum#@")then dr.Add(r) elseif(r.GetText = "@#Tot_sh#@")then gres.Add(r) elseif(r.GetText = "@#IDs#@")then dses.Add(r) elseif(r.GetText = "@#Rs#@")then dsrs.Add(r) end end end '================================================================= '=== If no records are selected, we'll work with whole table === '================================================================= BMP = fr.GetSelection.Clone if(fr.GetSelection.Count = 0)then BMP.SetAll end '==================================== '=== Main circle ==================== '==================================== for each r in BMP IDn=fr.ReturnValue(num,r) if (IDn>0) then '=== Getting values for current sheet === ext = fr.ReturnValue(fr.GetFields.Get(0),r).ReturnExtent sn = fr.ReturnValue(num,r).asString if (IDn<10) then Sn = "0" + sn end gre = fr.ReturnValue(gpe,r).asString dre = fr.ReturnValue(DSe,r).asString drr = fr.ReturnValue(DSr,r).asString '=== Zooming to current sheet === theView.GetDisplay.ZoomToRect(ext) '=== Setting our specified text containings === TMP = sn.Clone if (sn.Count=1) then TMP = "0"+TMP end TMP = "3"+TMP for each t in Sheets t.SetText(sn) end for each t in dr t.SetText(drt+TMP) end for each t in gres t.SetText(gre) end for each t in dses t.SetText(dre) end for each t in dsrs t.SetText(drr) end '================ '=== Plotting === '================ '=== File name === if(pr.GetFileName.Is(String))then if(pr.GetFileName.Count>0)then pr.SetFileName(pr_fn+sn) end end av.ShowMsg("Printing sheet"++sn++"of"++fr.getSelection.Count.asString) Lay.Print end end '===================================== '=== Restoring previous parameters === '===================================== for each t in Sheets t.SetText("@#Sheet#@") end for each t in dr t.SetText("@#DrNum#@") end for each t in GREs t.SetText("@#Tot_sh#@") end for each t in dses t.SetText("@#IDs#@") end for each t in dsrs t.SetText("@#Rs#@") end