public static void CreateLayout(string name) { _AcAp.Document acDoc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database acCurDb = acDoc.Database; using (_AcDb.Transaction trans = acCurDb.TransactionManager.StartTransaction()) { // Reference the Layout Manager _AcDb.LayoutManager acLayoutMgr = _AcDb.LayoutManager.Current; // Create the new layout with default settings _AcDb.ObjectId objID = acLayoutMgr.CreateLayout(name); // Open the layout _AcDb.Layout layout = trans.GetObject(objID, _AcDb.OpenMode.ForRead) as _AcDb.Layout; // Set the layout current if it is not already if (layout.TabSelected == false) { acLayoutMgr.CurrentLayout = layout.LayoutName; } // Output some information related to the layout object acDoc.Editor.WriteMessage("\nTab Order: " + layout.TabOrder + "\nTab Selected: " + layout.TabSelected + "\nBlock Table Record ID: " + layout.BlockTableRecordId.ToString()); // Save the changes made trans.Commit(); } }
private void mainCreationLoop(List <_Area_v2> areas) { foreach (_Area_v2 area in areas) { string name = getAreaName(area); double scale = getAreaScale(area); _Ge.Point3d centerPoint = getAreaCenter(area); _Db.Layout lay = createLayoutandSetActive(name); //setLayoutPlotSettings(lay, "ISO_full_bleed_A3_(297.00_x_420.00_MM)", "monochrome.ctb", "DWG To PDF.pc3"); setLayoutPlotSettings(lay, "PDFCreator", "A3", "monochrome.ctb"); _Db.Viewport vp = layoutViewportGetter(lay); _Db.Extents2d ext = getMaximumExtents(lay); setViewportGeometry(vp, ext, 1.05); setViewportParameters(vp, scale, centerPoint); Dictionary <_Db.Layout, string> layouts = new Dictionary <_Db.Layout, string>(); layouts[lay] = name; plotDriver(layouts); removeLayout(lay); } _c.ed.Regen(); }
private _Db.Viewport layoutViewportGetter(_Db.Layout lay) { _Db.ObjectIdCollection viewIds = lay.GetViewports(); _Db.Viewport vp = null; foreach (_Db.ObjectId id in viewIds) { _Db.Viewport vp2 = _c.trans.GetObject(id, _Db.OpenMode.ForWrite) as _Db.Viewport; if (vp2 != null && vp2.Number == 2) { vp = vp2; break; } } if (vp == null) { _Db.BlockTableRecord btr = _c.trans.GetObject(lay.BlockTableRecordId, _Db.OpenMode.ForWrite) as _Db.BlockTableRecord; vp = new _Db.Viewport(); btr.AppendEntity(vp); _c.trans.AddNewlyCreatedDBObject(vp, true); vp.On = true; vp.GridOn = false; } return(vp); }
private _Db.Extents2d getMaximumExtents(_Db.Layout lay) { double div = lay.PlotPaperUnits == _Db.PlotPaperUnit.Inches ? 25.4 : 1.0; bool trigger = lay.PlotRotation == _Db.PlotRotation.Degrees090 || lay.PlotRotation == _Db.PlotRotation.Degrees270; var min = swapCoords(lay.PlotPaperMargins.MinPoint, trigger) / div; var max = (swapCoords(lay.PlotPaperSize, trigger) - swapCoords(lay.PlotPaperMargins.MaxPoint, trigger).GetAsVector()) / div; return(new _Db.Extents2d(min, max)); }
public _AcDb.ResultBuffer LayoutListSelected(_AcDb.ResultBuffer args) { if (args != null) { throw new TooFewArgsException(); } _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = doc.Database; //Editor ed = doc.Editor; //LayoutManager layoutMgr = LayoutManager.Current; List <string> layouts = new List <string>(); _AcDb.ResultBuffer res = new _AcDb.ResultBuffer(); using (_AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { _AcDb.DBDictionary layoutDic = (_AcDb.DBDictionary)tr.GetObject(db.LayoutDictionaryId, _AcDb.OpenMode.ForRead, openErased: false); foreach (_AcDb.DBDictionaryEntry entry in layoutDic) { _AcDb.Layout layout = (_AcDb.Layout)tr.GetObject(entry.Value, _AcDb.OpenMode.ForRead); string layoutName = layout.LayoutName; if (layout.TabSelected) { layouts.Add(layoutName); } } tr.Commit(); } layouts.Remove("Model"); if (0 < layouts.Count) { layouts.Sort(); foreach (string layoutName in layouts) { res.Add(new _AcDb.TypedValue((int)(_AcBrx.LispDataType.Text), layoutName)); } return(res); } else { return(null); } }
private void setLayoutPlotSettings(_Db.Layout lay, string device, string pageSize, string styleSheet) { using (_Db.PlotSettings plotSettings = new _Db.PlotSettings(lay.ModelType)) { plotSettings.CopyFrom(lay); _Db.PlotSettingsValidator validator = _Db.PlotSettingsValidator.Current; StringCollection devices = validator.GetPlotDeviceList(); if (devices.Contains(device)) { validator.SetPlotConfigurationName(plotSettings, device, null); validator.RefreshLists(plotSettings); } else { write("[WARNING] Device not found!"); } StringCollection paperSizes = validator.GetCanonicalMediaNameList(plotSettings); if (paperSizes.Contains(pageSize)) { validator.SetCanonicalMediaName(plotSettings, pageSize); } else { write("[WARNING] Paper not found!"); } StringCollection styleSheets = validator.GetPlotStyleSheetList(); if (styleSheets.Contains(styleSheet)) { validator.SetCurrentStyleSheet(plotSettings, styleSheet); } else { write("[WARNING] Style not found!"); } lay.CopyFrom(plotSettings); } }
/// <summary> /// Apply plot settings to the provided layout. /// </summary> /// <param name="pageSize">The canonical media name for our page size.</param> /// <param name="styleSheet">The pen settings file (ctb or stb).</param> /// <param name="devices">The name of the output device.</param> //public static void SetPlotSettings( // this _AcDb.Layout lay, string pageSize, string styleSheet, string device //) //{ // using (var ps = new _AcDb.PlotSettings(lay.ModelType)) // { // ps.CopyFrom(lay); // var psv = _AcDb.PlotSettingsValidator.Current; // // Set the device // var devs = psv.GetPlotDeviceList(); // if (devs.Contains(device)) // { // psv.SetPlotConfigurationName(ps, device, null); // psv.RefreshLists(ps); // } // // Set the media name/size // var mns = psv.GetCanonicalMediaNameList(ps); // if (mns.Contains(pageSize)) // { // psv.SetCanonicalMediaName(ps, pageSize); // } // // Set the pen settings // var ssl = psv.GetPlotStyleSheetList(); // if (ssl.Contains(styleSheet)) // { // psv.SetCurrentStyleSheet(ps, styleSheet); // } // // Copy the PlotSettings data back to the Layout // var upgraded = false; // if (!lay.IsWriteEnabled) // { // lay.UpgradeOpen(); // upgraded = true; // } // lay.CopyFrom(ps); // if (upgraded) // { // lay.DowngradeOpen(); // } // } //} /// <summary> /// Determine the maximum possible size for this layout. /// </summary> /// <returns>The maximum extents of the viewport on this layout.</returns> public static _AcDb.Extents2d GetMaximumExtents(this _AcDb.Layout lay) { // If the drawing template is imperial, we need to divide by // 1" in mm (25.4) var div = lay.PlotPaperUnits == _AcDb.PlotPaperUnit.Inches ? 25.4 : 1.0; // We need to flip the axes if the plot is rotated by 90 or 270 deg var doIt = lay.PlotRotation == _AcDb.PlotRotation.Degrees090 || lay.PlotRotation == _AcDb.PlotRotation.Degrees270; // Get the extents in the correct units and orientation var min = lay.PlotPaperMargins.MinPoint.Swap(doIt) / div; var max = (lay.PlotPaperSize.Swap(doIt) - lay.PlotPaperMargins.MaxPoint.Swap(doIt).GetAsVector()) / div; return(new _AcDb.Extents2d(min, max)); }
public void PlotLayout(_Db.Layout lay, string location) { using (_Pl.PlotInfo plotInfo = new _Pl.PlotInfo()) { plotInfo.Layout = lay.ObjectId; using (_Db.PlotSettings plotSettings = new _Db.PlotSettings(lay.ModelType)) { plotSettings.CopyFrom(lay); plotInfo.OverrideSettings = plotSettings; _Db.PlotSettingsValidator plotValidator = _Db.PlotSettingsValidator.Current; using (_Pl.PlotInfoValidator infoValidator = new _Pl.PlotInfoValidator()) { infoValidator.MediaMatchingPolicy = _Pl.MatchingPolicy.MatchEnabled; infoValidator.Validate(plotInfo); using (_Pl.PlotProgressDialog dialog = new _Pl.PlotProgressDialog(false, 1, true)) { write("Plotting: " + _c.doc.Name + " - " + lay.LayoutName); engine.BeginPlot(dialog, null); engine.BeginDocument(plotInfo, _c.doc.Name, null, 1, true, location); using (_Pl.PlotPageInfo pageInfo = new _Pl.PlotPageInfo()) { engine.BeginPage(pageInfo, plotInfo, true, null); } engine.BeginGenerateGraphics(null); engine.EndGenerateGraphics(null); engine.EndPage(null); engine.EndDocument(null); engine.EndPlot(null); } } } } }
private _Db.Layout createLayoutandSetActive(string name) //EH? { string randomName = generateRandomString(20); _Db.ObjectId id = layoutManager.GetLayoutId(randomName); if (!id.IsValid) { id = layoutManager.CreateLayout(randomName); } else { write("Layout " + randomName + " already exists."); } _Db.Layout layout = _c.trans.GetObject(id, _Db.OpenMode.ForWrite) as _Db.Layout; if (layout.TabSelected == false) { layoutManager.CurrentLayout = randomName; } return(layout); }
/// <summary> /// Applies an action to the specified viewport from this layout. /// Creates a new viewport if none is found withthat number. /// </summary> /// <param name="tr">The transaction to use to open the viewports.</param> /// <param name="vpNum">The number of the target viewport.</param> /// <param name="f">The action to apply to each of the viewports.</param> public static void ApplyToViewport( this _AcDb.Layout lay, _AcDb.Transaction tr, int vpNum, Action <_AcDb.Viewport> f ) { var vpIds = lay.GetViewports(); _AcDb.Viewport vp = null; foreach (_AcDb.ObjectId vpId in vpIds) { var vp2 = tr.GetObject(vpId, _AcDb.OpenMode.ForWrite) as _AcDb.Viewport; if (vp2 != null && vp2.Number == vpNum) { // We have found our viewport, so call the action vp = vp2; break; } } if (vp == null) { // We have not found our viewport, so create one var btr = (_AcDb.BlockTableRecord)tr.GetObject( lay.BlockTableRecordId, _AcDb.OpenMode.ForWrite ); vp = new _AcDb.Viewport(); // Add it to the database btr.AppendEntity(vp); tr.AddNewlyCreatedDBObject(vp, true); // Turn it - and its grid - on vp.On = true; vp.GridOn = true; } // Finally we call our function on it f(vp); }
private static bool PlotDwf(_AcDb.Layout lo, string dwfName) { try { var logMsg = string.Format("Erzeuge DWF-Datei für Layout '{0}'.", lo.LayoutName); log.Info(logMsg); _Editor.WriteMessage("\n" + logMsg); if (File.Exists(dwfName)) { File.Delete(dwfName); } var pi = new _AcPl.PlotInfo(); pi.Layout = lo.Id; var ps = new _AcDb.PlotSettings(lo.ModelType); ps.CopyFrom(lo); var psv = _AcDb.PlotSettingsValidator.Current; psv.SetPlotConfigurationName(ps, _PlotterName, null); SetClosestMediaName(psv, _PlotterName, ps, lo.PlotPaperSize.X, lo.PlotPaperSize.Y, _AcDb.PlotPaperUnit.Millimeters, true); psv.SetPlotCentered(ps, true); pi.OverrideSettings = ps; var piv = new _AcPl.PlotInfoValidator(); piv.MediaMatchingPolicy = _AcPl.MatchingPolicy.MatchEnabled; piv.Validate(pi); // You probably need to make sure background plotting is disabled. If the BACKGROUNDPLOT sysvar is set to 1 or 3, then PLOT will background plot (which is not what you want). // A PlotEngine does the actual plotting // (can also create one for Preview) if (_AcPl.PlotFactory.ProcessPlotState == _AcPl.ProcessPlotState.NotPlotting) { var pe = _AcPl.PlotFactory.CreatePublishEngine(); using (pe) { // Create a Progress Dialog to provide info // and allow the user to cancel var ppd = new _AcPl.PlotProgressDialog(false, 1, true); using (ppd) { ppd.set_PlotMsgString(_AcPl.PlotMessageIndex.DialogTitle, "Plot Fortschritt"); ppd.set_PlotMsgString(_AcPl.PlotMessageIndex.CancelJobButtonMessage, "Plot Abbrechen"); ppd.set_PlotMsgString(_AcPl.PlotMessageIndex.CancelSheetButtonMessage, "Sheet Abbrechen"); ppd.set_PlotMsgString(_AcPl.PlotMessageIndex.SheetSetProgressCaption, "Sheet Set Fortschritt"); ppd.set_PlotMsgString(_AcPl.PlotMessageIndex.SheetProgressCaption, "Sheet Fortschritt"); ppd.LowerPlotProgressRange = 0; ppd.UpperPlotProgressRange = 100; ppd.PlotProgressPos = 0; // Let's start the plot, at last ppd.OnBeginPlot(); ppd.IsVisible = true; pe.BeginPlot(ppd, null); // We'll be plotting a single document pe.BeginDocument(pi, _Doc.Name, null, 1, true, dwfName); // Which contains a single sheet ppd.OnBeginSheet(); ppd.LowerSheetProgressRange = 0; ppd.UpperSheetProgressRange = 100; ppd.SheetProgressPos = 0; var ppi = new _AcPl.PlotPageInfo(); pe.BeginPage(ppi, pi, true, null); pe.BeginGenerateGraphics(null); pe.EndGenerateGraphics(null); // Finish the sheet pe.EndPage(null); ppd.SheetProgressPos = 100; ppd.OnEndSheet(); // Finish the document pe.EndDocument(null); // And finish the plot ppd.PlotProgressPos = 100; ppd.OnEndPlot(); pe.EndPlot(null); } } } else { var msg = string.Format("Fehler beim Plot von Layout '{0}' in Zeichnung '{1}'! Es wird gerade geplottet!", lo.LayoutName, _Doc.Name); log.Warn(msg); _Editor.WriteMessage("\n" + msg); return(false); } } catch (Exception ex) { var msg = string.Format("Fehler beim Plot von Layout '{0}' in Zeichnung '{1}'! {2}", lo.LayoutName, _Doc.Name, ex.Message); log.Warn(msg); _Editor.WriteMessage("\n" + msg); return(false); } _NrPlots++; return(true); }
private void removeLayout(_Db.Layout lay) { layoutManager.DeleteLayout(lay.LayoutName); layoutManager.CurrentLayout = "Model"; }
public static void ImportLayout(string layoutName, string filename) { // Get the current document and database _AcAp.Document acDoc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database acCurDb = acDoc.Database; // Specify the layout name and drawing file to work with //string layoutName = "MAIN AND SECOND FLOOR PLAN"; //string filename = "C:\\AutoCAD\\Sample\\Sheet Sets\\Architectural\\A-01.dwg"; // Create a new database object and open the drawing into memory _AcDb.Database acExDb = new _AcDb.Database(false, true); acExDb.ReadDwgFile(filename, Autodesk.AutoCAD.DatabaseServices.FileOpenMode.OpenForReadAndAllShare, true, ""); // Create a transaction for the external drawing using (_AcDb.Transaction acTransEx = acExDb.TransactionManager.StartTransaction()) { // Get the layouts dictionary _AcDb.DBDictionary layoutsEx = acTransEx.GetObject(acExDb.LayoutDictionaryId, _AcDb.OpenMode.ForRead) as _AcDb.DBDictionary; // Check to see if the layout exists in the external drawing if (layoutsEx.Contains(layoutName) == true) { // Get the layout and block objects from the external drawing _AcDb.Layout layEx = layoutsEx.GetAt(layoutName).GetObject(_AcDb.OpenMode.ForRead) as _AcDb.Layout; _AcDb.BlockTableRecord blkBlkRecEx = acTransEx.GetObject(layEx.BlockTableRecordId, _AcDb.OpenMode.ForRead) as _AcDb.BlockTableRecord; // Get the objects from the block associated with the layout _AcDb.ObjectIdCollection idCol = new _AcDb.ObjectIdCollection(); foreach (_AcDb.ObjectId id in blkBlkRecEx) { idCol.Add(id); } // Create a transaction for the current drawing using (_AcDb.Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Get the block table and create a new block // then copy the objects between drawings _AcDb.BlockTable blkTbl = acTrans.GetObject(acCurDb.BlockTableId, _AcDb.OpenMode.ForWrite) as _AcDb.BlockTable; using (_AcDb.BlockTableRecord blkBlkRec = new _AcDb.BlockTableRecord()) { int layoutCount = layoutsEx.Count - 1; blkBlkRec.Name = "*Paper_Space" + layoutCount.ToString(); blkTbl.Add(blkBlkRec); acTrans.AddNewlyCreatedDBObject(blkBlkRec, true); acExDb.WblockCloneObjects(idCol, blkBlkRec.ObjectId, new _AcDb.IdMapping(), _AcDb.DuplicateRecordCloning.Ignore, false); // Create a new layout and then copy properties between drawings _AcDb.DBDictionary layouts = acTrans.GetObject(acCurDb.LayoutDictionaryId, _AcDb.OpenMode.ForWrite) as _AcDb.DBDictionary; using (_AcDb.Layout lay = new _AcDb.Layout()) { lay.LayoutName = layoutName; lay.AddToLayoutDictionary(acCurDb, blkBlkRec.ObjectId); acTrans.AddNewlyCreatedDBObject(lay, true); lay.CopyFrom(layEx); _AcDb.DBDictionary plSets = acTrans.GetObject(acCurDb.PlotSettingsDictionaryId, _AcDb.OpenMode.ForRead) as _AcDb.DBDictionary; // Check to see if a named page setup was assigned to the layout, // if so then copy the page setup settings if (lay.PlotSettingsName != "") { // Check to see if the page setup exists if (plSets.Contains(lay.PlotSettingsName) == false) { plSets.UpgradeOpen(); using (_AcDb.PlotSettings plSet = new _AcDb.PlotSettings(lay.ModelType)) { plSet.PlotSettingsName = lay.PlotSettingsName; plSet.AddToPlotSettingsDictionary(acCurDb); acTrans.AddNewlyCreatedDBObject(plSet, true); _AcDb.DBDictionary plSetsEx = acTransEx.GetObject(acExDb.PlotSettingsDictionaryId, _AcDb.OpenMode.ForRead) as _AcDb.DBDictionary; _AcDb.PlotSettings plSetEx = plSetsEx.GetAt(lay.PlotSettingsName).GetObject(_AcDb.OpenMode.ForRead) as _AcDb.PlotSettings; plSet.CopyFrom(plSetEx); } } } } } // Regen the drawing to get the layout tab to display acDoc.Editor.Regen(); // Save the changes made acTrans.Commit(); } } else { // Display a message if the layout could not be found in the specified drawing acDoc.Editor.WriteMessage("\nLayout '" + layoutName + "' could not be imported from '" + filename + "'."); } // Discard the changes made to the external drawing file acTransEx.Abort(); } // Close the external drawing file acExDb.Dispose(); }
private void ReplaceLayerInEntities(Dictionary <string, string> substDict, _AcDb.Transaction trans, _AcDb.Database db) { //string oldLayer = linfo.OldLayer; //string newLayer = linfo.NewLayer; _AcDb.BlockTable blkTable = (_AcDb.BlockTable)trans.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead); foreach (var id in blkTable) { _AcDb.BlockTableRecord btRecord = (_AcDb.BlockTableRecord)trans.GetObject(id, _AcDb.OpenMode.ForRead); //System.Diagnostics.Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Block: {0}", btRecord.Name)); //btRecord.UpgradeOpen(); foreach (var entId in btRecord) { _AcDb.Entity entity = (_AcDb.Entity)trans.GetObject(entId, _AcDb.OpenMode.ForWrite); CheckSetLayer(substDict, entity); //if (string.Compare(entity.Layer, oldLayer, StringComparison.OrdinalIgnoreCase) == 0) //{ // entity.Layer = newLayer; //} _AcDb.BlockReference block = entity as _AcDb.BlockReference; if (block != null) { // sequend correction string saveLay = block.Layer; block.Layer = "0"; block.Layer = saveLay; foreach (var att in block.AttributeCollection) { _AcDb.ObjectId attOid = (_AcDb.ObjectId)att; _AcDb.AttributeReference attrib = trans.GetObject(attOid, _AcDb.OpenMode.ForWrite) as _AcDb.AttributeReference; if (attrib != null) { CheckSetLayer(substDict, attrib); //if (string.Compare(attrib.Layer, oldLayer, StringComparison.OrdinalIgnoreCase) == 0) //{ // attrib.Layer = newLayer; //} } } } } //} } // Layouts iterieren _AcDb.DBDictionary layoutDict = (_AcDb.DBDictionary)trans.GetObject(db.LayoutDictionaryId, _AcDb.OpenMode.ForRead); foreach (var loEntry in layoutDict) { if (loEntry.Key.ToUpperInvariant() == "MODEL") { continue; } _AcDb.Layout lo = (_AcDb.Layout)trans.GetObject(loEntry.Value, _AcDb.OpenMode.ForRead, false); if (lo == null) { continue; } //System.Diagnostics.Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Layout: {0}", lo.LayoutName)); _AcDb.BlockTableRecord btRecord = (_AcDb.BlockTableRecord)trans.GetObject(lo.BlockTableRecordId, _AcDb.OpenMode.ForRead); foreach (var entId in btRecord) { _AcDb.Entity entity = (_AcDb.Entity)trans.GetObject(entId, _AcDb.OpenMode.ForWrite); CheckSetLayer(substDict, entity); //if (string.Compare(entity.Layer, oldLayer, StringComparison.OrdinalIgnoreCase) == 0) //{ // entity.Layer = newLayer; //} _AcDb.BlockReference block = entity as _AcDb.BlockReference; if (block != null) { string saveLay = block.Layer; block.Layer = "0"; block.Layer = saveLay; foreach (var att in block.AttributeCollection) { _AcDb.ObjectId attOid = (_AcDb.ObjectId)att; _AcDb.AttributeReference attrib = trans.GetObject(attOid, _AcDb.OpenMode.ForWrite) as _AcDb.AttributeReference; if (attrib != null) { CheckSetLayer(substDict, attrib); //if (string.Compare(attrib.Layer, oldLayer, StringComparison.OrdinalIgnoreCase) == 0) //{ // //attrib.UpgradeOpen(); // attrib.Layer = newLayer; //} } } } } } }
public static void SetPlotSettings(this _AcDb.Layout lay, string device, string mediaName, string styleSheet, double?scaleNumerator, double?scaleDenominator, short?rotation) { using (var ps = new _AcDb.PlotSettings(lay.ModelType)) { ps.CopyFrom(lay); var psv = _AcDb.PlotSettingsValidator.Current; // Set the device if (!string.IsNullOrEmpty(device)) { var devs = psv.GetPlotDeviceList(); if (devs.ContainsIgnoreUc(ref device)) { log.InfoFormat(CultureInfo.CurrentCulture, "Setze Device '{0}' für Layout '{1}'.", device, lay.LayoutName); psv.SetPlotConfigurationName(ps, device, null); psv.RefreshLists(ps); } else { log.WarnFormat(CultureInfo.CurrentCulture, "Device '{0}' existiert nicht!", device); } } // Set the media name/size if (!string.IsNullOrEmpty(mediaName)) { var mns = psv.GetCanonicalMediaNameList(ps); if (mns.ContainsIgnoreUc(ref mediaName)) { log.InfoFormat(CultureInfo.CurrentCulture, "Setze PageSize '{0}' für Layout '{1}'.", mediaName, lay.LayoutName); psv.SetCanonicalMediaName(ps, mediaName); } else { string canonicalMediaName = LocaleToCanonicalMediaName(psv, ps, mediaName); if (!string.IsNullOrEmpty(canonicalMediaName)) { log.InfoFormat(CultureInfo.CurrentCulture, "Setze PageSize '{0}' für Layout '{1}'.", canonicalMediaName, lay.LayoutName); psv.SetCanonicalMediaName(ps, canonicalMediaName); } else { log.WarnFormat(CultureInfo.CurrentCulture, "Size '{0}' existiert nicht!", mediaName); } } } // Set the pen settings if (!string.IsNullOrEmpty(styleSheet)) { var ssl = psv.GetPlotStyleSheetList(); if (ssl.ContainsIgnoreUc(ref styleSheet)) { log.InfoFormat(CultureInfo.CurrentCulture, "Setze StyleSheet '{0}' für Layout '{1}'.", styleSheet, lay.LayoutName); psv.SetCurrentStyleSheet(ps, styleSheet); } else { log.WarnFormat(CultureInfo.CurrentCulture, "Stylesheet '{0}' existiert nicht!", mediaName); } } // Copy the PlotSettings data back to the Layout if (scaleNumerator.HasValue && scaleDenominator.HasValue) { log.InfoFormat(CultureInfo.CurrentCulture, "Setze Scale '{0}:{2}' für Layout '{1}'.", scaleNumerator.Value.ToString(), lay.LayoutName, scaleDenominator.Value.ToString()); _AcDb.CustomScale cs = new _AcDb.CustomScale(scaleNumerator.Value, scaleDenominator.Value); if (ps.PlotPaperUnits != _AcDb.PlotPaperUnit.Millimeters) { psv.SetPlotPaperUnits(ps, _AcDb.PlotPaperUnit.Millimeters); } psv.SetCustomPrintScale(ps, cs); } if (rotation.HasValue && (rotation.Value == 0 || rotation.Value == 90 || rotation.Value == 180 || rotation.Value == 270)) { _AcDb.PlotRotation pRot = _AcDb.PlotRotation.Degrees000; switch (rotation.Value) { case 90: pRot = _AcDb.PlotRotation.Degrees090; break; case 180: pRot = _AcDb.PlotRotation.Degrees180; break; case 270: pRot = _AcDb.PlotRotation.Degrees270; break; case 0: default: break; } log.InfoFormat(CultureInfo.CurrentCulture, "Setze Rotation '{0}' für Layout '{1}'.", pRot.ToString(), lay.LayoutName); psv.SetPlotRotation(ps, pRot); } // plottype hardcoded auf fenster try { if (ps.PlotType != _AcDb.PlotType.Window) { if (ps.PlotWindowArea.ToString() == "((0,0),(0,0))") { _AcDb.Extents2d e2d = new _AcDb.Extents2d(0.0, 0.0, 10.0, 10.0); psv.SetPlotWindowArea(ps, e2d); } psv.SetPlotType(ps, _AcDb.PlotType.Window); } } catch (Exception ex) { log.ErrorFormat(CultureInfo.CurrentCulture, "Fehler beim Setzen von PlotType auf FENSTER! {0}", ex.Message); } var upgraded = false; if (!lay.IsWriteEnabled) { lay.UpgradeOpen(); upgraded = true; } lay.CopyFrom(ps); if (upgraded) { lay.DowngradeOpen(); } } }
//[_AcTrx.CommandMethod("ListLayouts")] public static void ListLayoutsMethod() { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = doc.Database; _AcEd.Editor ed = doc.Editor; _AcDb.LayoutManager layoutMgr = _AcDb.LayoutManager.Current; ed.WriteMessage ( String.Format ( "{0}Active Layout is : {1}", Environment.NewLine, layoutMgr.CurrentLayout ) ); ed.WriteMessage ( String.Format ( "{0}Number of Layouts: {1}{0}List of all Layouts:", Environment.NewLine, layoutMgr.LayoutCount ) ); using (_AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { _AcDb.DBDictionary layoutDic = tr.GetObject( db.LayoutDictionaryId, _AcDb.OpenMode.ForRead, false ) as _AcDb.DBDictionary; foreach (_AcDb.DBDictionaryEntry entry in layoutDic) { _AcDb.ObjectId layoutId = entry.Value; _AcDb.Layout layout = tr.GetObject( layoutId, _AcDb.OpenMode.ForRead ) as _AcDb.Layout; ed.WriteMessage( String.Format( "{0}--> {1}", Environment.NewLine, layout.LayoutName ) ); } tr.Commit(); } }
//[_AcTrx.CommandMethod("SaveView")] //public static void SaveView() //{ // Globs.SaveView("Test"); //} //[_AcTrx.CommandMethod("RestoreView")] //public static void RestoreView() //{ // Globs.RestoreView("Test"); //} //[_AcTrx.CommandMethod("TestMakeLayer")] public void TestMakeLayer() { var doc = _AcAp.Application.DocumentManager.MdiActiveDocument; var db = doc.Database; var layerOid = CreateNewLayer(doc, db); using (_AcDb.Transaction trans = doc.TransactionManager.StartTransaction()) { _AcDb.BlockTable blkTable = (_AcDb.BlockTable)trans.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead); foreach (var id in blkTable) { _AcDb.BlockTableRecord btRecord = (_AcDb.BlockTableRecord)trans.GetObject(id, _AcDb.OpenMode.ForRead); //if (!btRecord.IsLayout) //{ //Access to the block (not model/paper space) System.Diagnostics.Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Block: {0}", btRecord.Name)); //MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nBlock name: {0}", btRecord.Name)); btRecord.UpgradeOpen(); foreach (var entId in btRecord) { _AcDb.Entity entity = (_AcDb.Entity)trans.GetObject(entId, _AcDb.OpenMode.ForRead); entity.UpgradeOpen(); //Access to the entity //MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nHandle: {0}", entity.Handle)); //System.Diagnostics.Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Handle: {0}, Layer: {1}", entity.Handle, entity.Layer)); entity.Layer = "MyTest"; _AcDb.BlockReference block = entity as _AcDb.BlockReference; if (block != null) { foreach (var att in block.AttributeCollection) { _AcDb.ObjectId attOid = (_AcDb.ObjectId)att; _AcDb.AttributeReference attrib = trans.GetObject(attOid, _AcDb.OpenMode.ForWrite) as _AcDb.AttributeReference; if (attrib != null) { //attrib.UpgradeOpen(); attrib.Layer = "MyTest"; } } } } //} } // Layouts iterieren _AcDb.DBDictionary layoutDict = (_AcDb.DBDictionary)trans.GetObject(db.LayoutDictionaryId, _AcDb.OpenMode.ForRead); foreach (var loEntry in layoutDict) { if (loEntry.Key.ToUpperInvariant() == "MODEL") { continue; } _AcDb.Layout lo = (_AcDb.Layout)trans.GetObject(loEntry.Value, _AcDb.OpenMode.ForRead, false); if (lo == null) { continue; } System.Diagnostics.Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Layout: {0}", lo.LayoutName)); _AcDb.BlockTableRecord btRecord = (_AcDb.BlockTableRecord)trans.GetObject(lo.BlockTableRecordId, _AcDb.OpenMode.ForRead); foreach (var entId in btRecord) { _AcDb.Entity entity = (_AcDb.Entity)trans.GetObject(entId, _AcDb.OpenMode.ForRead); entity.UpgradeOpen(); //Access to the entity //MgdAcApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nHandle: {0}", entity.Handle)); //System.Diagnostics.Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Handle: {0}, Layer: {1}", entity.Handle, entity.Layer)); entity.Layer = "MyTest"; _AcDb.BlockReference block = entity as _AcDb.BlockReference; if (block != null) { foreach (var att in block.AttributeCollection) { _AcDb.ObjectId attOid = (_AcDb.ObjectId)att; _AcDb.AttributeReference attrib = trans.GetObject(attOid, _AcDb.OpenMode.ForWrite) as _AcDb.AttributeReference; if (attrib != null) { //attrib.UpgradeOpen(); attrib.Layer = "MyTest"; } } } } } trans.Commit(); } }