// Helper function for OnCommandEnded private void UpdateLinkedEntities(ObjectId from) { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; ObjectIdCollection linked = m_linkManager.GetLinkedObjects(from); Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { try { Point3d firstCenter; Point3d secondCenter; double firstRadius; double secondRadius; Entity ent = (Entity)tr.GetObject(from, OpenMode.ForRead); if (GetCenterAndRadius( ent, out firstCenter, out firstRadius ) ) { foreach (ObjectId to in linked) { Entity ent2 = (Entity)tr.GetObject(to, OpenMode.ForRead); if (GetCenterAndRadius( ent2, out secondCenter, out secondRadius ) ) { Vector3d vec = firstCenter - secondCenter; if (!vec.IsZeroLength()) { // Only move the linked circle if it's not // already near enough double apart = vec.Length - (firstRadius + secondRadius); if (apart < 0.0) { apart = -apart; } if (apart > 0.00001) { ent2.UpgradeOpen(); ent2.TransformBy( Matrix3d.Displacement( vec.GetNormal() * apart ) ); } } } } } } catch (System.Exception ex) { Autodesk.AutoCAD.Runtime.Exception ex2 = ex as Autodesk.AutoCAD.Runtime.Exception; if (ex2 != null && ex2.ErrorStatus != ErrorStatus.WasOpenForUndo) { ed.WriteMessage("\nAutoCAD exception: {0}", ex2); } else if (ex2 == null) { ed.WriteMessage("\nSystem exception: {0}", ex); } } tr.Commit(); } }
// Helper function for OnCommandEnded private void UpdateLinkedEntities(ObjectId from) { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; ObjectIdCollection linked = m_linkManager.GetLinkedObjects(from); Transaction tr = db.TransactionManager.StartTransaction(); using (tr) { try { Point3d polyInters; Point3d circleCenter; double firstRadius; double secondRadius; Entity entPoly = (Entity)tr.GetObject(from, OpenMode.ForRead); if (entPoly.ObjectId.IsValid) { foreach (ObjectId to in linked) { Entity ent2 = (Entity)tr.GetObject(to, OpenMode.ForRead); if (GetCenterAndRadius(ent2, out circleCenter, out secondRadius)) { Polyline3d acPoly3d = (Polyline3d)tr.GetObject(entPoly.ObjectId, OpenMode.ForRead); Point3dCollection acPts3d = new Point3dCollection(); foreach (ObjectId acObjIdVert in acPoly3d) { PolylineVertex3d acPolVer3d; acPolVer3d = tr.GetObject(acObjIdVert, OpenMode.ForRead) as PolylineVertex3d; acPts3d.Add(acPolVer3d.Position); } foreach (Point3d pt in acPts3d) { MoveEntitiy(tr, circleCenter, pt, ent2.ObjectId); } //#region Move Circle to Intersection of Polyline //polyInters = acPoly3d.GetClosestPointTo(circleCenter, true); //MoveEntitiy(tr, circleCenter, polyInters, ent2.ObjectId); //Vector3d vec = polyInters - circleCenter; //double apart = vec.Length - 1; //if (apart > 0.00001) //{ // ent2.UpgradeOpen(); // ent2.TransformBy(Matrix3d.Displacement(vec.GetNormal() * apart)); //} } //#endregion } } } catch (System.Exception ex) { Autodesk.AutoCAD.Runtime.Exception ex2 = ex as Autodesk.AutoCAD.Runtime.Exception; if (ex2 != null && ex2.ErrorStatus != ErrorStatus.WasOpenForUndo) { ed.WriteMessage("\nAutoCAD exception: {0}", ex2); } else if (ex2 == null) { ed.WriteMessage("\nSystem exception: {0}", ex); } } tr.Commit(); } }