Author Topic: GenerateSectionGeometry Problem  (Read 2087 times)

0 Members and 1 Guest are viewing this topic.

JayH

  • Guest
GenerateSectionGeometry Problem
« on: November 21, 2018, 11:34:19 AM »
Hi All,

This is a my first post, so hello, and thank you in advance for any help!

I just wondered if anyone had ever been able to successfully reproduce generating a section view of multiple objects? I am hoping to achieve a dialog-free version of 'Generate Section Block' command.

In C# I am trying to use the 'GenerateSectionGeometry' method, but with little luck... Can anybody help?


Thanks,
James

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: GenerateSectionGeometry Problem
« Reply #1 on: November 21, 2018, 03:27:53 PM »
Hi James, welcome aboard!

It seems like the GenerateSectionGeometry is a COM method so I'm assuming you have the relevant settings and lib's loaded.
Do you have any code to share to get started with?

Another option is the HLR (Hidden Line Removal) engine but I'm not sure if there's a .net wrapper for it yet(?). It's a very powerful tool to create any view/s you would like.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

JayH

  • Guest
Re: GenerateSectionGeometry Problem
« Reply #2 on: November 22, 2018, 04:33:00 AM »
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



Code: [Select]
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;

Code: [Select]
[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);
}
}
}

Bryco

  • Water Moccasin
  • Posts: 1883
Re: GenerateSectionGeometry Problem
« Reply #3 on: November 22, 2018, 02:34:59 PM »
double wHeight = ppr1.Value.Y - ppr2.Value.Y;
if y1=10 and y2=-10  wHeight=20
It seems there is no need for a corner just pick the 2 points for the section
« Last Edit: November 22, 2018, 03:20:26 PM by Bryco »