.net - Get paper size of the layer in autocad c# -
i have method create layout. want set width , height of layout can't find properties.
how , set dimension of layout ?
you need call setcanonicalmedianame correct paper size available. check sample below
[commandmethod("setclosestmedianamecmd")] public void setclosestmedianamecmd() { document doc = application.documentmanager.mdiactivedocument; database db = doc.database; editor ed = doc.editor; plotsettingsvalidator psv = plotsettingsvalidator.current; // let's first select device stringcollection devlist = psv.getplotdevicelist(); ed.writemessage("\n--- plotting devices ---"); (int = 0; < devlist.count; ++i) { ed.writemessage("\n{0} - {1}", i+1, devlist[i]); } promptintegeroptions opts = new promptintegeroptions( "\nenter device number: "); opts.lowerlimit = 1; opts.upperlimit = devlist.count; promptintegerresult pir = ed.getinteger(opts); if(pir.status != promptstatus.ok) return; string device = devlist[pir.value - 1]; promptdoubleoptions pdo1 = new promptdoubleoptions( "\nenter media height(mm): "); promptdoubleresult pdr1 = ed.getdouble(pdo1); if (pdr1.status != promptstatus.ok) return; promptdoubleoptions pdo2 = new promptdoubleoptions( "\nenter media width(mm): "); promptdoubleresult pdr2 = ed.getdouble(pdo2); if (pdr2.status != promptstatus.ok) return; using (transaction tx = db.transactionmanager.starttransaction()) { layoutmanager layoutmgr = layoutmanager.current; layout layout = tx.getobject( layoutmgr.getlayoutid(layoutmgr.currentlayout), openmode.forwrite) layout; setclosestmedianame( psv, device, layout, pdr1.value, pdr2.value, plotpaperunit.millimeters, true); tx.commit(); } } void setclosestmedianame(plotsettingsvalidator psv, string device, layout layout, double pagewidth, double pageheight, plotpaperunit units, bool matchprintablearea) { psv.setplottype( layout, autodesk.autocad.databaseservices.plottype.extents); psv.setplotpaperunits(layout, units); psv.setusestandardscale(layout, false); psv.setstdscaletype(layout, stdscaletype.scaletofit); psv.setplotconfigurationname(layout, device, null); psv.refreshlists(layout); stringcollection medialist = psv.getcanonicalmedianamelist(layout); double smallestoffset = 0.0; string selectedmedia = string.empty; plotrotation selectedrot = plotrotation.degrees000; foreach(string media in medialist) { psv.setcanonicalmedianame(layout, media); psv.setplotpaperunits(layout, units); double mediapagewidth = layout.plotpapersize.x; double mediapageheight = layout.plotpapersize.y; if(matchprintablearea) { mediapagewidth -= (layout.plotpapermargins.minpoint.x + layout.plotpapermargins.maxpoint.x); mediapageheight -= (layout.plotpapermargins.minpoint.y + layout.plotpapermargins.maxpoint.y); } plotrotation rotationtype = plotrotation.degrees090; //check not outside media print area if(mediapagewidth < pagewidth || mediapageheight < pageheight) { //check if 90°rot fit, otherwise check next media if(mediapageheight < pagewidth || mediapagewidth >= pageheight) { //too small, let's check next media continue; } //that's ok 90°rot fit rotationtype = plotrotation.degrees090; } double offset = math.abs( mediapagewidth * mediapageheight - pagewidth * pageheight); if (selectedmedia == string.empty || offset < smallestoffset) { selectedmedia = media; smallestoffset = offset; selectedrot = rotationtype; //found perfect match can quit if (smallestoffset == 0) break; } } psv.setcanonicalmedianame(layout, selectedmedia); psv.setplotrotation(layout, selectedrot); string localmedia = psv.getlocalemedianame( layout, selectedmedia); editor ed = application.documentmanager.mdiactivedocument.editor; ed.writemessage("\n - closest media: " + localmedia); ed.writemessage("\n - offset: " + smallestoffset.tostring()); ed.writemessage("\n - rotation: " + selectedrot.tostring()); }
Comments
Post a Comment