Author Topic: HandOverTo, grips and audit...  (Read 1586 times)

0 Members and 1 Guest are viewing this topic.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
HandOverTo, grips and audit...
« on: January 29, 2014, 06:49:27 AM »
AutoCAD 2009 SP3
AutoCAD 2014 SP1

After my command's work the target entities must to be selected with the grips. But the grips is not displayed for them. If I switch into other Layout\Model and then switch back (or if I save the drawing), I can select this object and see the grips now.

Code - C#: [Select]
  1. // divide2.cs
  2. // © Andrey Bushman, 2014
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.IO;
  8.  
  9. using cad = Autodesk.AutoCAD.ApplicationServices.Application;
  10. using App = Autodesk.AutoCAD.ApplicationServices;
  11. using Ed = Autodesk.AutoCAD.EditorInput;
  12. using Db = Autodesk.AutoCAD.DatabaseServices;
  13. using Gem = Autodesk.AutoCAD.Geometry;
  14. using Rtm = Autodesk.AutoCAD.Runtime;
  15.  
  16. [assembly: Rtm.CommandClass(typeof(Bushman.CAD.Commands.Divide))]
  17.  
  18. namespace Bushman.CAD.Commands {
  19.  
  20.         public class Divide : Rtm.IExtensionApplication {
  21.  
  22.                 const String ns = "Bushman";
  23.                 static Int32 div_count = 2;
  24.                 const String msg0 = "The selection set has not the Line objects.\n";
  25.                 const String msg = "The command is interrupted.\n";
  26.  
  27.                 /// <summary>
  28.                 /// To convert the each Line object in the Pline3d object and
  29.                 /// to divide them on some count of segments.
  30.                 /// </summary>
  31.                 [Rtm.CommandMethod(ns, "divide2", Rtm.CommandFlags.UsePickSet | Rtm.CommandFlags.Redraw
  32.                         | Rtm.CommandFlags.Modal | Rtm.CommandFlags.NoPaperSpace)]
  33.                 public void Divide2() {
  34.                         App.Document doc = cad.DocumentManager.MdiActiveDocument;
  35.                         Ed.Editor ed = doc.Editor;
  36.                         Db.Database db = doc.Database;
  37.                         Ed.PromptSelectionResult psr;
  38.                         psr = ed.SelectImplied();
  39.                         Db.ObjectId[] ids = null;
  40.  
  41.                         if (psr.Status == Ed.PromptStatus.OK) {
  42.                                 ids = psr.Value.GetObjectIds().Where(id => id.ObjectClass.Name == "AcDbLine")
  43.                                         .ToArray();
  44.                                 if (ids != null && ids.Length > 0) ed.SetImpliedSelection(ids);
  45.                                 else {
  46.                                         ed.WriteMessage(msg0);
  47.                                         ed.WriteMessage(msg);
  48.                                         return;
  49.                                 }
  50.                         }
  51.                         else {
  52.                                 Db.TypedValue[] typeValues = new Db.TypedValue[1];
  53.                                 typeValues.SetValue(new Db.TypedValue((Int32)Db.DxfCode.Start, "LINE"), 0);
  54.                                 Ed.SelectionFilter filter = new Ed.SelectionFilter(typeValues);
  55.                                 psr = ed.GetSelection(filter);
  56.                         }
  57.  
  58.                         if (psr.Status != Ed.PromptStatus.OK) {
  59.                                 ed.WriteMessage(msg);
  60.                                 return;
  61.                         }
  62.  
  63.                         if (ids == null) ids = psr.Value.GetObjectIds();
  64.  
  65.  
  66.                         Ed.PromptIntegerOptions pio = new Ed.PromptIntegerOptions("Segments count");
  67.                         pio.AllowNegative = false;
  68.                         pio.AllowNone = false;
  69.                         pio.AllowZero = false;
  70.                         pio.DefaultValue = div_count;
  71.  
  72.                         Ed.PromptIntegerResult result = ed.GetInteger(pio);
  73.                         if (result.Status != Ed.PromptStatus.OK) {
  74.                                 ed.WriteMessage(msg);
  75.                                 return;
  76.                         }
  77.                         else {
  78.                                 div_count = result.Value;
  79.                         }
  80.                        
  81.                         using (Db.OpenCloseTransaction tr = db.TransactionManager.StartOpenCloseTransaction()) {
  82.                                 foreach (Db.ObjectId id in ids) {
  83.                                         Db.Line line = (Db.Line)tr.GetObject(id, Db.OpenMode.ForWrite);
  84.                                         Gem.Point3dCollection points = new Gem.Point3dCollection();
  85.                                         Gem.Point3d point = line.StartPoint;
  86.                                         points.Add(line.StartPoint);
  87.                                         Double dx = line.Delta.X / div_count;
  88.                                         Double dy = line.Delta.Y / div_count;
  89.                                         Double dz = line.Delta.Z / div_count;
  90.                                         for (int i = 1; i < div_count; i++) {
  91.                                                 point = new Gem.Point3d(point.X + dx, point.Y + dy, point.Z + dz);
  92.                                                 points.Add(point);
  93.                                         }
  94.                                         points.Add(line.EndPoint);
  95.  
  96.                                         Db.Polyline3d pline = new Db.Polyline3d(Db.Poly3dType.SimplePoly, points,
  97.                                                 false);
  98.                                         pline.SetDatabaseDefaults();
  99.                                         pline.LayerId = line.LayerId;
  100.                                         pline.Color = line.Color;
  101.                                         pline.ColorIndex = line.ColorIndex;
  102.                                         pline.LinetypeId = line.LinetypeId;
  103.                                         pline.LinetypeScale = line.LinetypeScale;
  104.                                         pline.LineWeight = line.LineWeight;
  105.                                        
  106.                                         line.HandOverTo(pline, true, true);
  107.                                 }
  108.                                 tr.Commit();
  109.                         }
  110.  
  111.                         ed.WriteMessage("Transformed objects count: {0}.\n", ids.Length);
  112.                         ed.SetImpliedSelection(ids);
  113.                 }
  114.  
  115.                 #region IExtensionApplication Members
  116.  
  117.                 public void Initialize() {
  118.                         App.Document doc = cad.DocumentManager.MdiActiveDocument;
  119.                         Ed.Editor ed = doc.Editor;
  120.                         ed.WriteMessage("\n{0}. © Andrey Bushman, 2014\n\n",
  121.                                 Path.GetFileName(this.GetType().Assembly.Location));
  122.                 }
  123.  
  124.                 public void Terminate() {                      
  125.                 }
  126.                 #endregion
  127.         }
  128. }

The _AUDIT command find the some errors, but after the drawing saving the errors is disappear.

The DWG file for testing is attached below.

Quote from: AutoCAD Console
Command: netload
div2.dll. © Andrey Bushman, 2014


Command: divide2

Select objects: Specify opposite corner: 9 found

Select objects:  Segments count <2>: 4
Transformed objects count: 9.

Command: audit

Fix any errors detected? [Yes/No] <N>:



Auditing Header


Auditing Tables


Auditing Entities Pass 1

Pass 1 1900    objects audited
Auditing Entities Pass 2

Pass 2 1800    objects auditedAcDb3dPolyline(1FBF5)             Sequence End
Null or invalid; Not fixed
AcDb3dPolyline(1FBF6)             Sequence End Null or invalid; Not fixed
AcDb3dPolyline(1FBF7)             Sequence End Null or invalid; Not fixed
AcDb3dPolyline(1FBF8)             Sequence End Null or invalid; Not fixed
AcDb3dPolyline(1FC73)             Sequence End Null or invalid; Not fixed
AcDb3dPolyline(1FC74)             Sequence End Null or invalid; Not fixed
AcDb3dPolyline(1FC75)             Sequence End Null or invalid; Not fixed
AcDb3dPolyline(1FC76)             Sequence End Null or invalid; Not fixed
AcDb3dPolyline(1FC77)             Sequence End Null or invalid; Not fixed

Pass 2 1900    objects audited
Auditing Blocks


 42      Blocks audited

Total errors found 9 fixed 0

Erased 0 objects


Command:
Command:
Command: _qsave
Command: AUDIT

Fix any errors detected? [Yes/No] <N>:



Auditing Header


Auditing Tables


Auditing Entities Pass 1

Pass 1 1900    objects audited
Auditing Entities Pass 2

Pass 2 1900    objects audited
Auditing Blocks

 42      Blocks audited

Total errors found 0 fixed 0

Erased 0 objects

How can I fix it?

Thank you.

Andrey Bushman

  • Swamp Rat
  • Posts: 864
Re: HandOverTo, grips and audit...
« Reply #1 on: January 29, 2014, 07:12:37 AM »
The problem is solved: I forgot the AddNewlyCreatedDBObject to write.
Code - C#: [Select]
  1. line.HandOverTo(pline, true, true);
  2. tr.AddNewlyCreatedDBObject(pline,true);