06/05/2018
					Определение радиуса и центра кругового конуса при помощи .NET
Мы можем использовать BREP API для определения радиуса и центра кругового конуса (свойства, показанные на изображении панели свойств).
Ниже фрагмента кода .NET, который можно использовать:
Код - C#: [Выделить]
- [CommandMethod("circularConeRadiusAndCenter")]
 - public void circularConeRadiusAndCenter()
 - {
 - Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
 - Database db = doc.Database;
 - Editor ed = doc.Editor;
 - // Ask the user to select a solid
 - PromptEntityOptions peo = new PromptEntityOptions("Выберите 3Dsolid");
 - peo.SetRejectMessage("\nНужно выбрать 3Dsolid.");
 - peo.AddAllowedClass(typeof(Solid3d), true);
 - PromptEntityResult per = ed.GetEntity(peo);
 - if (per.Status != PromptStatus.OK)
 - return;
 - Transaction tr = db.TransactionManager.StartTransaction();
 - using (tr)
 - {
 - Solid3d sol = tr.GetObject(per.ObjectId, OpenMode.ForRead) as Solid3d;
 - using (Brep brep = new Brep(sol))
 - {
 - // Проверяем, что в основе круг – тогда можно определить центр и радиус
 - foreach (Complex cmp in brep.Complexes)
 - {
 - int edgeCnt = 1;
 - foreach (Edge edge in brep.Edges)
 - {
 - ed.WriteMessage("\n --> Грань : {0}", edgeCnt++);
 - Curve3d edgeCurve = edge.Curve;
 - if (edgeCurve is ExternalCurve3d)
 - {
 - ed.WriteMessage("\n Тип грани : {0}", "ExternalCurve3d");
 - ExternalCurve3d extCurve3d = edgeCurve as ExternalCurve3d;
 - Curve3d nativeCurve = extCurve3d.NativeCurve;
 - if (nativeCurve is CircularArc3d)
 - {
 - ed.WriteMessage("\n Родной тип кривой : {0}", "CircularArc3d");
 - CircularArc3d circArc3d = nativeCurve as CircularArc3d;
 - ed.WriteMessage("\n Радиус: " + circArc3d.Radius.ToString());
 - ed.WriteMessage("\n Центр: " + PointToStr(circArc3d.Center));
 - }
 - else
 - {
 - ed.WriteMessage("\n Родной тип кривой не круг");
 - return;
 - }
 - }
 - }
 - }
 - }
 - }
 - }
 - private string PointToStr(Point3d point)
 - {
 - return "[" +
 - point.X.ToString("F2") + ", " +
 - point.Y.ToString("F2") + ", " +
 - point.Z.ToString("F2")
 - + "]";
 - }
 
                        
						Автор перевода: Александр Ривилис
						
						
					
				Обсуждение: http://adn-cis.org/forum/index.php?topic=
Опубликовано 06.05.2018