Thanks for the reply Mick,
Please see below my existing method (please ignore the scrappy section creation at the top, I've included it just to give the full picture).
My problem is - the GenerateSectionView method, seems to run on single entities at a time, it never runs using the whole object selection ie. (ss.SetGenerationOptions(SectionType.Section2d, SectionGeneration.SourceAllObjects | SectionGeneration.DestinationNewBlock);
Any help would be massively appreciated... maybe it is time to take the dive into ObjectARX?
Thanks again,
James
using System;
using Autodesk.AutoCAD;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
[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);
}
}
}