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(); } } } }
public static bool ImportLineTypes(string fileLineTypes) { try { string path = AcDb.HostApplicationServices.Current.FindFile(fileLineTypes, db, AcDb.FindFileHint.Default); db.LoadLineTypeFile("*", path); return(true); } catch (Teigha.Runtime.Exception ex) { if (ex.ErrorStatus == AcTrx.ErrorStatus.FilerError) { ed.WriteMessage("\nІмпору типів ліній > \n Не вдалося знайти файл '{0}'.", fileLineTypes); } else if (ex.ErrorStatus == AcTrx.ErrorStatus.DuplicateRecordName) { ed.WriteMessage("\nІмпору типів ліній > \n Неможливо завантажити деякі типи ліній."); } else { ed.WriteMessage("\nІмпору типів ліній > {0}", ex.Message); } return(false); } }
public static bool CallCropBat(_AcDb.ResultBuffer rb) { _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; string taskName = "CallCropBat"; try { using (TaskService tasksrvc = new TaskService("server", "pdfcrop", "workgroup", "pdf")) { Task task = tasksrvc.FindTask(taskName); if (task != null) { var t1 = task.Run(); ed.WriteMessage(string.Format("\nTask '{0}' ausgeführt.", taskName)); return(true); } else { ed.WriteMessage(string.Format("\nTask '{0}' nicht gefunden!", taskName)); } } } catch (System.Exception ex) { ed.WriteMessage(string.Format(CultureInfo.CurrentCulture, "\nFehler in CallCropBat! {0}'", ex.Message)); } return(false); }
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"); } }
public void Initialize() { _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; string assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); ed.WriteMessage("\nBeams application version:{0} loaded successfully!", assemblyVersion); ed.WriteMessage("\nEnter \"BEAM1\" to draw a beam."); ed.WriteMessage("\nEnter \"ENT-COLOUR\" to change and entity's colour."); }
public static bool Plan2RemoveHyperLinks(_AcDb.ResultBuffer rb) { var doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = _AcAp.Application.DocumentManager.MdiActiveDocument.Database; _AcDb.TransactionManager dbTrans = db.TransactionManager; _AcEd.Editor ed = doc.Editor; try { if (rb == null) { ed.WriteMessage("Aufruf: (Plan2RemoveHyperLinks el)"); return(false); } var typedValues = rb.AsArray(); if (typedValues == null || typedValues.Length != 1) { ed.WriteMessage("Aufruf: (Plan2RemoveHyperLinks el)"); return(false); } if (typedValues[0].TypeCode != (short)_AcBrx.LispDataType.ObjectId) { ed.WriteMessage("Aufruf: (Plan2RemoveHyperLinks el)"); return(false); } using (_AcDb.Transaction trans = dbTrans.StartTransaction()) { _AcDb.Entity ent = trans.GetObject((_AcDb.ObjectId)typedValues[0].Value, _AcDb.OpenMode.ForWrite) as _AcDb.Entity; if (ent != null) { //ent.Hyperlinks.Clear(); // -> crashes while (ent.Hyperlinks.Count > 0) { ent.Hyperlinks.RemoveAt(0); } } trans.Commit(); } return(true); } catch (Exception ex) { ed.WriteMessage("Aufruf: (Plan2RemoveHyperLinks el)"); } return(false); }
/// <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 bool CheckInvalidKomma(string blockName, string blockNameStringPlural, Func <_AcDb.BlockReference, bool> checkFunc, BlockReader blockReader, _AcEd.Editor ed) { var invalidRaumblocks = blockReader.GetAllBlocksInModelSpaceWith(checkFunc, blockName); if (invalidRaumblocks.Count > 0) { ed.WriteMessage(string.Format(CultureInfo.CurrentCulture, "\nAnzahl gefundener {1} mit Komma: {0}", invalidRaumblocks.Count, blockNameStringPlural)); ed.SetImpliedSelection(invalidRaumblocks.ToArray()); return(true); } ed.WriteMessage(string.Format(CultureInfo.CurrentCulture, "\nEs wurden keine {0} mit Komma gefunden.", blockNameStringPlural)); return(false); }
public void Initialize() { _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; CAS.myFunctions.DiaSettings objSettings = new myFunctions.DiaSettings(); ed.WriteMessage("CAS installed"); }
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(); } }
internal void close() { _ed.WriteMessage("\n[close connection]\n"); _trans.Commit(); _trans.Dispose(); _ed.Regen(); }
public bool Plan2ExcelToBlock(_AcDb.ResultBuffer rb) { _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; try { if (rb == null) { ShowCallInfoImport(ed); return(false); } _AcDb.TypedValue[] values = rb.AsArray(); if (values == null || values.Length < 2) { ShowCallInfoImport(ed); return(false); } // Get ExcelFileName from Args if (values[0].Value == null) { ShowCallInfoImport(ed); return(false); } string excelFileName = values[0].Value.ToString(); if (string.IsNullOrEmpty(excelFileName)) { ShowCallInfoImport(ed); return(false); } bool createChangeLines = true; switch (values[1].TypeCode) { case 5019: createChangeLines = false; break; case 5021: createChangeLines = true; break; default: ShowCallInfoImport(ed); return(false); } // Start Import StartImport(excelFileName, createChangeLines); return(true); } catch (System.Exception ex) { log.Error(ex.Message); string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2ExcelToBlock): {0}", ex.Message); ed.WriteMessage("\n" + msg); System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2ExcelToBlock"); return(false); } }
public bool Plan2BlockToExcel(_AcDb.ResultBuffer rb) { _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; try { if (rb == null) { ShowCallInfo(ed); return(false); } _AcDb.TypedValue[] values = rb.AsArray(); if (values == null || values.Length < 2) { ShowCallInfo(ed); return(false); } // Get Blockname from Args if (values[0].Value == null) { ShowCallInfo(ed); return(false); } string blockName = values[0].Value.ToString(); if (string.IsNullOrEmpty(blockName)) { ShowCallInfo(ed); return(false); } // Get ExcelFileName from Args if (values[1].Value == null) { ShowCallInfo(ed); return(false); } string excelFileName = values[1].Value.ToString(); if (string.IsNullOrEmpty(excelFileName)) { ShowCallInfo(ed); return(false); } // Start Export StartExport(blockName, excelFileName); return(true); } catch (System.Exception ex) { log.Error(ex.Message); string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2BlockToExcel): {0}", ex.Message); ed.WriteMessage("\n" + msg); System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2BlockToExcel"); return(false); } }
private static bool PlotInLayouts() { var ok = true; _AcAp.Application.SetSystemVariable("BACKGROUNDPLOT", 0); using (_Tr = _Db.TransactionManager.StartTransaction()) { var layouts = _Tr.GetObject(_Db.LayoutDictionaryId, _AcDb.OpenMode.ForRead) as _AcDb.DBDictionary; foreach (var layoutDe in layouts) { //_AcDb.ObjectId layoutId = layManager.GetLayoutId(layManager.CurrentLayout); var layoutId = layoutDe.Value; var layoutObj = (_AcDb.Layout)_Tr.GetObject(layoutId, _AcDb.OpenMode.ForWrite); var loNameUC = layoutObj.LayoutName.ToUpperInvariant(); if (string.Compare(loNameUC, "MODEL", StringComparison.OrdinalIgnoreCase) == 0 || loNameUC.StartsWith("X_", StringComparison.OrdinalIgnoreCase)) { continue; } var fileName = _Doc.Name; var dwgName = Path.GetFileNameWithoutExtension(fileName); var dirName = Path.GetDirectoryName(fileName); //var dwfName = Path.Combine(dirName, dwgName + "_" + RemoveInvalidCharacters(lo.LayoutName) + ".dwf"); var dwfName = Path.Combine(dirName, RemoveInvalidCharacters(layoutObj.LayoutName) + ".dwf"); log.InfoFormat("Ausgabedateiname: {0}", dwfName); var dwfNameUC = dwfName.ToUpperInvariant(); if (_LayoutNames.Contains(dwfNameUC)) { var msg = string.Format("Dwf kann nicht exportiert werden, da dieses schon aus einer Zeichnung exportiert wurde! {0}", dwfName); log.Warn(msg); _Editor.WriteMessage("\n" + msg); _MultipleLayoutNames = true; ok = false; continue; } else { _LayoutNames.Add(dwfNameUC); } if (layoutObj.TabSelected == false) { _AcDb.LayoutManager acLayoutMgr = _AcDb.LayoutManager.Current; acLayoutMgr.CurrentLayout = layoutObj.LayoutName; } if (!PlotDwf(layoutObj, dwfName)) { ok = false; } } _Tr.Commit(); } return(ok); }
private static void ExecuteCommandAsyncOut(string command, string args, ref int exitCode, _AcEd.Editor ed) { ProcessStartInfo ProcessInfo; Process process; //string sap = Application.StartupPath; ProcessInfo = new ProcessStartInfo(command, args); ProcessInfo.CreateNoWindow = true; ProcessInfo.UseShellExecute = false; //ProcessInfo.WorkingDirectory = Application.StartupPath + "\\txtmanipulator"; // *** Redirect the output *** ProcessInfo.RedirectStandardError = true; ProcessInfo.RedirectStandardOutput = true; using (process = Process.Start(ProcessInfo)) { process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => { if (!string.IsNullOrEmpty(e.Data)) { ed.WriteMessage("\n" + e.Data); } }; process.BeginOutputReadLine(); process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) => { if (!string.IsNullOrEmpty(e.Data)) { ed.WriteMessage("\nError>>" + e.Data); } }; process.BeginErrorReadLine(); process.WaitForExit(); exitCode = process.ExitCode; } }
public static void Plan2PlotToDwf() { log.Info("----------------------------------------------------------------"); log.Info("Plan2PlotToDwf"); _Doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _Db = _Doc.Database; _Editor = _Doc.Editor; _NrPlots = 0; _MultipleLayoutNames = false; _LayoutNames.Clear(); try { if (!PlotInLayouts()) { string msg = string.Format(CultureInfo.CurrentCulture, "Fehler beim Plotten. Siehe Log-Datei!"); _Editor.WriteMessage("\n" + msg); System.Windows.Forms.MessageBox.Show(msg, "Plan2PlotToDwf"); } else { string add = string.Empty; if (_MultipleLayoutNames) { add = "\n" + "Mehrfache Layoutnamen! (siehe Log-Datei)."; } string resultMsg = string.Format(CultureInfo.CurrentCulture, "Anzahl erzeugter Plots: {0}{1}", _NrPlots.ToString(), add); log.Info(resultMsg); System.Windows.Forms.MessageBox.Show(resultMsg, "Plan2PlotToDwf"); } } catch (System.Exception ex) { string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2SetPlotterInLayouts): {0}", ex.Message); _Editor.WriteMessage("\n" + msg); System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2PlotToDwf"); } }
public void CreateLayerFilter() { _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = doc.Database; _AcEd.Editor ed = doc.Editor; _AcLm.LayerFilterTree filterTree = db.LayerFilters; _AcLm.LayerFilterCollection filters = filterTree.Root.NestedFilters; // Lets find out about the root filter ed.WriteMessage(String.Format("\n(Root) Name : {0} Expr : {1}", db.LayerFilters.Root.Name, db.LayerFilters.Root.FilterExpression) ); // Lets find out about all the filters foreach (_AcLm.LayerFilter f in filters) { ed.WriteMessage(String.Format("\nName : {0} Expr : {1}", f.Name, f.FilterExpression) ); } // Lets find out about the current filter if (db.LayerFilters.Current != null) { ed.WriteMessage(String.Format("\n(Current) Name : {0} Expr : {1}", db.LayerFilters.Current.Name, db.LayerFilters.Current.FilterExpression) ); } // Create and add a new layer filter _AcLm.LayerFilter layerFilter = new _AcLm.LayerFilter(); layerFilter.Name = "MyLyFilter"; layerFilter.FilterExpression = "NAME == \"*Test*\""; filters.Add(layerFilter); // Set the changed layer filters tree to the database db.LayerFilters = filterTree; }
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"); } }
private static void DisplayDynBlockProperties(_AcEd.Editor ed, _AcDb.BlockReference br, string name) { // Only continue is we have a valid dynamic block if (br != null && br.IsDynamicBlock) { ed.WriteMessage("\nDynamic properties for \"{0}\"\n", name); // Get the dynamic block's property collection _AcDb.DynamicBlockReferencePropertyCollection pc = br.DynamicBlockReferencePropertyCollection; // Loop through, getting the info for each property foreach (_AcDb.DynamicBlockReferenceProperty prop in pc) { // Start with the property name, type and description ed.WriteMessage("\nProperty: \"{0}\" : {1}", prop.PropertyName, prop.UnitsType); if (prop.Description != "") { ed.WriteMessage("\n Description: {0}", prop.Description); } // Is it read-only? if (prop.ReadOnly) { ed.WriteMessage(" (Read Only)"); } // Get the allowed values, if it's constrained bool first = true; foreach (object value in prop.GetAllowedValues()) { ed.WriteMessage((first ? "\n Allowed values: [" : ", ")); ed.WriteMessage("\"{0}\"", value); first = false; } if (!first) { ed.WriteMessage("]"); } // And finally the current value ed.WriteMessage("\n Current value: \"{0}\"\n", prop.Value); } } }
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); }
public _AcDb.ResultBuffer Plan2GetExcelToBlockDwgs(_AcDb.ResultBuffer rb) { _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; try { if (rb == null) { ShowCallInfoDwgs(ed); return(null); } _AcDb.TypedValue[] values = rb.AsArray(); if (values == null || values.Length < 1) { ShowCallInfoDwgs(ed); return(null); } // Get ExcelFileName from Args if (values[0].Value == null) { ShowCallInfoDwgs(ed); return(null); } string excelFileName = values[0].Value.ToString(); if (string.IsNullOrEmpty(excelFileName)) { ShowCallInfoDwgs(ed); return(null); } return(GetDwgNames(excelFileName)); } catch (System.Exception ex) { log.Error(ex.Message); string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2GetExcelToBlockDwgs): {0}", ex.Message); ed.WriteMessage("\n" + msg); System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2GetExcelToBlockDwgs"); return(null); } }
public static bool Plan2FinishPlot(_AcDb.ResultBuffer rb) { _AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor; try { if (rb == null) { return(false); } _AcDb.TypedValue[] values = rb.AsArray(); if (values == null || values.Length < 1) { return(false); } if (values[0].Value == null) { return(false); } string dirName = values[0].Value.ToString(); if (string.IsNullOrEmpty(dirName)) { return(false); } if (!System.IO.Directory.Exists(dirName)) { return(false); } return(Plan2FinishPlot(dirName)); } catch (System.Exception ex) { string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2FinishPlot): {0}", ex.Message); ed.WriteMessage("\n" + msg); System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2FinishPlot"); return(false); } }
public static AcDb.ObjectId InsertBlock( string nameBlock, AcGe.Point3d insertionPoint, double scale, double rotation, AcDb.ObjectId layerId, Dictionary <string, string> tags) { AcDb.ObjectId idBlock = AcDb.ObjectId.Null; using (AcDb.Transaction tr = db.TransactionManager.StartTransaction()) { AcDb.BlockTable blockTable = (AcDb.BlockTable)tr.GetObject(db.BlockTableId, AcDb.OpenMode.ForRead); if (!blockTable.Has(nameBlock)) { ed.WriteMessage("\nНезнайдено блок '{0}' у таблиці блоків креслення.", nameBlock); return(idBlock); } AcDb.BlockTableRecord curSpace = (AcDb.BlockTableRecord)tr.GetObject(db.CurrentSpaceId, AcDb.OpenMode.ForWrite); AcDb.BlockReference blockReference = new AcDb.BlockReference(insertionPoint, blockTable[nameBlock]) { LayerId = layerId, ScaleFactors = new AcGe.Scale3d(scale, scale, scale), Rotation = rotation }; blockReference.TransformBy(ed.CurrentUserCoordinateSystem); curSpace.AppendEntity(blockReference); tr.AddNewlyCreatedDBObject(blockReference, true); if (tags != null) { ReplaceAttributeBlock(blockReference, tags, true); } idBlock = blockReference.ObjectId; tr.Commit(); } return(idBlock); }
//[_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(); } }
internal void DoIt(_AcAp.Document doc, string rbName, string fgLayer) { log.Debug("--------------------------"); _FlaechenGrenzen.Clear(); _Raumbloecke.Clear(); var _AreaEngine = new AreaEngine(); _AcGe.Matrix3d ucs = _AcGe.Matrix3d.Identity; try { ucs = doc.Editor.CurrentUserCoordinateSystem; doc.Editor.CurrentUserCoordinateSystem = _AcGe.Matrix3d.Identity; if (!string.IsNullOrEmpty(rbName)) { _RaumblockName = rbName; } if (!string.IsNullOrEmpty(fgLayer)) { _FgLayer = fgLayer; } _AreaEngine.SelectFgAndRb(_FlaechenGrenzen, _Raumbloecke, _FgLayer, _RaumblockName); if (_FlaechenGrenzen.Count == 0) { return; } // todo: läuft nicht synchron - wird dzt in lisp ausgeführt //Globs.SetWorldUCS(); ZoomToFlaechenGrenzen(); // init div int fehlerKeinRb = 0; int fehlerMehrRb = 0; int fehlerWertFalsch = 0; _AcDb.Database db = doc.Database; _AcEd.Editor ed = doc.Editor; _AcDb.TransactionManager tm = db.TransactionManager; _AcDb.Transaction myT = tm.StartTransaction(); try { _AcGe.Point2d lu = new _AcGe.Point2d(); _AcGe.Point2d ro = new _AcGe.Point2d(); for (int i = 0; i < _FlaechenGrenzen.Count; i++) { log.Debug("--------------------------"); double sumAF = 0; int rbInd = -1; _AcDb.ObjectId elFG = _FlaechenGrenzen[i]; log.DebugFormat("Flächengrenze {0}", elFG.Handle.ToString()); _AcDb.Extents3d ext = GetExtents(tm, elFG); _AcGe.Point3d minExt = new _AcGe.Point3d(ext.MinPoint.X - ABSTANDTEXT, ext.MinPoint.Y - ABSTANDTEXT, ext.MinPoint.Z); _AcGe.Point3d maxExt = new _AcGe.Point3d(ext.MaxPoint.X + ABSTANDTEXT, ext.MaxPoint.Y + ABSTANDTEXT, ext.MaxPoint.Z); List <_AcDb.ObjectId> rbsToIgnoreCol = GetFgAnz(minExt, maxExt, elFG); if (rbsToIgnoreCol.Count > 0) { string handles = string.Join(",", rbsToIgnoreCol.Select(x => x.Handle.ToString()).ToArray()); log.DebugFormat("Zu ignorierende Raumblöcke: {0}", handles); } // 'raumbloecke holen List <_AcDb.ObjectId> ssRB = selRB(minExt, maxExt); if (ssRB.Count > 0) { string handles = string.Join(",", ssRB.Select(x => x.Handle.ToString()).ToArray()); log.DebugFormat("Raumblöcke: {0}", handles); } int rbAnz = 0; // 'raumbloecke pruefen for (int rbCnt = 0; rbCnt < ssRB.Count; rbCnt++) { _AcDb.ObjectId rbBlock2 = ssRB[rbCnt]; // ' ignore rbs _AcDb.ObjectId found = rbsToIgnoreCol.FirstOrDefault(x => x.Equals(rbBlock2)); if (found != default(_AcDb.ObjectId)) { continue; } using (_AcDb.DBObject dbObj = tm.GetObject(rbBlock2, _AcDb.OpenMode.ForRead, false)) { _AcGe.Point3d rbEp = ((_AcDb.BlockReference)dbObj).Position; using (_AcDb.Entity elFGEnt = (_AcDb.Entity)tm.GetObject(elFG, _AcDb.OpenMode.ForRead, false)) { if (AreaEngine.InPoly(rbEp, elFGEnt)) { log.DebugFormat("Raumblock {0} ist innerhalb der Flächengrenze.", rbBlock2.Handle.ToString()); if (_Raumbloecke.Contains(rbBlock2)) { _Raumbloecke.Remove(rbBlock2); } rbAnz++; rbInd = rbCnt; } else { log.DebugFormat("Außen liegender Raumblock {0} wird ignoriert.", rbBlock2.Handle.ToString()); } } } } if (rbAnz < 1) { log.WarnFormat("Kein Raumblock in Flächengrenze {0}!", elFG.Handle.ToString()); //FehlerLineOrHatchPoly(elFG, _InvalidNrRb, 255, 0, 0, tm, Globs.GetLabelPoint(elFG)); fehlerKeinRb++; } else if (rbAnz > 1) { log.WarnFormat("Mehr als ein Raumblock in Flächengrenze {0}!", elFG.Handle.ToString()); //FehlerLineOrHatchPoly(elFG, _InvalidNrRb, 255, 0, 0, tm, Globs.GetLabelPoint(elFG)); fehlerMehrRb++; } else { using (var tr = doc.TransactionManager.StartTransaction()) { var pt = Globs.GetLabelPoint(elFG); if (pt.HasValue) { var rblock = tr.GetObject(ssRB[rbInd], _AcDb.OpenMode.ForWrite) as _AcDb.BlockReference; var pos = rblock.GetCenter(); if (!pos.HasValue) { pos = rblock.Position; } _AcGe.Vector3d acVec3d = pos.Value.GetVectorTo(pt.Value); rblock.TransformBy(_AcGe.Matrix3d.Displacement(acVec3d)); ed.WriteMessage("\nCentroid is {0}", pt); } else { var poly = tr.GetObject(elFG, _AcDb.OpenMode.ForRead) as _AcDb.Polyline; string msg = string.Format(CultureInfo.CurrentCulture, "\nFläche {0}. Centroid liegt außerhalb.", poly.Handle.ToString()); ed.WriteMessage(msg); log.Warn(msg); } tr.Commit(); } } } //if (_Raumbloecke.Count > 0) //{ // List<object> insPoints = new List<object>(); // for (int i = 0; i < _Raumbloecke.Count; i++) // { // _AcIntCom.AcadBlockReference rbBlock = (_AcIntCom.AcadBlockReference)Globs.ObjectIdToAcadEntity(_Raumbloecke[i], tm); // insPoints.Add(rbBlock.InsertionPoint); // } // _AcCm.Color col = _AcCm.Color.FromRgb((byte)0, (byte)255, (byte)0); // Plan2Ext.Globs.InsertFehlerLines(insPoints, _LooseBlockLayer, 50, Math.PI * 1.25, col); //} if (fehlerKeinRb > 0 || fehlerMehrRb > 0 || fehlerWertFalsch > 0 || _Raumbloecke.Count > 0) { string msg = string.Format(CultureInfo.CurrentCulture, "Räume ohne Raumblock: {0}\nRäume mit mehr als einem Raumblock: {1}\nRäume mit falschem Wert in Raumblock: {2}\nRaumblöcke ohne entsprechende Flächengrenzen: {3}", fehlerKeinRb, fehlerMehrRb, fehlerWertFalsch, _Raumbloecke.Count); log.Debug(msg); _AcAp.Application.ShowAlertDialog(msg); } //If wucs = 0 Then // ThisDrawing.SendCommand "(command ""_.UCS"" ""_P"") " //End If myT.Commit(); } finally { myT.Dispose(); } } finally { doc.Editor.CurrentUserCoordinateSystem = ucs; } }
public void Info(string msg) { _log.Info(msg); _editor.WriteMessage("\n" + msg); }
private static void ShowCallInfoDwgs(_AcEd.Editor ed) { ed.WriteMessage("\n Aufruf: (Plan2GetExcelToBlockDwgs ExcelFileName)"); }
private static void ShowCallInfoImport(_AcEd.Editor ed) { ed.WriteMessage("\n Aufruf: (Plan2ExcelToBlock ExcelFileName ShowChangeLines)"); }
private static void ShowCallInfo(_AcEd.Editor ed) { ed.WriteMessage("\n Aufruf: (Plan2BlockToExcel BlockName ExcelFileName)"); }
public static void Plan2AufteilungNet() { var acadApp = (Autodesk.AutoCAD.Interop.AcadApplication)_AcAp.Application.AcadApplication; _AcAp.Document doc = _AcAp.Application.DocumentManager.MdiActiveDocument; _AcDb.Database db = doc.Database; _AcEd.Editor ed = doc.Editor; try { ed.Command("_.LAYER", "_TH", "*", "_ON", "*", "_UN", "*", ""); var selOp = new _AcEd.PromptSelectionOptions(); selOp.MessageForAdding = "Zu verschiebende Elemente wählen: "; _AcEd.SelectionFilter filter = new _AcEd.SelectionFilter(new _AcDb.TypedValue[] { new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "<NOT"), new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "<AND"), new _AcDb.TypedValue((int)_AcDb.DxfCode.Start, "*POLYLINE"), new _AcDb.TypedValue((int)_AcDb.DxfCode.LayerName, "A_AL_MANSFEN"), new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "AND>"), new _AcDb.TypedValue((int)_AcDb.DxfCode.Operator, "NOT>") }); while (true) { var res = ed.GetSelection(selOp, filter); if (res.Status != _AcEd.PromptStatus.OK) { break; } else { var ss = res.Value; var selOpE = new _AcEd.PromptSelectionOptions(); _AcDb.ObjectId mf1 = default(_AcDb.ObjectId); if (!GetMansfen("Quell-Mansfen wählen: ", ref mf1)) { break; } _AcDb.ObjectId mf2 = default(_AcDb.ObjectId); if (!GetMansfen("Ziel-Mansfen wählen: ", ref mf2)) { break; } if (!SameMansfens(mf1, mf2)) { ed.WriteMessage("\nDie gewählten Mansfens sind nicht identisch!"); System.Windows.Forms.MessageBox.Show("\nDie gewählten Mansfens sind nicht identisch!", "Plan2AufteilungNet"); } else { _AcGe.Point3d fromPoint = GetLuPoint(mf1); _AcGe.Point3d toPoint = GetLuPoint(mf2); string dwgName = doc.Name; var dwgProposal = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(dwgName), System.IO.Path.GetFileNameWithoutExtension(dwgName) + "_X.dwg"); _AcWnd.SaveFileDialog sfd = new _AcWnd.SaveFileDialog("Ziel-Zeichnung", dwgProposal, "dwg", "TargetDrawing", _AcWnd.SaveFileDialog.SaveFileDialogFlags.NoFtpSites); System.Windows.Forms.DialogResult dr = sfd.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.OK) { var ucs = ed.CurrentUserCoordinateSystem; var fromPointU = Globs.TransWcsUcs(fromPoint); // fromPoint.TransformBy(ucs); var toPointU = Globs.TransWcsUcs(toPoint); // toPoint.TransformBy(ucs); // only acad2015 - ed.Command("_.UNDO", "_M"); ed.Command("_.DIMDISASSOCIATE", ss, ""); ed.Command("_.MOVE", ss, "", fromPointU, toPointU); //ed.Command("_.MOVE", ss, "", "0,0", "100,100"); ed.Command("_.ERASE", "_ALL", "_R", ss, mf2, ""); doc.Database.SaveAs(sfd.Filename, false, _AcDb.DwgVersion.Current, doc.Database.SecurityParameters); ed.Command("_.UNDO", "_B"); //doc.SendStringToExecute("._UNDO B", true, false, true); // also supports acad2013 doc.SendStringToExecute(".'_UNDO M ", true, false, true); //acadApp.ActiveDocument.SendCommand("_.UNDO _M\n"); //acadApp.ActiveDocument.SendCommand("_.DIMDISASSOCIATE _P \n"); } } Globs.HightLight(mf1, onOff: false); Globs.HightLight(mf2, onOff: false); } } } catch (System.Exception ex) { string msg = string.Format(CultureInfo.CurrentCulture, "Fehler in (Plan2AufteilungNet): {0}", ex.Message); ed.WriteMessage("\n" + msg); System.Windows.Forms.MessageBox.Show(ex.Message, "Plan2AufteilungNet"); } }