highlightNestedEntity() { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; PromptNestedEntityResult rs = ed.GetNestedEntity("\nSelect nested entity: "); if (rs.Status == PromptStatus.OK) { ObjectId[] objIds = rs.GetContainers(); ObjectId ensel = rs.ObjectId; int len = objIds.Length; // Reverse the "containers" list ObjectId[] revIds = new ObjectId[len + 1]; for (int i = 0; i < len; i++) { ObjectId id = (ObjectId)objIds.GetValue(len - i - 1); revIds.SetValue(id, i); } // Now add the selected entity to the end revIds.SetValue(ensel, len); // Retrieve the sub-entity path for this entity SubentityId subEnt = new SubentityId(SubentityType.Null, (IntPtr)0); FullSubentityPath path = new FullSubentityPath(revIds, subEnt); try { using (Transaction tr = BaseObjs.startTransactionDb()) { // Open the outermost container... ObjectId id = (ObjectId)revIds.GetValue(0); Entity ent = (Entity)tr.GetObject(id, OpenMode.ForRead); // ... and highlight the nested entity ent.Highlight(path, false); tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " View.cs: line: 162"); } } }
/// <summary> /// Функция производит "мигание" объектом при помощи Highlight/Unhighlight /// </summary> /// <param name="id">ObjectId для примитива</param> /// <param name="num">Количество "миганий"</param> /// <param name="delay1">Длительность "подсвеченного" состояния</param> /// <param name="delay2">Длительность "неподсвеченного" состояния</param> public static void FlickObjectHighlight(this ObjectId id, int num, int delay1, int delay2) { var doc = Application.DocumentManager.MdiActiveDocument; for (var i = 0; i < num; i++) { // Highlight entity using (doc.LockDocument()) using (var tr = doc.TransactionManager.StartTransaction()) { var en = (Entity)tr.GetObject(id, OpenMode.ForWrite); var ids = new ObjectId[1]; ids[0] = id; var index = new SubentityId(SubentityType.Null, IntPtr.Zero); var path = new FullSubentityPath(ids, index); en.Highlight(path, true); tr.Commit(); } doc.Editor.UpdateScreen(); // Wait for delay1 msecs Thread.Sleep(delay1); // Unhighlight entity using (doc.LockDocument()) using (var tr = doc.TransactionManager.StartTransaction()) { var en = (Entity)tr.GetObject(id, OpenMode.ForWrite); var ids = new ObjectId[1]; ids[0] = id; var index = new SubentityId(SubentityType.Null, IntPtr.Zero); var path = new FullSubentityPath(ids, index); en.Unhighlight(path, true); tr.Commit(); } doc.Editor.UpdateScreen(); // Wait for delay2 msecs Thread.Sleep(delay2); } }
/// <summary> /// Функция производит "мигание" подобъектом при помощи Highlight/Unhighlight /// </summary> /// <param name="idsPath">Цепочка вложенности объектов. BlockReference->Subentity</param> /// <param name="num">Количество "миганий"</param> /// <param name="delay1">Длительность "подсвеченного" состояния</param> /// <param name="delay2">Длительность "неподсвеченного" состояния</param> public static void FlickSubentityHighlight(ObjectId[] idsPath, int num, int delay1, int delay2) { var doc = Application.DocumentManager.MdiActiveDocument; for (var i = 0; i < num; i++) { // Highlight entity using (doc.LockDocument()) using (var tr = doc.TransactionManager.StartTransaction()) { var subId = new SubentityId(SubentityType.Null, IntPtr.Zero); var path = new FullSubentityPath(idsPath, subId); var ent = (Entity)idsPath[0].GetObject(OpenMode.ForRead); ent.Highlight(path, true); tr.Commit(); } doc.Editor.UpdateScreen(); // Wait for delay1 msecs Thread.Sleep(delay1); // Unhighlight entity using (doc.LockDocument()) using (var tr = doc.TransactionManager.StartTransaction()) { var subId = new SubentityId(SubentityType.Null, IntPtr.Zero); var path = new FullSubentityPath(idsPath, subId); var ent = (Entity)idsPath[0].GetObject(OpenMode.ForRead); ent.Unhighlight(path, true); tr.Commit(); } doc.Editor.UpdateScreen(); // Wait for delay2 msecs Thread.Sleep(delay2); } }
/// <summary> /// Функция производит "мигание" объектом при помощи Highlight/Unhighlight /// </summary> /// <param name="id">ObjectId для примитива</param> /// <param name="num">Количество "миганий"</param> /// <param name="delay1">Длительность "подсвеченного" состояния</param> /// <param name="delay2">Длительность "неподсвеченного" состояния</param> public static void FlickObjectHighlight(this ObjectId id, int num, int delay1, int delay2) { Document doc = Application.DocumentManager.MdiActiveDocument; for (int i = 0; i < num; i++) { // Highlight entity using (DocumentLock doclock = doc.LockDocument()) { using (Transaction tr = doc.TransactionManager.StartTransaction()) { Entity en = (Entity)tr.GetObject(id, OpenMode.ForWrite); ObjectId[] ids = new ObjectId[1]; ids[0] = id; SubentityId index = new SubentityId(SubentityType.Null, 0); FullSubentityPath path = new FullSubentityPath(ids, index); en.Highlight(path, true); tr.Commit(); } } doc.Editor.UpdateScreen(); // Wait for delay1 msecs Thread.Sleep(delay1); // Unhighlight entity using (DocumentLock doclock = doc.LockDocument()) { using (Transaction tr = doc.TransactionManager.StartTransaction()) { Entity en = (Entity)tr.GetObject(id, OpenMode.ForWrite); ObjectId[] ids = new ObjectId[1]; ids[0] = id; SubentityId index = new SubentityId(SubentityType.Null, 0); FullSubentityPath path = new FullSubentityPath(ids, index); en.Unhighlight(path, true); tr.Commit(); } } doc.Editor.UpdateScreen(); // Wait for delay2 msecs Thread.Sleep(delay2); } }
/// <summary> /// TODO /// </summary> /// <param name="acSol"></param> /// <param name="subId"></param> public EntInfo(Solid3d acSol, SubentityId subId, Database acCurDb, Transaction acTrans) { ObjId = acSol.ObjectId; Hndl = acSol.Handle; SubId = subId; EntLayer = acSol.Layer; EntColor = acSol.Color; EntMaterial = acSol.Material; TxDirection = TextureDirection.Unknown; RcName = string.Empty; IsSweep = false; IsMirror = false; IsChild = false; RcInfo = string.Empty; RcQtyOf = 0; RcQtyTotal = 0; LayMatrix = Matrix3d.Identity; AsymmetryVector = new Vector3d(); NumberOfChanges = acSol.NumChanges; ParentHandle = acSol.Handle; ChildHandles = new List <Handle>(); ReadEntity(acSol, acCurDb, acTrans); }
private static void HighlightSubEntity(Document doc, PromptNestedEntityResult rs) { // Extract relevant information from the prompt object ObjectId selId = rs.ObjectId; ObjectId[] objIds = rs.GetContainers(); int len = objIds.Length; // Reverse the "containers" list ObjectId[] revIds = new ObjectId[len + 1]; for (int i = 0; i < len; i++) { ObjectId id = (ObjectId)objIds.GetValue(len - i - 1); revIds.SetValue(id, i); } // Now add the selected entity to the end revIds.SetValue(selId, len); // Retrieve the sub-entity path for this entity SubentityId subEnt = new SubentityId(SubentityType.Null, 0); FullSubentityPath path = new FullSubentityPath(revIds, subEnt); // Open the outermost container, relying on the open // transaction... ObjectId id2 = (ObjectId)revIds.GetValue(0); Entity ent = id2.GetObject(OpenMode.ForRead) as Entity; // ... and highlight the nested entity if (ent != null) { ent.Highlight(path, false); } }
getNestedEntity(string prompt, out bool escape, out Point3d pnt3dX, out string nameLayer, out FullSubentityPath path) { nameLayer = ""; Entity ent = null; Database db = BaseObjs._db; path = new FullSubentityPath(); Editor ed = BaseObjs._editor; PromptNestedEntityOptions pneo = new PromptNestedEntityOptions(prompt); PromptNestedEntityResult pner = ed.GetNestedEntity(pneo); if (pner.Status == PromptStatus.Cancel || pner.Status == PromptStatus.None) { pnt3dX = Pub.pnt3dO; escape = true; return(null); } pnt3dX = pner.PickedPoint; try { using (Transaction tr = BaseObjs.startTransactionDb()) { if (pner.Status == PromptStatus.OK) { escape = false; ObjectId[] idsContainers = pner.GetContainers(); ObjectId idSel = pner.ObjectId; int len = idsContainers.Length; ObjectId[] idsRev = new ObjectId[len + 1]; //Reverse the "containers" list for (int i = 0; i < len; i++) { ObjectId id = (ObjectId)idsContainers.GetValue(len - 1 - i); idsRev.SetValue(id, i); } //Now add the selected entity to the end of the array idsRev.SetValue(idSel, len); //Retrieve the sub-entity path for this entity SubentityId idSubEnt = new SubentityId(SubentityType.Null, (IntPtr)0); path = new FullSubentityPath(idsRev, idSubEnt); ObjectId idX = (ObjectId)idsRev.GetValue(0); ent = (Entity)tr.GetObject(idX, OpenMode.ForRead); ent.Highlight(path, false); DBObject obj = idSel.GetObject(OpenMode.ForRead); ObjectId idOwner = ObjectId.Null; if (obj is PolylineVertex3d || obj is Vertex2d) { idOwner = obj.OwnerId; ent = (Entity)tr.GetObject(idOwner, OpenMode.ForRead); } else if (obj is MText || obj is DBText || !(obj is Entity)) { return(ent); } else { ent = (Entity)obj; } object o = ent.Clone(); Entity clone = (Entity)o; if (clone != null) { //ObjectId[] conts = pner.GetContainers(); foreach (ObjectId idContainer in idsContainers) { BlockReference br = (BlockReference)idContainer.GetObject(OpenMode.ForRead); if (br != null) { clone.SetPropertiesFrom(br); clone.TransformBy(br.BlockTransform); } } BlockTableRecord space = (BlockTableRecord)db.CurrentSpaceId.GetObject(OpenMode.ForWrite); if (space == null) { clone.Dispose(); return(ent); } else if (clone is Arc) { Arc arc = (Arc)clone; pnt3dX = arc.GetClosestPointTo(pnt3dX, false); } else if (clone is Line) { Line line = (Line)clone; pnt3dX = line.GetClosestPointTo(pnt3dX, false); } else if (clone is Polyline) { Polyline poly = (Polyline)clone; pnt3dX = poly.GetClosestPointTo(pnt3dX, false); } else { Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(string.Format("Selected item was of type: {0}. Exiting...", clone.GetType().Name)); } nameLayer = ent.Layer.ToString(); tr.Commit(); return(ent); } } else { escape = true; } } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " xRef.cs: line: 842"); escape = true; } return(ent); }
/// <summary> /// Функция построения корпуса мотора /// </summary> /// <param name="database">База данных</param> /// <param name="trans">Транцакция</param> /// <param name="parameters">Класс с параметрами построения мотора</param> public void Build(Database database, Transaction trans, MotorParameters parameters) { int lenBox = _lenBox; int diameretBox = _diameretBox; // Открываем таблицу блоков для чтения BlockTable blockTable = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable; // Открываем таблицу блоков модели для записи BlockTableRecord blockTableRecord = trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; Solid3d box = new Solid3d(); box.SetDatabaseDefaults(); box.CreateFrustum(lenBox, diameretBox / 2, diameretBox / 2, diameretBox / 2); box.ColorIndex = 4; // Добавляем новый обьект в таблицу блоков и отправляем на транзакцию blockTableRecord.AppendEntity(box); trans.AddNewlyCreatedDBObject(box, true); ObjectId[] ids = new ObjectId[] { box.ObjectId }; SubentityId subentId = new SubentityId(SubentityType.Null, IntPtr.Zero); FullSubentityPath path = new FullSubentityPath(ids, subentId); List <SubentityId> subentIds = new List <SubentityId>(); DoubleCollection radii = new DoubleCollection(); DoubleCollection startSetback = new DoubleCollection(); DoubleCollection endSetback = new DoubleCollection(); // Углы скругления double angTop = 60.0; double angDown = 15.0; using (Autodesk.AutoCAD.BoundaryRepresentation.Brep brep = new Autodesk.AutoCAD.BoundaryRepresentation.Brep(path)) { foreach (Autodesk.AutoCAD.BoundaryRepresentation.Edge edge in brep.Edges) { if (edge.Vertex1.Point.Z == -lenBox / 2) { subentIds.Add(edge.SubentityPath.SubentId); radii.Add(angTop); startSetback.Add(0.0); endSetback.Add(angDown); } if (edge.Vertex1.Point.Z == lenBox / 2) { subentIds.Add(edge.SubentityPath.SubentId); radii.Add(angDown); startSetback.Add(0.0); endSetback.Add(angDown); } } } box.FilletEdges(subentIds.ToArray(), radii, startSetback, endSetback); // Позиция центра новой фигуры box.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, 0) - Point3d.Origin)); double angleRotate = Math.PI / 2; Vector3d vRot = new Point3d(0, 0, 0).GetVectorTo(new Point3d(1, 0, 0)); box.TransformBy(Matrix3d.Rotation(angleRotate, vRot, new Point3d(0, 0, 0))); double radiusBox = diameretBox / 2; double coordinate = (radiusBox * ((Math.Sqrt(2) - 1) / 2) + radiusBox) / Math.Sqrt(2); // Отрисовка лап double lenPaw = 0.9 * lenBox; BuildPawsBox(database, trans, radiusBox / 2, lenBox, radiusBox, -radiusBox, 0); BuildPawsBox(database, trans, radiusBox / 2, lenPaw, coordinate, -coordinate, angleRotate / 2); BuildPawsBox(database, trans, radiusBox / 2, lenBox, -radiusBox, -radiusBox, 0); BuildPawsBox(database, trans, radiusBox / 2, lenPaw, -coordinate, -coordinate, -angleRotate / 2); // Элементы радиатора int n = parameters.CountGrille; double coordX = 0; double coordZ = 0; double angleRadiatorElements = 40; double angleRadiatorStep = 5; if (n > 1) { angleRadiatorStep = 80 / (n - 1); } for (int i = 0; i < n; i++) { if (angleRadiatorElements <= 40 && angleRadiatorElements >= -40) { coordX = radiusBox * Math.Cos(angleRadiatorElements * Math.PI / 180); coordZ = radiusBox * Math.Sin(angleRadiatorElements * Math.PI / 180); BuildRadiator(database, trans, coordX, coordZ); BuildRadiator(database, trans, -coordX, coordZ); angleRadiatorElements -= angleRadiatorStep; } } }
getNestedEntityAndHighlight(Point3d pnt3d, BlockReference br, out FullSubentityPath path, out bool isClosed) { Entity ent = null; isClosed = false; path = new FullSubentityPath(); Editor ed = BaseObjs._editor; PromptNestedEntityOptions pneo = new PromptNestedEntityOptions(""); pneo.NonInteractivePickPoint = pnt3d; pneo.UseNonInteractivePickPoint = true; PromptNestedEntityResult pner = ed.GetNestedEntity(pneo); try { using (Transaction tr = BaseObjs.startTransactionDb()) { if (pner.Status == PromptStatus.OK) { ObjectId[] idsContainers = pner.GetContainers(); ObjectId idSel = pner.ObjectId; int len = idsContainers.Length; ObjectId[] idsRev = new ObjectId[len + 1]; //Reverse the "containers" list for (int i = 0; i < len; i++) { ObjectId id = (ObjectId)idsContainers.GetValue(len - i - 1); idsRev.SetValue(id, i); } //Now add the selected entity to the end of the array idsRev.SetValue(idSel, len); //Retrieve the sub-entity path for this entity SubentityId idSubEnt = new SubentityId(SubentityType.Null, (IntPtr)0); path = new FullSubentityPath(idsRev, idSubEnt); ObjectId idX = (ObjectId)idsRev.GetValue(0); ent = (Entity)tr.GetObject(idX, OpenMode.ForRead); DBObject obj = idSel.GetObject(OpenMode.ForRead); ObjectId idOwner = ObjectId.Null; DBObject objParent = null; if (obj is PolylineVertex3d) { idOwner = obj.OwnerId; objParent = (Polyline3d)idOwner.GetObject(OpenMode.ForRead); Polyline3d poly3d = (Polyline3d)obj; poly3d.Highlight(path, false); isClosed = poly3d.Closed; } else if (obj is Vertex2d) { idOwner = obj.OwnerId; objParent = (Polyline)idOwner.GetObject(OpenMode.ForRead); Polyline poly = (Polyline)obj; poly.Highlight(path, false); isClosed = poly.Closed; } else if (obj is Polyline3d) { objParent = obj; Polyline3d poly3d = (Polyline3d)obj; poly3d.Highlight(path, false); isClosed = poly3d.Closed; } else if (obj is Polyline) { objParent = obj; Polyline poly = (Polyline)obj; poly.Highlight(path, false); isClosed = poly.Closed; } else if (obj is Arc) { objParent = obj; Arc arc = (Arc)obj; arc.Highlight(path, false); isClosed = false; } else if (obj is MText || obj is DBText) { return(null); } ent = (Entity)objParent; } tr.Commit(); } } catch (System.Exception ex) { BaseObjs.writeDebug(ex.Message + " xRef2.cs: line: 108"); } return(ent); }
//[Obsolete] /// <summary> /// Assign to each face by it's identificator a color or materials by boolean. /// </summary> /// <param name="doc_dyn">Current document</param> /// <param name="solids_id_list">List with solid3d ObjectId</param> /// <param name="faces_info_list">List with Dictionaries for each solid (created in Python script).</param> /// <param name="MaterialsByName">Dictionary with materials for names</param> /// <param name="ColorsByNames">Dictionary with colors for names</param> /// <param name="UseColors">If true - using colors; else -- materials</param> public static void SetMaterialByFacesCentroids(Autodesk.AutoCAD.DynamoNodes.Document doc_dyn, List <ObjectId> solids_id_list, List <Dictionary <string, string> > faces_info_list, Dictionary <string, ObjectId> MaterialsByName, Dictionary <string, Autodesk.AutoCAD.Colors.Color> ColorsByNames, bool UseColors = false) { Document doc = doc_dyn.AcDocument; //Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; for (int i2 = 0; i2 < solids_id_list.Count; i2++) { ObjectId OneSolidId = solids_id_list[i2]; Dictionary <string, string> faces_info = faces_info_list[i2]; using (Solid3d OneSolid = OneSolidId.Open(OpenMode.ForWrite) as Solid3d) { FullSubentityPath path = new FullSubentityPath(new ObjectId[1] { OneSolidId }, new SubentityId(SubentityType.Null, IntPtr.Zero)); List <FacesProps> faces = new List <FacesProps>(); using (Brep brep = new Brep(path)) { //List<Autodesk.AutoCAD.BoundaryRepresentation.Face> solid_faces = brep.Faces.ToList(); //foreach (KeyValuePair<string, string> face_info in faces_info) foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face face in brep.Faces) { //int FaceNumber = Convert.ToInt32(face_info.Key.Split('_')[1]); //long FaceNumber = Convert.ToInt64(face_info.Key.Split('_')[1]); //IntPtr face_IntPtr = (IntPtr)FaceNumber; //FullSubentityPath path2 = new FullSubentityPath(new ObjectId[1] { OneSolidId }, new SubentityId(SubentityType.Null, face_IntPtr)); //Autodesk.AutoCAD.BoundaryRepresentation.Face face = solid_faces[FaceNumber]; string Face_Id = $"{OneSolidId.Handle}_{face.SubentityPath.SubentId.IndexPtr.ToInt64()}"; if (faces_info.ContainsKey(Face_Id)) { SubentityId face_id = face.SubentityPath.SubentId; var face_info_material_name = faces_info[Face_Id]; FacesProps face_data = new FacesProps(); if (UseColors == true) { face_data.color = ColorsByNames[face_info_material_name]; } else { face_data.material = MaterialsByName[face_info_material_name]; } face_data.id = face_id; faces.Add(face_data); } } } if (UseColors == true) { foreach (FacesProps face_one in faces) { OneSolid.SetSubentityColor(face_one.id, face_one.color); //doc.Editor.WriteMessage($"Color {face_one.color} was assigned for {face_one.id}"); } } else { foreach (FacesProps face_one in faces) { OneSolid.SetSubentityMaterial(face_one.id, face_one.material); //doc.Editor.WriteMessage($"Material was assigned for {face_one.id}"); } } } } }
/// <summary> /// Функция производит "мигание" подобъектом при помощи Highlight/Unhighlight /// </summary> /// <param name="idsPath">Цепочка вложенности объектов. BlockReference->Subentity</param> /// <param name="num">Количество "миганий"</param> /// <param name="delay1">Длительность "подсвеченного" состояния</param> /// <param name="delay2">Длительность "неподсвеченного" состояния</param> public static void FlickSubentityHighlight(ObjectId[] idsPath, int num, int delay1, int delay2) { Document doc = Application.DocumentManager.MdiActiveDocument; for (int i = 0; i < num; i++) { // Highlight entity using (DocumentLock doclock = doc.LockDocument()) { using (Transaction tr = doc.TransactionManager.StartTransaction()) { SubentityId subId = new SubentityId(SubentityType.Null, 0); FullSubentityPath path = new FullSubentityPath(idsPath, subId); var ent = idsPath[0].GetObject(OpenMode.ForRead) as Entity; ent.Highlight(path, true); tr.Commit(); } } doc.Editor.UpdateScreen(); // Wait for delay1 msecs Thread.Sleep(delay1); // Unhighlight entity using (DocumentLock doclock = doc.LockDocument()) { using (Transaction tr = doc.TransactionManager.StartTransaction()) { SubentityId subId = new SubentityId(SubentityType.Null, 0); FullSubentityPath path = new FullSubentityPath(idsPath, subId); var ent = idsPath[0].GetObject(OpenMode.ForRead) as Entity; ent.Unhighlight(path, true); tr.Commit(); } } doc.Editor.UpdateScreen(); // Wait for delay2 msecs Thread.Sleep(delay2); } }