Hi @_gile
Here is the code for one of the class within the namespace. As you can see from the code below -
I am executing following steps that are common to most of the classes.
- Create a Polyline.
- Add vertices to this Polyline from Point2dCollection parameter.
- Add newly created Polyline to DBObjectCollection variable.
- Create region.
- Revolve region object about Y-axis 360°.
- Align solid achieved by revolution above to suit desired Direction parameter.
- Move object using Displacement parameter.
I am trying to conceive a function something like a following signature -
RevolveAndAlineObject(Point2dCollection Polypoints, Vector3d Direction, Vector Displacement)
I've written plenty of drafting helper functions in an independent class called DrawingHelper. But, I was thinking to use proposed function within the namespace specified.
Is there a way to create function that will be exclusively used by the classes within the namespace.
Thanks,
Nimish
public class Shell3d
{
private double _InsideDiameter, _Thickness, _Length;
private Point3d _Location;
private Vector3d _Direction;
private readonly Point2dCollection ShellPoints = new Point2dCollection();
private Point3d Origin3d = new Point3d(0, 0, 0);
private Point2d Origin2d = new Point2d();
private Vector3d DisplacementVector;
public double InsideDiameter
{
set { _InsideDiameter = value; }
get { return _InsideDiameter; }
}
public double Thickness
{
set { _Thickness = value; }
get { return _Thickness; }
}
public double Length
{
set { _Length = value; }
get { return _Length; }
}
public Point3d Location
{
set { _Location = value; }
get { return _Location; }
}
public Vector3d Direction
{
set { _Direction = value; }
get { return _Direction; }
}
private void CalculateProperties()
{
Origin2d = Origin3d.Convert2d(new Plane(Origin3d, Vector3d.ZAxis));
DisplacementVector = Origin3d.GetVectorTo(_Location);
}
private void CalculateVertices()
{
Point2d tempPoint2d;
CalculateProperties();
ShellPoints.Clear();
tempPoint2d = Origin2d.Add(new Vector2d(_InsideDiameter / 2, _Length / 2));
ShellPoints.Add(tempPoint2d);
tempPoint2d = tempPoint2d.Add(new Vector2d(_Thickness, 0));
ShellPoints.Add(tempPoint2d);
tempPoint2d = tempPoint2d.Add(new Vector2d(0, -_Length));
ShellPoints.Add(tempPoint2d);
tempPoint2d = tempPoint2d.Add(new Vector2d(-Thickness, 0));
ShellPoints.Add(tempPoint2d);
}
public void Draw()
{
Document acaddoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acaddb = acaddoc.Database;
//Editor edt = acaddoc.Editor;
CalculateVertices();
int VertexIndex = 0;
Polyline ShellPolyLine = new Polyline();
foreach (Point2d ShellPoint in ShellPoints)
{
ShellPolyLine.AddVertexAt(VertexIndex, ShellPoint, 0, 0, 0);
VertexIndex += 1;
}
ShellPolyLine.Closed = true;
DBObjectCollection pl = new DBObjectCollection();
pl.Add(ShellPolyLine);
DBObjectCollection regn = Region.CreateFromCurves(pl);
Region region = (Region)regn[0];
Solid3d Shell = new Solid3d();
Shell.Revolve(region, Origin3d, new Vector3d(0, 1, 0), 2 * PI);
if (_Direction.X == 0 && _Direction.Y == 0)
{
Shell.TransformBy(Matrix3d.Rotation(PI / 2, (_Direction.Z > 0 ? 1 : -1) * Vector3d.XAxis, Origin3d));
}
else
{
Vector3d XYVector = _Direction.OrthoProjectTo(Vector3d.ZAxis);
double rotation = Vector3d.YAxis.GetAngleTo(XYVector, Vector3d.ZAxis);
Shell.TransformBy(Matrix3d.Rotation(rotation, Vector3d.ZAxis, Origin3d));
Vector3d RotAxis = XYVector.GetPerpendicularVector().Negate();
rotation = XYVector.GetAngleTo(_Direction, RotAxis);
Shell.TransformBy(Matrix3d.Rotation(rotation, RotAxis, Origin3d));
}
Shell.TransformBy(Matrix3d.Displacement(DisplacementVector));
using (Transaction trans = acaddb.TransactionManager.StartTransaction())
{
BlockTable bt;
bt = trans.GetObject(acaddb.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr;
btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
btr.AppendEntity(Shell);
trans.AddNewlyCreatedDBObject(Shell, true);
trans.Commit();
}
}
}//Class - Shell3d