[CommandMethod("вв_(ПТО_№2:выбор по фильтру)")] //, CommandFlags.Redraw)]
public void Vibor_Setup()
{
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
TypedValue[] acTypValAr = new TypedValue[2];
if (ac_Vibor.set_RGB == false)
{
acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, FiltrPerem.nameObj), 0);
acTypValAr.SetValue(new TypedValue((int)DxfCode.LayerName, FiltrPerem.nameLayer), 1);
}
else
{
ac_Vibor.LayerRGB = ac_Vibor.LayerRGB.Trim();
string[] LayerRGBtemp = new string []{ };
LayerRGBtemp = ac_Vibor.LayerRGB.Split(';');
Array.Resize(ref acTypValAr, acTypValAr.Length + 1);
acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, FiltrPerem.nameObj), 0);
acTypValAr.SetValue(new TypedValue((int)DxfCode.LayerName, FiltrPerem.nameLayer), 1);
int color1 = eColor1.TrueColor;
acTypValAr.SetValue(new TypedValue((int)DxfCode.ColorRgb, color1), 2);
acTypValAr.SetValue(new TypedValue((int)DxfCode.Operator, "<or"),2);
int j = 3;
string[] LayerRGB = new string[] { };
LayerRGB = ac_Vibor.LayerRGB.Split(',',';');
for (int i = 0; i < LayerRGB.Length; i=i+3)
{
Array.Resize(ref acTypValAr, acTypValAr.Length + 1);
//EntityColor eColor1 = new EntityColor(37, 88, 218);
EntityColor eColor1 = new EntityColor(Convert.ToByte(LayerRGB[i]), Convert.ToByte(LayerRGB[i+1]), Convert.ToByte(LayerRGB[i+2]));
int color1 = eColor1.TrueColor;
acTypValAr.SetValue(new TypedValue((int)DxfCode.ColorRgb, color1), j);
j++;
}
acTypValAr.SetValue(new TypedValue((int)DxfCode.Operator, "or>"),j);
}
// Назначение критериев фильтра объекту SelectionFilter
SelectionFilter acSelFtr = new SelectionFilter(acTypValAr);
// Запрос выбора объектов на чертеже
PromptSelectionResult acSSPrompt;
try
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
string boolHyp = "";
List<ObjectId> objects = new List<ObjectId>();
//ed.WriteMessage("\nDXF name: " + asObjId.ObjectClass.DxfName);
//ed.WriteMessage("\nObjectID: " + asObjId.ToString());
//ed.WriteMessage("\nHandle: " + asObjId.Handle.ToString());
//ed.WriteMessage("\n");
if (ac_Vibor.nameHyp != boolHyp && ac_Vibor.nameHyp != null)
{
foreach (ObjectId asObjId in acSSPrompt.Value.GetObjectIds())
{
string HyperName = null;
if (asObjId.ObjectClass.Name == "AcDbPolyline")
{
Polyline plln = trans.GetObject(asObjId, OpenMode.ForRead) as Polyline;
foreach (HyperLink hyper in plln.Hyperlinks)
{
HyperName = hyper.Description.ToString();
if (HyperName.Contains(ac_Vibor.nameHyp)) objects.Add(asObjId);
}
}
if (asObjId.ObjectClass.Name == "AcDline")
{
Line plln = trans.GetObject(asObjId, OpenMode.ForRead) as Line;
foreach (HyperLink hyper in plln.Hyperlinks)
{
HyperName = hyper.Description.ToString();
if (HyperName.Contains(ac_Vibor.nameHyp)) objects.Add(asObjId);
}
}
if (asObjId.ObjectClass.Name == "AcDbHatch")
{
Hatch plln = trans.GetObject(asObjId, OpenMode.ForRead) as Hatch;
foreach (HyperLink hyper in plln.Hyperlinks)
{
HyperName = hyper.Description.ToString();
if (HyperName.Contains(ac_Vibor.nameHyp)) objects.Add(asObjId);
}
}
}
}
else
{
foreach (ObjectId asObjId in acSSPrompt.Value.GetObjectIds())
{
if (ac_Vibor.set_RGB == true)
{
objects.Add(asObjId);
}
else
{
objects.Add(asObjId);
}
}
}
ed.SetImpliedSelection(objects.ToArray());
trans.Commit();//Это обязательно даже если ничего не меняешь в рисунке
ac_Vibor.objects.Clear();
ac_Vibor.objects = objects;
if (ac_Vibor.set_VV == true)
{
AcIt.Utils.SelectObjects(objects.ToArray());
doc.SendStringToExecute("КОПИЯВСЛОЙ\n", true, false, true);
}
}
}
catch (System.NullReferenceException)
{
ed.WriteMessage("\nНичего не найдено!!!");
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
acadApp.ShowAlertDialog(ex.Message);
}
}
}