感谢Mick的回复,
请查看下面我现有的方法(请忽略顶部的零碎部分创建,我已经包括它只是为了给出完整的图片)。
我的问题是GenerateSectionView方法似乎一次只能在单个实体上运行,它从未使用整个对象选择ie运行。(不锈钢。SetGenerationOptions(section type。Section2d,SectionGeneration。source all objects | section generation。DestinationNewBlock);
非常感谢任何帮助...也许是时候深入了解ObjectARX了?再次感谢詹姆斯代码0]
- [CommandMethod("CreateView", CommandFlags.UsePickSet | CommandFlags.Redraw | CommandFlags.Modal)]
- public void CreateView()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- Point3dCollection pts = new Point3dCollection();
- // Get Corner 1
- PromptPointResult ppr1 = ed.GetPoint("\nPick Top Left Corner: ");
- if (ppr1.Status != PromptStatus.OK)
- return;
- // Get Corner 2
- PromptCornerOptions pco2 = new PromptCornerOptions("\nPick Bottom Right Corner: ", ppr1.Value);
- PromptPointResult ppr2 = ed.GetCorner(pco2);
- if (ppr2.Status != PromptStatus.OK)
- return;
- // Get Left, Right and Middle Points
- double wHeight = ppr1.Value.Y - ppr2.Value.Y;
- double midPoint = ppr2.Value.Y + (wHeight / 2);
- Point3d lPt = new Point3d(ppr1.Value.X, midPoint, 80000);
- Point3d rPt = new Point3d(ppr2.Value.X, midPoint, 80000);
- pts.Add(lPt);
- pts.Add(rPt);
- // Start Transaction
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- try
- {
- BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
- BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- // Create Section
- Section sec = new Section(pts, Vector3d.YAxis);
- sec.State = SectionState.Plane;
- // Add section to the drawing
- ObjectId secId = ms.AppendEntity(sec);
- tr.AddNewlyCreatedDBObject(sec, true);
- // Set up some of its direct properties and settings
- sec.SetHeight(SectionHeight.HeightAboveSectionLine, wHeight / 2);
- sec.SetHeight(SectionHeight.HeightBelowSectionLine, wHeight / 2);
- SectionSettings ss = (SectionSettings)tr.GetObject(sec.Settings, OpenMode.ForWrite);
- ss.CurrentSectionType = SectionType.Section2d;
- ss.SetGenerationOptions(SectionType.Section2d, SectionGeneration.SourceAllObjects | SectionGeneration.DestinationNewBlock);
-
- ss.SetVisibility(SectionType.Section2d, SectionGeometry.IntersectionFill, false);
- ss.SetVisibility(SectionType.Section2d, SectionGeometry.IntersectionFill, false);
- ss.SetVisibility(SectionType.Section2d, SectionGeometry.CurveTangencyLines, false);
- ss.SetVisibility(SectionType.Section2d, SectionGeometry.BackgroundGeometry, true);
- ss.SetHiddenLine(SectionType.Section2d, SectionGeometry.BackgroundGeometry, false);
- Autodesk.AutoCAD.Colors.Color c = new Autodesk.AutoCAD.Colors.Color();
- c = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByLayer, 256);
- ss.SetColor(SectionType.Section2d, SectionGeometry.BackgroundGeometry, c);
- ss.SetLayer(SectionType.Section2d, SectionGeometry.BackgroundGeometry, "*_2D");
- ss.SetLinetype(SectionType.Section2d, SectionGeometry.BackgroundGeometry, "ByLayer");
- ss.SetLineWeight(SectionType.Section2d, SectionGeometry.BackgroundGeometry, LineWeight.ByLayer);
-
- tr.Commit();
- ed.WriteMessage("\n" + "Section created successfully");
- }
- catch (System.Exception ex)
- {
- ed.WriteMessage("\nException: " + ex.Message);
- }
- }
- }
|