Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using Autodesk;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.Runtime;
- namespace ZaznaczeniePoligonalne
- {
- public class Class1
- {
- [CommandMethod("sel")]
- public void MySelection()
- {
- var listaPunktow = new List<Point3d>();
- Document doc = Application.DocumentManager.MdiActiveDocument;
- //The DocumentManager property of the Application object allows you to access the current document with the MdiActiveDocument property
- Editor ed = doc.Editor;
- Database db = doc.Database;
- var flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
- using (Transaction acTrans = db.TransactionManager.StartTransaction())
- {
- PromptSelectionResult acSSPrompt = doc.Editor.GetSelection();
- if (acSSPrompt.Status == PromptStatus.OK)
- {
- SelectionSet acSSet = acSSPrompt.Value;
- foreach (SelectedObject acSSObj in acSSet)
- {
- if (acSSObj != null)
- {
- Entity acEnt = acTrans.GetObject(acSSObj.ObjectId,
- OpenMode.ForWrite) as Entity;
- var type = acEnt.GetType();
- // https://stackoverflow.com/questions/1196991/get-property-value-from-string-using-reflection-in-c-sharp
- var center = type.GetProperty("Center");
- if (center == null)
- {
- ed.WriteMessage("Nie ma center");
- }
- else
- {
- Point3d centerxD = (Point3d)center.GetValue(acEnt, null);
- listaPunktow.Add(centerxD);
- }
- }
- }
- }
- }
- Point3dCollection pntCol = new Point3dCollection();
- foreach (var punkt in listaPunktow)
- {
- pntCol.Add(punkt);
- }
- int numOfEntsFound = 0;
- PromptSelectionResult pmtSelRes = null;
- TypedValue[] typedVal = new TypedValue[1];
- var gowno = new TypedValue[0];
- typedVal[0] = new TypedValue((int)DxfCode.Start, "Line");
- SelectionFilter selFilter = new SelectionFilter(gowno);
- //PromptSelectionResult prSelRes = ed.SelectCrossingPolygon(pc.Collect());
- pmtSelRes = ed.SelectCrossingPolygon(pntCol, selFilter);
- if (pmtSelRes.Status == PromptStatus.OK)
- {
- using (Transaction acTrans = db.TransactionManager.StartTransaction())
- {
- foreach (ObjectId objId in
- pmtSelRes.Value.GetObjectIds())
- {
- Entity acEnt = acTrans.GetObject(objId, OpenMode.ForWrite) as Entity;
- bool allow = true;
- var type = acEnt.GetType();
- // https://stackoverflow.com/questions/1196991/get-property-value-from-string-using-reflection-in-c-sharp
- var center = type.GetProperty("Center");
- if (center == null)
- {
- ed.WriteMessage("Nie ma center");
- }
- else
- {
- Point3d centerxD = (Point3d)center.GetValue(acEnt, null);
- if (listaPunktow.Contains(centerxD))
- {
- allow = false;
- }
- }
- //http://www.temblast.com/songview/color3.htm
- if (allow)
- {
- acEnt.ColorIndex = 150;
- }
- numOfEntsFound++;
- }
- acTrans.Commit();
- }
- ed.WriteMessage("\nZnaleziono: " + numOfEntsFound.ToString());
- ed.Regen();
- }
- else
- ed.WriteMessage("\nNie znaleziono");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement