Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Autodesk;
  8. using Autodesk.AutoCAD.ApplicationServices;
  9. using Autodesk.AutoCAD.DatabaseServices;
  10. using Autodesk.AutoCAD.EditorInput;
  11. using Autodesk.AutoCAD.Geometry;
  12. using Autodesk.AutoCAD.Runtime;
  13.  
  14. namespace ZaznaczeniePoligonalne
  15. {
  16. public class Class1
  17. {
  18.  
  19.  
  20. [CommandMethod("sel")]
  21. public void MySelection()
  22. {
  23. var listaPunktow = new List<Point3d>();
  24.  
  25. Document doc = Application.DocumentManager.MdiActiveDocument;
  26. //The DocumentManager property of the Application object allows you to access the current document with the MdiActiveDocument property
  27. Editor ed = doc.Editor;
  28. Database db = doc.Database;
  29. var flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
  30. using (Transaction acTrans = db.TransactionManager.StartTransaction())
  31. {
  32. PromptSelectionResult acSSPrompt = doc.Editor.GetSelection();
  33. if (acSSPrompt.Status == PromptStatus.OK)
  34. {
  35. SelectionSet acSSet = acSSPrompt.Value;
  36.  
  37. foreach (SelectedObject acSSObj in acSSet)
  38. {
  39. if (acSSObj != null)
  40. {
  41. Entity acEnt = acTrans.GetObject(acSSObj.ObjectId,
  42. OpenMode.ForWrite) as Entity;
  43. var type = acEnt.GetType();
  44. // https://stackoverflow.com/questions/1196991/get-property-value-from-string-using-reflection-in-c-sharp
  45. var center = type.GetProperty("Center");
  46. if (center == null)
  47. {
  48. ed.WriteMessage("Nie ma center");
  49. }
  50. else
  51. {
  52. Point3d centerxD = (Point3d)center.GetValue(acEnt, null);
  53. listaPunktow.Add(centerxD);
  54. }
  55. }
  56. }
  57. }
  58. }
  59.  
  60. Point3dCollection pntCol = new Point3dCollection();
  61.  
  62. foreach (var punkt in listaPunktow)
  63. {
  64. pntCol.Add(punkt);
  65. }
  66.  
  67. int numOfEntsFound = 0;
  68. PromptSelectionResult pmtSelRes = null;
  69.  
  70. TypedValue[] typedVal = new TypedValue[1];
  71. var gowno = new TypedValue[0];
  72.  
  73. typedVal[0] = new TypedValue((int)DxfCode.Start, "Line");
  74. SelectionFilter selFilter = new SelectionFilter(gowno);
  75. //PromptSelectionResult prSelRes = ed.SelectCrossingPolygon(pc.Collect());
  76. pmtSelRes = ed.SelectCrossingPolygon(pntCol, selFilter);
  77.  
  78. if (pmtSelRes.Status == PromptStatus.OK)
  79. {
  80. using (Transaction acTrans = db.TransactionManager.StartTransaction())
  81. {
  82. foreach (ObjectId objId in
  83. pmtSelRes.Value.GetObjectIds())
  84. {
  85. Entity acEnt = acTrans.GetObject(objId, OpenMode.ForWrite) as Entity;
  86. bool allow = true;
  87. var type = acEnt.GetType();
  88. // https://stackoverflow.com/questions/1196991/get-property-value-from-string-using-reflection-in-c-sharp
  89. var center = type.GetProperty("Center");
  90. if (center == null)
  91. {
  92. ed.WriteMessage("Nie ma center");
  93. }
  94. else
  95. {
  96. Point3d centerxD = (Point3d)center.GetValue(acEnt, null);
  97. if (listaPunktow.Contains(centerxD))
  98. {
  99. allow = false;
  100. }
  101. }
  102.  
  103.  
  104. //http://www.temblast.com/songview/color3.htm
  105. if (allow)
  106. {
  107. acEnt.ColorIndex = 150;
  108. }
  109.  
  110. numOfEntsFound++;
  111. }
  112. acTrans.Commit();
  113. }
  114. ed.WriteMessage("\nZnaleziono: " + numOfEntsFound.ToString());
  115. ed.Regen();
  116. }
  117.  
  118. else
  119. ed.WriteMessage("\nNie znaleziono");
  120.  
  121. }
  122.  
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement