Message 1 of 2
Create Section
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying create 2D section on 3D Model.
I found two codes from some sites and mixed them then I got what I wanted 90%
https://www.keanw.com/2008/05/sectioning-an-a.html
https://forums.autodesk.com/t5/net/creating-a-section-of-multiple-solids/m-p/6272476#M48298
My problem is some unwanted lines are being seen on hatch area
How can I solve the problem I'm trying to explain with pictures
Thanks
SectionType st= SectionType.Section2d;
st = SectionType.Section3d;
Section sec = new Section(pts, Vector3d.ZAxis)
{
State = SectionState.Plane
};
ObjectId secId = ms.AppendEntity(sec);
tr.AddNewlyCreatedDBObject(sec, true);
sec.SetHeight(SectionHeight.HeightAboveSectionLine, 3.0);
sec.SetHeight(SectionHeight.HeightBelowSectionLine, 2.0);
SectionSettings ss = (SectionSettings)tr.GetObject(sec.Settings, OpenMode.ForWrite);
ss.CurrentSectionType = st;
ss.HatchVisibility(st, SectionGeometry.IntersectionFill);
ss.HiddenLine(st, SectionGeometry.ForegroundGeometry);
ss.SetHatchPatternName(st, SectionGeometry.IntersectionFill, "ANSI31");
ss.SetHatchPatternType(st, SectionGeometry.IntersectionFill, HatchPatternType.PreDefined);
ss.SetHatchVisibility(st, SectionGeometry.IntersectionFill, true);
ss.SetSourceObjects(st, targets);
ss.SetVisibility(st, SectionGeometry.IntersectionFill, true);
ss.SetVisibility(st, SectionGeometry.BackgroundGeometry, true);
ss.SetVisibility(st, SectionGeometry.ForegroundGeometry, false);
ss.SetHiddenLine(st, SectionGeometry.BackgroundGeometry, false);
ss.SetHiddenLine(st, SectionGeometry.ForegroundGeometry, false);
ss.SetGenerationOptions(st, SectionGeneration.SourceSelectedObjects | SectionGeneration.DestinationFile);
Matrix3d transform = Matrix3d.AlignCoordinateSystem( sec.Boundary[0],
sec.Boundary[0].GetVectorTo(sec.Boundary[1]).GetNormal(),
sec.VerticalDirection,
sec.ViewingDirection,
new Point3d.Origin
Vector3d.XAxis,
Vector3d.YAxis,
Vector3d.ZAxis
);
List<Entity> entities = new List<Entity>();
foreach (ObjectId id in targets)
{
Entity entity = (Entity)tr.GetObject(id, OpenMode.ForWrite, true);
Array intersectionBoundary;
Array intersectionFillAnnotation;
Array background;
Array foreground;
Array curveTangency;
if (!(entity is Solid3d || entity is Body || entity is Region || entity is Autodesk.AutoCAD.DatabaseServices.Surface))
continue;
sec.GenerateSectionGeometry(entity, out intersectionBoundary, out intersectionFillAnnotation, out background, out foreground, out curveTangency);
foreach (Entity e in intersectionBoundary)
entities.Add(e);
foreach (Entity e in intersectionFillAnnotation)
entities.Add(e);
foreach (Entity e in background)
entities.Add(e);
foreach (Entity e in foreground)
entities.Add(e);
foreach (Entity e in curveTangency)
entities.Add(e);
}
foreach (Entity entc in entities)
{
entc.TransformBy(transform);
ms.AppendEntity(entc);
tr.AddNewlyCreatedDBObject(entc, true);
}