public static void SetProgress(int pos) { progressPos = pos; int newPercent = (int)((double)pos / (double)progressSteps * 100.0); if (newPercent > progressPercent) { progressPercent = newPercent; #if AutoCAD Autodesk.AutoCAD.Internal.Utils.SetApplicationStatusBarProgressMeter(newPercent); #else if (progressSteps > 99) { if (newPercent % 10 == 0) { Ac.Write(newPercent.ToString()); Ac.Editor.UpdateScreen(); } else if (newPercent % 2 == 0) { Ac.Write("."); } } //Editor.UpdateScreen(); #endif //DoEvents(); } }
internal void BuildPolygons(System.Windows.Controls.ProgressBar progressBar) { using (var trans = Ac.StartTransaction()) try { progressBar.Maximum = Lines.Count; progressBar.Minimum = 0; foreach (var ln in Lines) { Polyline polyline = new Polyline(); polyline.AddVertex(ln.StartPoint); if (BuildPolygon(polyline, ln.StartPoint, ln)) { polyline.Closed = true; if (polyline.NumberOfVertices > 2) { trans.AddEntity(polyline); } } progressBar.Value = progressBar.Value + 1; System.Windows.Forms.Application.DoEvents(); } trans.Commit(); } catch (System.Exception ex) { Ac.WriteLn("Geo7: " + ex.Message); } }
public int BuildPolygons() { int res = 0; using (var trans = Ac.StartTransaction()) try { Ac.InitProgress(AppServices.Strings.CreatingPolygons, Lines.Count()); foreach (var ln in Lines) { Polyline polyline = new Polyline(); polyline.AddVertex(ln.StartPoint); if (BuildPolygon(polyline, ln.StartPoint, ln)) { res++; polyline.Closed = true; if (polyline.NumberOfVertices > 2) { trans.AddEntity(polyline); } } Ac.ProgressStep(); } Ac.ClearProgress(); trans.Commit(); } catch (System.Exception ex) { Ac.WriteLn("Geo7: " + ex.Message); } return(res); }
public int LoadLinesData() { Lines.Clear(); LinesDict.Clear(); int res = 0; using (var trans = Ac.StartTransaction()) { var acLines = trans.GetAllEntities <Line>(); Ac.InitProgress(AppServices.Strings.LoadingLines, acLines.Count()); foreach (var acLn in acLines) { if (acLn.Length < 0.000001) { continue; } var ln = new AcPolygonSegment(acLn); var lnRev = ln.Reverse(); Lines.Add(ln); LinesDict.AddListItem(ln.StartPoint.Id(), ln); // Trzeba dodać odwrotną linię, bo nie zawsze startPoint jest // z tej strony, z której bym chciał Lines.Add(lnRev); LinesDict.AddListItem(lnRev.StartPoint.Id(), lnRev); res++; Ac.SetProgress(res); } Ac.ClearProgress(); } return(res); }
private static Xrecord GetValueRecord(this AcTransaction trans, string valName) { valName = Ac.GetValidName(valName); var valDict = trans.GetGeo7Dict("Values"); if (valDict.Contains(valName)) { var valId = valDict.GetAt(valName); return(trans.GetObject <Xrecord>(valId)); } else { var typedVal = new TypedValue((int)DxfCode.Text, ""); using (var resBuff = new ResultBuffer(typedVal)) { var xRec = new Xrecord(); xRec.Data = resBuff; valDict.SetAt(valName, xRec); trans.AddNewlyCreatedDBObject(xRec, true); return(xRec); } } //ResultBuffer resbuf = new ResultBuffer( new TypedValue((int)DxfCode.Text, "HELLO"), // new TypedValue((int)DxfCode.Int16, 256), // new TypedValue((int)DxfCode.Real, 25.4)); }
private static ObjectId ImportMissedRecord(SymbolTable srcTable, string key, SymbolTable destTable) { if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("ImportMissedRecord(" + srcTable.GetType().Name + ".key)"); } if (destTable.Has(key)) // It is not missed { return(destTable[key]); } if (!srcTable.Has(key)) { throw new KeyNotFoundException("'" + key + "' not found in " + srcTable.GetType().Name); } Ac.WriteLn("Updating " + destTable.GetType().Name + "... "); // Updating BlockTable... using (var mapping = new IdMapping()) using (var sourceIds = new ObjectIdCollection()) { sourceIds.Add(srcTable[key]); srcTable.Database.WblockCloneObjects(sourceIds, destTable.ObjectId, mapping, DuplicateRecordCloning.Ignore, false); Ac.Write(string.Format("'{0}' added.", key)); // G7-FixedPoint added. return(destTable[key]); } }
/// <summary> /// If there is no value for 'name' empty string ("") is returned. /// </summary> /// <param name="name"></param> /// <returns></returns> public static string GetValue(string name) { using (var docLoc = Ac.Doc.LockDocument()) using (var trans = Ac.StartTransaction()) { return(trans.GetValue(name)); } }
public static void SetValue(string name, string value) { using (var docLoc = Ac.Doc.LockDocument()) using (var trans = Ac.StartTransaction()) { trans.SetValue(name, value); trans.Commit(); } }
public static SelectionFilter GetBlockSelectionFilter(this Editor ed, params string[] blockNames) { var values = new TypedValue[] { Ac.GetTypedValue(DxfCode.Start, "INSERT"), Ac.GetTypedValue(DxfCode.BlockName, blockNames.Join(",")) }; return(new SelectionFilter(values)); }
public static string GetLastFileName(string filter) { var res = Ac.GetValue("FileDialog." + filter); if (string.IsNullOrEmpty(res)) { res = System.IO.Path.ChangeExtension(Ac.Db.Filename, ""); res = res.TrimEnd('.'); } return(res); }
public static void InitProgress(string msg, int stepsCount) { progressPos = 0; progressPercent = 0; progressSteps = stepsCount; #if AutoCAD Autodesk.AutoCAD.Internal.Utils.SetApplicationStatusBarProgressMeter(msg, 0, 100); #else if (progressSteps > 99) { Ac.WriteLn(msg + " 0"); } #endif }
void ICommand.Execute(object parameter) { if (!(this as ICommand).CanExecute(parameter)) { Ac.ShowAlertDialog("Cannot execute " + this.DisplayName + " (Possible reason: there is no drawing environment)"); return; } try { InProgress = true; AppServices.Log.Add(this.GetType().FullName + ": Executing..."); //CommandManager.InvalidateRequerySuggested(); // Requests to modify objects or access AutoCAD can occur in any context, and coming from any number of applications. // To prevent conflicts with other requests, you are responsible for locking a document before you modify it. // http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-A2CD7540-69C5-4085-BCE8-2A8ACE16BFDD //using (var docLock = Ac.Doc.LockDocument()) -> Lock document only when needed (Button pressed) //using (var uiLock = Ac.StartUserInteraction()) -> Lock user interaction only when needed (Button pressed) { ExecuteCore(); //uiLock.End(); } AppServices.Log.Add(this.GetType().FullName + ": Done."); } catch (Exception ex) { Ac.WriteError(ex, this.GetType().Name + ".Execute()", this.DisplayName); if (this.DisplayErrormMessageBox) { Ac.ShowAlertDialog(ex.Message); } } finally { InProgress = false; Ac.ClearProgress(); } var trans = Ac.Db.TransactionManager.TopTransaction; if (trans != null) { trans.Abort(); } CommandManager.InvalidateRequerySuggested(); }
public static void ClearProgress() { try { #if AutoCAD Autodesk.AutoCAD.Internal.Utils.RestoreApplicationStatusBar(); #else Ac.WriteLn(""); #endif DoEvents(); } catch (System.Exception ex) { Ac.WriteError(ex, "Ac.ClearProgress()", null); } }
public void Commit() { DisposeTransactionObjects(); try { if ((this.Transaction != null) && (!this.Transaction.IsDisposed)) { this.Transaction.Commit(); } } catch (Exception ex) { Ac.ShowErr(ex); //throw; }; }
public void Run() { using (var trans = Ac.StartTransaction()) { var allTexts = trans.GetAllEntities <DBText>().Where(t => !string.IsNullOrEmpty(t.TextString.Trim())); var polygons = trans.GetAllEntities <Polyline>().Where(p => (p.Closed == true) && (p.Length > 0.01)); Ac.InitProgress(AppServices.Strings.ProcessingData, polygons.Count()); foreach (var p in polygons) { var pTexts = GetTextsInPolygon(p, allTexts); ChangePolygonLayer(trans, p, pTexts); Ac.ProgressStep(); } Ac.ClearProgress(); trans.Commit(); } }
internal static void WriteError(System.Exception ex, string methodName, string commandName) { Ac.WriteLn(""); Ac.WriteLn("G7 Error: "); AppServices.Log.AddLn(); if (!string.IsNullOrEmpty(commandName)) { AppServices.Log.Add("CommanddName: " + commandName); Ac.WriteLn("CommanddName: " + commandName); } if (!string.IsNullOrEmpty(methodName)) { AppServices.Log.Add("MethodName: " + methodName); Ac.WriteLn("MethodName: " + methodName); } Ac.WriteLn(ex.GetAllMessages()); AppServices.Log.Add(ex); }
public static SortedSet <string> GetBlockNames(bool onlyWithReferences, bool onlyWithAttributes) { var res = new SortedSet <string>(); using (var trans = Ac.StartTransaction()) { var dbBlocks = trans.BlockDefs.AsEnumerable(); if (onlyWithReferences) { dbBlocks = dbBlocks.Where(b => b.HasReferences); } if (onlyWithAttributes) { dbBlocks = dbBlocks.Where(b => b.HasAttributes); } res.AddItems(dbBlocks.Select(b => b.Name)); } return(res); }
public void Run(IEnumerable <Entity> entities, bool showProgress) { BuildEntitiesDict(entities); if (showProgress) { Ac.InitProgress(AppServices.Strings.DeletingDuplicates, entities.Count()); } foreach (var kv in EntitiesDict) { var ids = kv.Value; var ent = kv.Key; if (ent.IsErased) { continue; } foreach (var id in ids) { var duplEnts = IdsDict.GetList(id); foreach (var duplEnt in duplEnts) { if (duplEnt != ent) { duplEnt.UpgradeOpen(); duplEnt.Erase(); } } } if (showProgress) { Ac.ProgressStep(); } } if (showProgress) { Ac.ClearProgress(); } }
public static void Run() { using (var trans = Ac.StartTransaction()) { var polylines = trans.GetAllEntities <Polyline>(); var polygons = polylines.Where(p => p.Closed == true).ToList(); var polygonsByLength = polygons.ToLookup(p => p.Length.ToString(Ac.LinearPrecisionFormat)); Ac.InitProgress(AppServices.Strings.DeletingDuplicates, polygonsByLength.Count); Ac.WriteLn(AppServices.Strings.DeletingDuplicates); foreach (var polygonsWithLength in polygonsByLength) { var ents = polygonsWithLength.ConvertTo <Entity>(); AcRemoveDuplicatedPolygons rdp = new AcRemoveDuplicatedPolygons(); rdp.Run(ents, false); Ac.ProgressStep(); } Ac.ClearProgress(); trans.Commit(); } }
private void ChangePolygonLayer(AcTransaction trans, Polyline polygon, List <DBText> texts) { polygon.UpgradeOpen(); string layerName = ""; if (texts.Count < 1) { layerName = "#PolygonsWithoutTextInside"; } else if (texts.Count == 1) { layerName = texts[0].TextString; } else { var textStrings = from t in texts select t.TextString.Trim(); string prefix = "#" + textStrings.Count().ToString() + "-"; layerName = prefix + textStrings.ToList().Join("-"); } layerName = Ac.GetValidName(layerName); polygon.LayerId = trans.CreateLayer(layerName); }
public static void SetLastFileName(string filter, string value) { Ac.SetValue("FileDialog." + filter, value); }