public static bool GetPoint(ref AcadGeo.Point3d val, string message, AcadGeo.Point3d bp) { AcadApp.DocumentManager.MdiActiveDocument.Window.Focus(); using (AcadApp.DocumentManager.MdiActiveDocument.LockDocument()) { using (AcadDB.Transaction tr = AcadFuncs.GetActiveDoc().TransactionManager.StartTransaction()) { AcadEd.PromptPointOptions prmpt_pnt = new AcadEd.PromptPointOptions(message); prmpt_pnt.UseBasePoint = true; prmpt_pnt.BasePoint = bp; AcadEd.PromptPointResult prmpt_ret = AcadFuncs.GetEditor().GetPoint(prmpt_pnt); if (AcadEd.PromptStatus.Cancel == prmpt_ret.Status) { tr.Abort(); tr.Dispose(); return(false); } val = prmpt_ret.Value; tr.Commit(); } } return(true); }
private void FilterEnts(ref List <AcadDB.ObjectId> ids) { using (AcadDB.Transaction tr = AcadFuncs.GetActiveDB().TransactionManager.StartTransaction()) { foreach (var id in ids.ToList()) { AcadDB.Entity ent = tr.GetObject(id, AcadDB.OpenMode.ForRead) as AcadDB.Entity; if (!(ent is AcadDB.Line)) { ids.Remove(id); } } } }
public void BuildProfile() { //double width = 0.0; if (!AcadFuncs.GetDouble(ref width, "Nhập chiều rộng:")) { throw new Exception("Cancel process"); } //double height = 0.0; if (!AcadFuncs.GetDouble(ref height, "Nhập chiều cao:")) { throw new Exception("Cancel process"); } if (!AcadFuncs.GetDouble(ref thickness, "Nhập độ dày:")) { throw new Exception("Cancel process"); } //AcadGeo.Point3d bp = new AcadGeo.Point3d(); //while (true) //{ // if (!AcadFuncs.GetPoint(ref bp, "Chọn điểm bắt đầu:")) // throw new Exception("Cancel process"); // if (null != FindNode(bp)) // break; //} //AcadGeo.Point3d vp = new AcadGeo.Point3d(); //if (!AcadFuncs.GetPoint(ref vp, "Chọn hướng:", bp)) // throw new Exception("Cancel process"); //AcadGeo.Point3d up = new AcadGeo.Point3d(); //if (!AcadFuncs.GetPoint(ref up, "Chọn up:", bp)) // throw new Exception("Cancel process"); AcadGeo.Point3d bp = new AcadGeo.Point3d(); AcadGeo.Vector3d up_vec = new AcadGeo.Vector3d(); AcadGeo.Vector3d norm = new AcadGeo.Vector3d(); AutoDetectParams(ref bp, ref up_vec, ref norm); profile.Width = width; profile.Height = height; profile.Thickness = thickness; profile.BasePoint = bp; profile.NormalVector = norm; profile.UpVector = up_vec; }
private double AngleElbow(Node n) { if (ELBOW_CONNS != n.Connections.Count) { return(AcadFuncs.kPI * 0.5); } AcadGeo.Vector3d vec1 = n.Position.IsEqualTo(n.Connections[0].Source.Position) ? AcadFuncs.GetVec(n.Connections[0].Source.Position, n.Connections[0].Target.Position) : AcadFuncs.GetVec(n.Connections[0].Target.Position, n.Connections[0].Source.Position); AcadGeo.Vector3d vec2 = n.Position.IsEqualTo(n.Connections[1].Target.Position) ? AcadFuncs.GetVec(n.Connections[1].Target.Position, n.Connections[1].Source.Position) : AcadFuncs.GetVec(n.Connections[1].Source.Position, n.Connections[1].Target.Position); return(Math.Abs(vec1.GetAngleTo(vec2))); }
private AcadGeo.Point3d GetMainTeePos(AcadGeo.Point3d pos, AcadGeo.Point3d pos1, AcadGeo.Point3d pos2, AcadGeo.Point3d pos3) { AcadGeo.Vector3d vec1 = AcadFuncs.GetVec(pos, pos1); AcadGeo.Vector3d vec2 = AcadFuncs.GetVec(pos, pos2); AcadGeo.Vector3d vec3 = AcadFuncs.GetVec(pos, pos3); if (vec1.IsParallelTo(vec2)) { return(pos3); } if (vec1.IsParallelTo(vec3)) { return(pos2); } return(pos1); }
//[CommandMethod("RoutingSolid")] public void RoutingSolid() { try { AcadFuncs.GetEditor().WriteMessage("dev by [[email protected]]"); Model model = new Model(); model.BuildModel(); model.BuildProfile(); model.BuildRoutingSolid(); model.RoutingSolid(); } catch (Autodesk.AutoCAD.Runtime.Exception ex) { } finally { } }
private static List <AcadGeo.Point3d> ParseLine(AcadDB.ObjectId id, List <AcadDB.ObjectId> ids) { List <AcadGeo.Point3d> pnts = new List <AcadGeo.Point3d>(); using (AcadDB.Transaction tr = AcadFuncs.GetActiveDB().TransactionManager.StartTransaction()) { AcadDB.Entity ent = tr.GetObject(id, AcadDB.OpenMode.ForRead) as AcadDB.Entity; if (!(ent is AcadDB.Line)) { return(pnts); } AcadDB.Line line = ent as AcadDB.Line; pnts.Add(line.StartPoint); pnts.Add(line.EndPoint); foreach (var tmp_id in ids) { if (id == tmp_id) { continue; } AcadDB.Entity tmp_ent = tr.GetObject(tmp_id, AcadDB.OpenMode.ForRead) as AcadDB.Entity; AcadGeo.Point3dCollection intersected_pnts = new AcadGeo.Point3dCollection(); line.IntersectWith(tmp_ent, AcadDB.Intersect.OnBothOperands, intersected_pnts, (IntPtr)0, (IntPtr)0); for (int i = 0; i < intersected_pnts.Count; i++) { if (intersected_pnts[i].IsEqualTo(line.StartPoint) || intersected_pnts[i].IsEqualTo(line.EndPoint)) { continue; } pnts.Add(intersected_pnts[i]); } } } pnts.Sort((x, y) => x.DistanceTo(pnts.First()).CompareTo(y.DistanceTo(pnts.First()))); pnts = pnts.Distinct().ToList(); return(pnts); }
public void BuildModel() { List <AcadDB.ObjectId> obj_ids = AcadFuncs.PickEnts(); if (0 == obj_ids.Count) { throw new Exception("No Object is selected"); } FilterEnts(ref obj_ids); foreach (var id in obj_ids) { List <AcadGeo.Point3d> pnts = ParseLine(id, obj_ids); for (int i = 0; i < pnts.Count - 1; i++) { Connect(pnts[i], pnts[i + 1]); } } }
public static List <AcadDB.ObjectId> PickEnts() { AcadApp.DocumentManager.MdiActiveDocument.Window.Focus(); using (AcadApp.DocumentManager.MdiActiveDocument.LockDocument()) { using (AcadDB.Transaction tr = AcadFuncs.GetActiveDoc().TransactionManager.StartTransaction()) { AcadEd.PromptSelectionResult prmpt_ret = AcadFuncs.GetEditor().GetSelection(); if (AcadEd.PromptStatus.Cancel == prmpt_ret.Status) { tr.Abort(); tr.Dispose(); return(new List <AcadDB.ObjectId>()); } tr.Commit(); return(prmpt_ret.Value.GetObjectIds().ToList()); } } }
private string GetContent(ObjectId id) { using (Transaction tr = AcadFuncs.GetActiveDB().TransactionManager.StartTransaction()) { var obj = tr.GetObject(id, OpenMode.ForRead); DBText text = obj as DBText; if (null != text) { return(text.TextString); } MText mtext = obj as MText; if (null != mtext) { return(mtext.Text); } } return(""); }
public static bool GetDouble(ref double val, string message) { AcadApp.DocumentManager.MdiActiveDocument.Window.Focus(); using (AcadApp.DocumentManager.MdiActiveDocument.LockDocument()) { using (AcadDB.Transaction tr = AcadFuncs.GetActiveDoc().TransactionManager.StartTransaction()) { AcadEd.PromptDoubleOptions prmpt_pnt = new AcadEd.PromptDoubleOptions(message); AcadEd.PromptDoubleResult prmpt_ret = AcadFuncs.GetEditor().GetDouble(prmpt_pnt); if (AcadEd.PromptStatus.Cancel == prmpt_ret.Status) { tr.Abort(); tr.Dispose(); return(false); } val = prmpt_ret.Value; tr.Commit(); } } return(true); }
private AcadGeo.Point3d GetPosition(ObjectId id, out bool valid) { using (Transaction tr = AcadFuncs.GetActiveDB().TransactionManager.StartTransaction()) { valid = true; var obj = tr.GetObject(id, OpenMode.ForWrite); DBText text = obj as DBText; if (null != text) { text.Justify = AttachmentPoint.BottomLeft; return(text.Position); } MText mtext = obj as MText; if (null != mtext) { mtext.SetAttachmentMovingLocation(AttachmentPoint.BottomLeft); return(mtext.Location); } valid = false; return(new AcadGeo.Point3d()); } }
private AcadGeo.Vector3d ConnVec(Connection conn) { return(AcadFuncs.GetVec(conn.Target.Position, conn.Source.Position)); }
private Solid.Profile CalculateProfile(AcadGeo.Point3d pnt) { Solid.Profile ret_prol = new Solid.Profile(profile); Node sn = FindNode(ret_prol.BasePoint); Node dn = FindNode(pnt); if (sn == dn) { return(ret_prol); } if (null == sn || null == dn) { return(null); } IEnumerable <Connection> routes = null; TryFunc <Node, IEnumerable <Connection> > func = routers.ShortestPathsDijkstra(e => 1, sn); if (func(dn, out routes)) { if (null == routes || 0 == routes.Count()) { return(null); } List <AcadGeo.Point3d> route_pnts = new List <AcadGeo.Point3d>(); route_pnts.Add(sn.Position); for (int i = 0; i < routes.Count(); i++) { if (routes.ElementAt(i).Source.Position.IsEqualTo(route_pnts.Last())) { route_pnts.Add(routes.ElementAt(i).Target.Position); } else { route_pnts.Add(routes.ElementAt(i).Source.Position); } } if (route_pnts.Count > 1) { ret_prol.Rotate(AcadFuncs.GetVec(route_pnts[0], route_pnts[1])); } for (int i = 0; i < route_pnts.Count() - 1; i++) { AcadGeo.Point3d sc = route_pnts.ElementAt(i); AcadGeo.Point3d dc = route_pnts.ElementAt(i + 1); ret_prol.Translate(AcadFuncs.GetVec(dc, sc) * sc.DistanceTo(dc)); if (i > 0) { ret_prol.Rotate(ret_prol.BasePoint.IsEqualTo(dc) ? AcadFuncs.GetVec(dc, sc) : AcadFuncs.GetVec(sc, dc)); } } return(ret_prol); } return(null); }
public void BuildRoutingSolid() { List <Node> nodes = routers.Vertices.ToList(); foreach (var n in nodes.ToList()) { nodes.Remove(n); if (n.Connections.Count > 4) { continue; } foreach (var conn in n.Connections) { Node sn = n.GetConnection(conn); if (null != nodes.Find(x => x == sn)) { Solid.Straight solid = BuildStraight(n, sn); if (null != solid) { Solid.Profile cal_prol = CalculateProfile(n.Position); cal_prol.Rotate(AcadFuncs.GetVec(sn.Position, n.Position)); solid.Profile = cal_prol; solids.Add(solid); } } } if (ELBOW_CONNS == n.Connections.Count) { Solid.Elbow elbow = new Solid.Elbow(); elbow.Position = n.Position; AcadGeo.Point3d[] bps = new AcadGeo.Point3d[2]; bps[0] = n.Connections[0].Source.Position == n.Position ? n.Connections[0].Target.Position : n.Connections[0].Source.Position; bps[1] = n.Connections[1].Source.Position == n.Position ? n.Connections[1].Target.Position : n.Connections[1].Source.Position; elbow.BranchPos = bps; elbow.Profile = CalculateProfile(n.Position); elbow.Radius = width; elbow.CalculateAngle(); solids.Add(elbow); } else if (TEE_CONNS == n.Connections.Count) { Solid.Tee tee = new Solid.Tee(); tee.Position = n.Position; tee.MainBranchPosition = GetMainTeePos(n.Position, n.Connections[0].ConnectedPos(n.Position), n.Connections[1].ConnectedPos(n.Position), n.Connections[2].ConnectedPos(n.Position)); tee.BranchPosition = GetBranchTeePos(n.Position, n.Connections[0].ConnectedPos(n.Position), n.Connections[1].ConnectedPos(n.Position), n.Connections[2].ConnectedPos(n.Position)); tee.Profile = CalculateProfile(n.Position); tee.Radius = width; solids.Add(tee); } else if (CROSSING_CONNS == n.Connections.Count) { Solid.Crossing crossing = new Solid.Crossing(); crossing.Position = n.Position; crossing.MainBranchPosition = GetMainTeePos(n.Position, n.Connections[0].ConnectedPos(n.Position), n.Connections[1].ConnectedPos(n.Position), n.Connections[2].ConnectedPos(n.Position)); crossing.BranchPosition = GetBranchTeePos(n.Position, n.Connections[0].ConnectedPos(n.Position), n.Connections[1].ConnectedPos(n.Position), n.Connections[2].ConnectedPos(n.Position)); crossing.Profile = CalculateProfile(n.Position); crossing.Radius = width; solids.Add(crossing); } } }
public void SetupDeltaY() { AcadFuncs.GetDouble(ref delta_y, "Nhap khoang cach:"); }
private Solid.Straight BuildStraight(Node sn, Node en) { double length = sn.Position.DistanceTo(en.Position); AcadGeo.Vector3d vec = AcadFuncs.GetVec(sn.Position, en.Position); Solid.Straight straight = new Solid.Straight(); if (ELBOW_CONNS == sn.Connections.Count) { double angle = AngleElbow(sn); if (Math.Abs(Math.Sin(angle * 0.5)) < 0.001 || Math.Abs(Math.Cos(angle * 0.5)) < 0.001) { straight.StartPosition = sn.Position - vec * width; length -= width; } else { straight.StartPosition = sn.Position - vec * (width / Math.Tan(angle * 0.5)); length -= width / Math.Tan(angle * 0.5); } } else if (sn.Connections.Count > 1) { straight.StartPosition = sn.Position - vec * width; length -= width; } else { straight.StartPosition = sn.Position; } if (ELBOW_CONNS == en.Connections.Count) { double angle = AngleElbow(en); if (Math.Abs(Math.Sin(angle * 0.5)) < 0.001 || Math.Abs(Math.Cos(angle * 0.5)) < 0.001) { straight.EndPosition = en.Position + vec * width; length -= width; } else { straight.EndPosition = en.Position + vec * (width / Math.Tan(angle * 0.5)); length -= width / Math.Tan(angle * 0.5); } } else if (en.Connections.Count > 1) { straight.EndPosition = en.Position + vec * width; } else { straight.EndPosition = en.Position; } if (length > 0.0) { return(straight); } else { return(null); } }
public void JoinText2() { var ent_ids = AcadFuncs.PickEnts(); if (0 == ent_ids.Count) { return; } AcadGeo.Point3d ins_pnt = new AcadGeo.Point3d(); if (!AcadFuncs.GetPoint(ref ins_pnt, "Chon vi tri text:")) { return; } var watch = System.Diagnostics.Stopwatch.StartNew(); //C5.IntervalHeap<JoinEnt> data = new C5.IntervalHeap<JoinEnt>(); List <JoinEnt> data = new List <JoinEnt>(); for (int i = 0; i < ent_ids.Count; i++) { bool valid = true; JoinEnt je = new JoinEnt(ent_ids[i], GetPosition(ent_ids[i], out valid)); if (valid) { data.Add(je); } } //data.Sort((item1, item2) => item1.pos.Y.CompareTo(item2.pos.Y)); data.Sort(); while (data.Count > 0) { JoinEnt je = data.Min(); //data.DeleteMin(); data.RemoveAt(0); List <JoinEnt> ents = new List <JoinEnt>(); ents.Add(je); while (data.Count > 0) { bool export = false; if (Math.Abs(data.Min().pos.Y - je.pos.Y) < delta_y) { ents.Add(data.Min()); //data.DeleteMin(); } else { export = true; } if (0 == data.Count || export) { ents.Sort((item1, item2) => item1.pos.X.CompareTo(item2.pos.X)); DBText text = new DBText(); text.TextString += GetContent(ents[0].id); text.TextString += "_"; for (int i = 1; i < ents.Count; i++) { text.TextString += GetContent(ents[i].id); text.TextString += "x"; } text.TextString = text.TextString.Substring(0, text.TextString.Count() - 1); text.Position = ins_pnt; text.Height = 1.0; ins_pnt = new AcadGeo.Point3d(ins_pnt.X, ins_pnt.Y + text.Height * 2.0, ins_pnt.Z); AcadFuncs.AddNewEnt(text); break; } } } AcadFuncs.GetEditor().WriteMessage("\nDone By [email protected]\n"); watch.Stop(); AcadFuncs.GetEditor().WriteMessage(watch.ElapsedMilliseconds.ToString()); }