static public void DynamicBlockProps() { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = doc.Database; _AcEd.Editor ed = doc.Editor; _AcEd.PromptStringOptions pso = new _AcEd.PromptStringOptions("\nEnter dynamic block name or enter to select: "); pso.AllowSpaces = true; _AcEd.PromptResult pr = ed.GetString(pso); if (pr.Status != _AcEd.PromptStatus.OK) { return; } _AcDb.Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { _AcDb.BlockReference br = null; // If a null string was entered allow entity selection if (pr.StringResult == "") { // Select a block reference _AcEd.PromptEntityOptions peo = new _AcEd.PromptEntityOptions("\nSelect dynamic block reference: "); peo.SetRejectMessage("\nEntity is not a block."); peo.AddAllowedClass(typeof(_AcDb.BlockReference), false); _AcEd.PromptEntityResult per = ed.GetEntity(peo); if (per.Status != _AcEd.PromptStatus.OK) { return; } // Access the selected block reference br = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead) as _AcDb.BlockReference; } else { // Otherwise we look up the block by name _AcDb.BlockTable bt = tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead) as _AcDb.BlockTable; if (!bt.Has(pr.StringResult)) { ed.WriteMessage("\nBlock \"" + pr.StringResult + "\" does not exist."); return; } // Create a new block reference referring to the block br = new _AcDb.BlockReference(new _AcGe.Point3d(), bt[pr.StringResult]); } _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(br.DynamicBlockTableRecord, _AcDb.OpenMode.ForRead); // Call our function to display the block properties DisplayDynBlockProperties(ed, br, btr.Name); // Committing is cheaper than aborting tr.Commit(); } }
private void CreateOrModifyLayer(LayerInfo layerInfo, _AcAp.Document doc, _AcDb.Database db, _AcDb.Transaction trans, _AcDb.LayerTable layTb) { if (layTb.Has(layerInfo.NewLayer)) { var oid = layTb[layerInfo.NewLayer]; _AcDb.LayerTableRecord ltr = (_AcDb.LayerTableRecord)trans.GetObject(oid, _AcDb.OpenMode.ForWrite); layerInfo.ModifyLayer(ltr, trans, db); } else { using (_AcDb.LayerTableRecord ltr = new _AcDb.LayerTableRecord()) { // Assign the layer a name ltr.Name = layerInfo.NewLayer; // Upgrade the Layer table for write //layTb.UpgradeOpen(); // Append the new layer to the Layer table and the transaction layTb.Add(ltr); trans.AddNewlyCreatedDBObject(ltr, true); layerInfo.ModifyLayer(ltr, trans, db); } } }
public static void Plan2ImportLayerFilters() { var filePath = GetDwgName(); if (string.IsNullOrEmpty(filePath)) { return; } if (!System.IO.File.Exists(filePath)) { return; } _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcEd.Editor ed = doc.Editor; _AcDb.Database destDb = doc.Database; _AcLm.LayerFilterTree lft = destDb.LayerFilters; using (_AcDb.Database srcDb = new _AcDb.Database(false, false)) { srcDb.ReadDwgFile(filePath, _AcDb.FileOpenMode.OpenForReadAndAllShare, false, String.Empty); ImportNestedFilters(srcDb.LayerFilters.Root, lft.Root, srcDb, destDb, false, ed); } destDb.LayerFilters = lft; }
static public void RelinkToDoc(_BcAp.Document document) { if (LinkedDocument == document) { return; } if (LinkedDocument != null) { LinkedDocument.CommandEnded -= OnCommandEnded; LinkedDocument.Database.ObjectAppended -= OnObjectAppended; LinkedDocument.Database.ObjectErased -= OnObjectErased; LinkedDocument.Database.ObjectModified -= OnObjectModified; LinkedDocument.CloseWillStart -= OnBcDocCloseWillStart; } _preview?.Dispose(); LinkedDocument = document; LinkedDocument.CloseWillStart += OnBcDocCloseWillStart; LinkedDocument.Database.ObjectModified += OnObjectModified; LinkedDocument.Database.ObjectErased += OnObjectErased; LinkedDocument.Database.ObjectAppended += OnObjectAppended; LinkedDocument.CommandEnded += OnCommandEnded; _preview = new Visualization.GrasshopperPreview(); ExpireGH(); NeedRedraw = true; }
static public void Plan2LayTransExport() { try { #if BRX_APP return; #else _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (_AcAp.DocumentLock m_doclock = doc.LockDocument()) { //_AcWnd.SaveFileDialog sfd = new _AcWnd.SaveFileDialog("Excel-Datei", "", "xlsx","LayTransSave", _AcWnd.SaveFileDialog.SaveFileDialogFlags.AllowAnyExtension); //System.Windows.Forms.DialogResult dr = sfd.ShowDialog(); //if (dr != System.Windows.Forms.DialogResult.OK) return; Engine engine = new Engine(); var ok = engine.ExcelExport(); if (!ok) { _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler beim Export!")); } else { string msg = string.Format(CultureInfo.CurrentCulture, "Der Excel-Export wurde erfolgreich beendet."); _AcAp.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(msg); log.Info(msg); } } #endif } catch (System.Exception ex) { log.Error(ex.Message, ex); _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2LayTransExport aufgetreten! {0}", ex.Message)); } }
private void btnSelAbstand_Click(object sender, EventArgs e) { try { _AcAp.DocumentCollection dm = _AcAp.Application.DocumentManager; _AcAp.Document doc = dm.MdiActiveDocument; Editor ed = doc.Editor; #if NEWSETFOCUS doc.Window.Focus(); #else Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView(); // previous 2014 AutoCAD - Versions #endif PromptDoubleResult per = ed.GetDistance("\nTextabstand zeigen: "); if (per.Status == PromptStatus.OK) { _FensterOptions.TextAbstand = per.Value; txtAbstand.Text = _FensterOptions.TextAbstandString; } _AcAp.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\n"); } catch (Exception ex) { _AcAp.Application.ShowAlertDialog(ex.Message); } }
static public void GetXData() { AcAp.Document doc = AcApp.DocumentManager.MdiActiveDocument; AcEd.Editor ed = doc.Editor; AcEd.PromptEntityOptions opt = new AcEd.PromptEntityOptions("\nSelect entity: "); AcEd.PromptEntityResult res = ed.GetEntity(opt); if (res.Status == AcEd.PromptStatus.OK) { using (AcDb.Transaction tr = doc.TransactionManager.StartTransaction()) { AcDb.DBObject obj = tr.GetObject(res.ObjectId, AcDb.OpenMode.ForRead); AcDb.ResultBuffer rb = obj.XData; if (rb == null) { ed.WriteMessage("\nEntity does not have XData attached."); } else { int n = 0; foreach (AcDb.TypedValue tv in rb) { ed.WriteMessage("\nTypedValue {0} - type: {1}, value: {2}", n++, tv.TypeCode, tv.Value); } rb.Dispose(); } } } }
private static bool SetPlotSettings(string loName, string device, string pageSize, string styleSheet, double?scaleNumerator, double?scaleDenominator, short?plotRotation) { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = doc.Database; _AcEd.Editor ed = doc.Editor; _AcDb.LayoutManager layoutMgr = _AcDb.LayoutManager.Current; var layoutId = layoutMgr.GetLayoutId(loName); if (!layoutId.IsValid) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Layout '{0}' existiert nicht!", loName)); } using (var tr = db.TransactionManager.StartTransaction()) { var layout = (_AcDb.Layout)tr.GetObject(layoutId, _AcDb.OpenMode.ForWrite); layout.SetPlotSettings(device, pageSize, styleSheet, scaleNumerator, scaleDenominator, plotRotation); tr.Commit(); } return(true); }
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(); } }
public static void Plan2SetCtbInLayouts() { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _Db = doc.Database; _AcEd.Editor ed = doc.Editor; _CtbName = string.Empty; _DwgsWrongCtb.Clear(); _NrCtbs = 0; try { if (!GetCtbName(ed)) { return; } if (!SetCtbInLayouts()) { string msg = string.Format(CultureInfo.CurrentCulture, "Ctb '{0}' existiert nicht!", _CtbName); ed.WriteMessage("\n" + msg); System.Windows.Forms.MessageBox.Show(msg, "Plan2SetCtbInLayouts"); } else { string resultMsg = string.Format(CultureInfo.CurrentCulture, "Anzahl gesetzter CTBs: {0}", _NrCtbs.ToString()); log.Info(resultMsg); System.Windows.Forms.MessageBox.Show(resultMsg, "Plan2SetCtb"); } } catch (System.Exception ex) { string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2SetCtbInLayouts): {0}", ex.Message); ed.WriteMessage("\n" + msg); System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2SetCtbInLayouts"); } }
private static bool OpenAutoIdPalette() { if (_AutoIdPalette == null) { _AutoIdPalette = new AutoIdPalette(); } bool wasOpen = _AutoIdPalette.Show(); if (!wasOpen) { return(false); } _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; if (doc == null) { return(false); } log.DebugFormat("Dokumentname: {0}.", doc.Name); if (Globs.TheAutoIdOptions == null) { return(false); } else { return(true); } }
public static void Run(GH_Document definition, GrasshopperData ghData, _BcAp.Document bcDoc) { bool saveState = GH_Document.EnableSolutions; GH_Document.EnableSolutions = true; definition.Enabled = true; var inputs = GetInputParams(definition); var hostEntityId = ghData.HostEntity; foreach (var input in inputs) { if (!IsInputName(input.NickName)) { continue; } if (input is Parameters.BcEntity) { input.ClearData(); var data = new Types.BcEntity(hostEntityId.ToFsp(), bcDoc.Name); input.AddVolatileData(new Grasshopper.Kernel.Data.GH_Path(0), 0, data); data.LoadGeometry(bcDoc); continue; } var prop = ghData.GetProperty(FormatName(input.NickName)); if (prop == null) { continue; } input.VolatileData.ClearData(); switch (prop) { case int intValue: case double doubleValue: case bool boolValue: case string strValue: input.AddVolatileData(new Grasshopper.Kernel.Data.GH_Path(0), 0, prop); break; case _OdGe.Point3d pntValue: input.AddVolatileData(new Grasshopper.Kernel.Data.GH_Path(0), 0, pntValue.ToRhino()); break; case _OdGe.Vector3d vecValue: input.AddVolatileData(new Grasshopper.Kernel.Data.GH_Path(0), 0, vecValue.ToRhino()); break; } } Rhino.RhinoApp.SetFocusToMainWindow(); definition.NewSolution(false, GH_SolutionMode.Silent); Rhinoceros.Run(); GH_Document.EnableSolutions = saveState; }
internal void DelErrSyms(_AcAp.Document doc) { var invalidNrRbLayerName = "Blockanzahl_ungleich_1"; var centroidOutsideLayerName = "Centroid_liegt_außerhalb."; DeleteFehlerSymbols(new List <string>() { invalidNrRbLayerName, centroidOutsideLayerName }); }
public _CONNECTION() { _doc = _Ap.Application.DocumentManager.MdiActiveDocument; _db = _doc.Database; _ed = _doc.Editor; _trans = _db.TransactionManager.StartTransaction(); _blockTable = _trans.GetObject(_db.BlockTableId, _Db.OpenMode.ForWrite) as _Db.BlockTable; _modelSpace = _trans.GetObject(_Db.SymbolUtilityServices.GetBlockModelSpaceId(_db), _Db.OpenMode.ForWrite) as _Db.BlockTableRecord; }
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 _AcDb.ObjectId CreateNewLayer(_AcAp.Document doc, _AcDb.Database db) { using (_AcDb.Transaction trans = doc.TransactionManager.StartTransaction()) { try { string layerName = "MyTest"; _AcDb.LayerTable layTb = trans.GetObject(db.LayerTableId, _AcDb.OpenMode.ForRead) as _AcDb.LayerTable; using (_AcDb.LayerTableRecord acLyrTblRec = new _AcDb.LayerTableRecord()) { // Assign the layer a name acLyrTblRec.Name = layerName; // Upgrade the Layer table for write layTb.UpgradeOpen(); // Append the new layer to the Layer table and the transaction layTb.Add(acLyrTblRec); trans.AddNewlyCreatedDBObject(acLyrTblRec, true); int transparenz = 10; Byte alpha = TransparenzToAlpha(transparenz); _AcCm.Transparency tr = new _AcCm.Transparency(alpha); acLyrTblRec.Transparency = tr; _AcCm.Color col = _AcCm.Color.FromColorIndex(_AcCm.ColorMethod.ByColor, 2); //_AcCm.Color col = _AcCm.Color.FromRgb(10, 20, 30); acLyrTblRec.Color = col; _AcDb.ObjectId ltOid = GetLinetypeFromName("Continuous", trans, db); if (!ltOid.IsNull) { acLyrTblRec.LinetypeObjectId = ltOid; } _AcDb.LineWeight lw = _AcDb.LineWeight.LineWeight030; acLyrTblRec.LineWeight = lw; // ??? //acLyrTblRec.PlotStyleName = "hugo"; acLyrTblRec.Description = "My new Layer"; return(acLyrTblRec.ObjectId); } } finally { trans.Commit(); } } }
static public void Plan2CenterBlockSelBlock() { try { if (!OpenPalette()) { return; } var opts = Globs.TheOptions; _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (_AcAp.DocumentLock m_doclock = doc.LockDocument()) { _AcAp.DocumentCollection dm = _AcAp.Application.DocumentManager; if (doc == null) { return; } _AcEd.Editor ed = doc.Editor; #if NEWSETFOCUS doc.Window.Focus(); #else Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView(); // previous 2014 AutoCAD - Versions #endif _AcEd.PromptNestedEntityResult per = ed.GetNestedEntity("\nBlock wählen: "); if (per.Status == _AcEd.PromptStatus.OK) { using (var tr = doc.TransactionManager.StartTransaction()) { _AcDb.DBObject obj = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead); _AcDb.BlockReference br = obj as _AcDb.BlockReference; if (br == null) { br = Plan2Ext.Globs.GetBlockFromItsSubentity(tr, per); if (br == null) { return; } } opts.SetBlockname(br.Name); tr.Commit(); } } } } catch (System.Exception ex) { _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2CenterBlockSelBlock aufgetreten! {0}", ex.Message)); } }
public static void SetXData(AcDb.ObjectId objectId, AcDb.ResultBuffer valueXData) { AcAp.Document doc = AcApp.DocumentManager.MdiActiveDocument; using (AcDb.Transaction tr = doc.TransactionManager.StartTransaction()) { AcDb.DBObject obj = tr.GetObject(objectId, AcDb.OpenMode.ForWrite); AddRegAppTableRecord((string)valueXData.AsArray()[0].Value); obj.XData = valueXData; valueXData.Dispose(); tr.Commit(); } }
public static void Plan2ReplaceInLayoutNames() { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _Db = doc.Database; _AcEd.Editor ed = doc.Editor; _OldText = string.Empty; _NewText = string.Empty; try { var layoutNames = Plan2Ext.Layouts.GetLayoutNames(); layoutNames = layoutNames.Where(x => string.Compare(x, "Model", StringComparison.OrdinalIgnoreCase) != 0).ToList(); if (!GetOldText(ed)) { return; } if (!GetNewText(ed)) { return; } _Tr = _Db.TransactionManager.StartTransaction(); using (_Tr) { _AcDb.LayoutManager layoutMgr = _AcDb.LayoutManager.Current; foreach (var name in layoutNames) { bool changed; var newT = ReplaceTexts(name, out changed); if (changed) { layoutMgr.RenameLayout(name, newT); } } _Tr.Commit(); } } catch (System.Exception ex) { string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2ReplaceInLayoutNames): {0}", ex.Message); ed.WriteMessage("\n" + msg); System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2ReplaceInLayoutNames"); } }
/// <summary> /// Öffnen einer Dwg ohne Editor /// </summary> //[_AcTrx.CommandMethod("Plan2TestSideDb")] static public void Plan2TestSideDb() { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcEd.Editor ed = doc.Editor; // Ask the user to select a file _AcEd.PromptResult res = ed.GetString("\nEnter the path of a DWG or DXF file: "); if (res.Status == _AcEd.PromptStatus.OK) { // Create a database and try to load the file _AcDb.Database db = new _AcDb.Database(false, true); using (db) { try { db.ReadDwgFile(res.StringResult, System.IO.FileShare.Read, false, ""); } catch (System.Exception) { ed.WriteMessage("\nUnable to read drawing file."); return; } _AcDb.Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { // Open the blocktable, get the modelspace _AcDb.BlockTable bt = (_AcDb.BlockTable)tr.GetObject(db.BlockTableId, _AcDb.OpenMode.ForRead); _AcDb.BlockTableRecord btr = (_AcDb.BlockTableRecord)tr.GetObject(bt[_AcDb.BlockTableRecord.ModelSpace], _AcDb.OpenMode.ForRead); // Iterate through it, dumping objects foreach (_AcDb.ObjectId objId in btr) { _AcDb.Entity ent = (_AcDb.Entity)tr.GetObject(objId, _AcDb.OpenMode.ForRead); // Let's get rid of the standard namespace const string prefix = "Autodesk.AutoCAD.DatabaseServices."; string typeString = ent.GetType().ToString(); if (typeString.Contains(prefix)) { typeString = typeString.Substring(prefix.Length); } ed.WriteMessage("\nEntity " + ent.ObjectId.ToString() + " of type " + typeString + " found on layer " + ent.Layer + " with colour " + ent.Color.ToString()); } } } } }
private static string GetDwgName() { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcEd.Editor ed = doc.Editor; _AcWnd.OpenFileDialog ofd = new _AcWnd.OpenFileDialog( "AutoCAD-Datei mit den zu importierenden Layerfilter wählen", "", "dwg", "AutoCAD-Datei mit den zu importierenden Layerfilter wählen", _AcWnd.OpenFileDialog.OpenFileDialogFlags.AllowAnyExtension ); System.Windows.Forms.DialogResult dr = ofd.ShowDialog(); if (dr != System.Windows.Forms.DialogResult.OK) { return(null); } return(ofd.Filename); }
static public void Plan2LayTransExportBulk() { try { #if BRX_APP return; #else log.Info("----------------------------------------------------------------------------------"); log.Info("Plan2LayTransExportBulk"); _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (_AcAp.DocumentLock m_doclock = doc.LockDocument()) { string dirName = string.Empty; using (var folderBrowser = new System.Windows.Forms.FolderBrowserDialog()) { folderBrowser.Description = "Verzeichnis mit Zeichnungen für den Layerexport"; folderBrowser.RootFolder = Environment.SpecialFolder.MyComputer; if (folderBrowser.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } dirName = folderBrowser.SelectedPath; } //dirName = @"D:\Plan2\Data\Plan2PlotToDwf"; Engine engine = new Engine(); var ok = engine.ExcelExport(dirName); if (!ok) { _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler beim Plan2LayTransExportBulk!")); } else { string msg = string.Format(CultureInfo.CurrentCulture, "Der Excel-Export wurde erfolgreich beendet."); _AcAp.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(msg); log.Info(msg); } } #endif } catch (System.Exception ex) { log.Error(ex.Message, ex); _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2LayTransExportBulk aufgetreten! {0}", ex.Message)); } }
static public void Plan2LayTrans() { try { #if BRX_APP return; #else _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (_AcAp.DocumentLock m_doclock = doc.LockDocument()) { _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; // First let's use the editor method, GetFileNameForOpen() _AcEd.PromptOpenFileOptions opts = new _AcEd.PromptOpenFileOptions("Excel-Datei für Layer-Infos"); opts.Filter = "Excel (*.xlsx)|*.xlsx|Excel alt (*.xls)|*.xls"; _AcEd.PromptFileNameResult pr = ed.GetFileNameForOpen(opts); if (pr.Status != _AcEd.PromptStatus.OK) { return; } //_AcWnd.OpenFileDialog ofd = new _AcWnd.OpenFileDialog("Excel-Datei", "", "xlsx", "LayTrans", _AcWnd.OpenFileDialog.OpenFileDialogFlags.AllowAnyExtension); //System.Windows.Forms.DialogResult dr = ofd.ShowDialog(); //if (dr != System.Windows.Forms.DialogResult.OK) return; string fileName = pr.StringResult; Engine engine = new Engine(); var ok = engine.LayTrans(fileName); if (!ok) { _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in LayTrans!")); } else { string msg = string.Format(CultureInfo.CurrentCulture, "LayTrans wurde erfolgreich beendet."); _AcAp.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(msg); log.Info(msg); } } #endif } catch (System.Exception ex) { log.Error(ex.Message, ex); _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Fehler in Plan2LayTrans aufgetreten! {0}", ex.Message)); } }
public GhDataManager(_BcAp.Document doc) { Document = doc; DefinitionManager = new GhDefinitionManager(); DefinitionManager.Reloaded += (s, def) => { using (var transaction = Document.Database.TransactionManager.StartTransaction()) { foreach (var it in _grasshopperData) { var ghDataId = it.Key; var ghData = transaction.GetObject(ghDataId, _OdDb.OpenMode.ForRead) as GrasshopperData; if (ghData == null) { continue; } _toUpdate.Add(ghDataId); } } }; var database = doc.Database; using (var transaction = database.TransactionManager.StartTransaction()) { var blockTable = transaction.GetObject(database.BlockTableId, _OdDb.OpenMode.ForRead) as _OdDb.BlockTable; var searchPath = new string[] { DwgPath }; foreach (var blockId in blockTable) { var block = transaction.GetObject(blockId, _OdDb.OpenMode.ForRead) as _OdDb.BlockTableRecord; foreach (var id in block) { var entity = transaction.GetObject(id, _OdDb.OpenMode.ForRead) as _OdDb.Entity; var ghDataId = GrasshopperData.GetGrasshopperData(entity); if (ghDataId.IsNull) { continue; } var ghData = transaction.GetObject(ghDataId, _OdDb.OpenMode.ForRead) as GrasshopperData; DefinitionManager.Load(ghData.Definition, searchPath); _toUpdate.Add(ghDataId); } } transaction.Commit(); } EnableReactors(); }
private void btnAG_Click(object sender, EventArgs e) { try { _AcAp.DocumentCollection dm = _AcAp.Application.DocumentManager; _AcAp.Document doc = dm.MdiActiveDocument; Editor ed = doc.Editor; #if NEWSETFOCUS _AcAp.Application.DocumentManager.MdiActiveDocument.Window.Focus(); #else Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView(); // previous 2014 AutoCAD - Versions #endif PromptEntityResult per = ed.GetEntity("\nAbzugsfläche wählen: "); if (per.Status == PromptStatus.OK) { Transaction tr = doc.TransactionManager.StartTransaction(); using (tr) { string layer = string.Empty; DBObject obj = tr.GetObject(per.ObjectId, OpenMode.ForRead); layer = GetPolylineLayer(obj); if (string.IsNullOrEmpty(layer)) { return; } if (string.Compare(txtFG.Text, layer, StringComparison.OrdinalIgnoreCase) == 0) { _AcAp.Application.ShowAlertDialog(string.Format(CultureInfo.CurrentCulture, "Die Layer für Flächengrenze und Abzugsfläche müssen unterschiedlich sein.")); return; } txtAG.Text = layer; tr.Commit(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static AcDb.ResultBuffer GetXData(AcDb.ObjectId objectId) { AcAp.Document doc = AcApp.DocumentManager.MdiActiveDocument; using (AcDb.Transaction tr = doc.TransactionManager.StartTransaction()) { AcDb.DBObject obj = tr.GetObject(objectId, AcDb.OpenMode.ForRead); AcDb.ResultBuffer resultBuffer = obj.XData; if (resultBuffer == null) { return(null); } else { return(resultBuffer); } } }
private static bool GetAttributeInfos(_AcEd.Editor ed, _AcAp.Document doc) { bool ok = false; _BlockName = string.Empty; _AttributeName = string.Empty; _AttributeValue = string.Empty; _AcEd.PromptNestedEntityResult per = ed.GetNestedEntity("\nZu änderndes Attribut wählen: "); if (per.Status == _AcEd.PromptStatus.OK) { using (var tr = doc.TransactionManager.StartTransaction()) { _AcDb.DBObject obj = tr.GetObject(per.ObjectId, _AcDb.OpenMode.ForRead); _AcDb.AttributeReference ar = obj as _AcDb.AttributeReference; if (ar != null && !ar.IsConstant) { _AcDb.BlockReference br = Plan2Ext.Globs.GetBlockFromItsSubentity(tr, per); if (br != null) { ed.WriteMessage(string.Format(CultureInfo.CurrentCulture, "\nBlockname: {0}, Attributname: {1}.", Plan2Ext.Globs.GetBlockname(br, tr), ar.Tag)); var prompt = new _AcEd.PromptStringOptions("\nText in Attribut: "); prompt.AllowSpaces = true; var prefixUserRes = ed.GetString(prompt); if (prefixUserRes.Status == _AcEd.PromptStatus.OK) { _AttributeValue = prefixUserRes.StringResult; _AttributeName = ar.Tag; _BlockName = Plan2Ext.Globs.GetBlockname(br, tr); log.InfoFormat(CultureInfo.CurrentCulture, "Block: {0}, Attribut: {1}, Wert: '{2}'", _BlockName, _AttributeName, _AttributeValue); ok = true; } } } tr.Commit(); } } return(ok); }
private List <_AcDb.ObjectId> SelectRaumBlocks() { string hkBlockName = RaumBlockName; var ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; _AcEd.SelectionFilter filter = new _AcEd.SelectionFilter(new _AcDb.TypedValue[] { new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "INSERT"), //new _AcDb.TypedValue((int)_AcDb.DxfCode.BlockName,hkBlockName) }); _AcEd.PromptSelectionResult res = ed.GetSelection(filter); if (res.Status != _AcEd.PromptStatus.OK) { return(new List <_AcDb.ObjectId>()); } #if BRX_APP SelectionSet ss = res.Value; #else using (_AcEd.SelectionSet ss = res.Value) #endif { List <_AcDb.ObjectId> theBlockOids = new List <_AcDb.ObjectId>(); _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; using (_AcDb.Transaction myT = doc.TransactionManager.StartTransaction()) { var lstBlocks = ss.GetObjectIds(); foreach (var oid in lstBlocks) { var br = myT.GetObject(oid, _AcDb.OpenMode.ForRead) as _AcDb.BlockReference; if (br != null && string.Compare(Plan2Ext.Globs.GetBlockname(br, myT), hkBlockName, StringComparison.OrdinalIgnoreCase) == 0) { theBlockOids.Add(oid); } } myT.Commit(); } return(theBlockOids); //return ss.GetObjectIds().ToList(); } }
//Plan2Ext.Layouts.ImportLayout("02.OG B-Bau", @"D:\Plan2\Data\Plan2RenameBlocks\work\02_OGa.dwg"); //Plan2Ext.Layouts.CreateLayout("alx"); //var layoutNames = Plan2Ext.Layouts.GetLayoutNames(); public static List <string> GetLayoutNames() { var layoutNames = new List <string>(); _AcAp.Document acDoc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database acCurDb = acDoc.Database; using (_AcDb.Transaction trans = acCurDb.TransactionManager.StartTransaction()) { _AcDb.DBDictionary lays = trans.GetObject(acCurDb.LayoutDictionaryId, _AcDb.OpenMode.ForRead) as _AcDb.DBDictionary; foreach (_AcDb.DBDictionaryEntry item in lays) { layoutNames.Add(item.Key); } trans.Commit(); } return(layoutNames); }
private static List <_AcGe.Point2d> GetLwPoints(_AcDb.ObjectId objectId) { var pts = new List <_AcGe.Point2d>(); _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = doc.Database; using (var trans = doc.TransactionManager.StartTransaction()) { var lwp = (_AcDb.Polyline)trans.GetObject(objectId, _AcDb.OpenMode.ForRead); int vn = lwp.NumberOfVertices; for (int i = 0; i < vn; i++) { _AcGe.Point2d pt = lwp.GetPoint2dAt(i); pts.Add(pt); } trans.Commit(); } return(pts); }