* cool thread to follow *
"3 (non colinear) source points and 3 (non colinear) destination points to be able to define the source plane and destination plane."
wizman - I'm intrigued by what you suggested as a manual approach. Is there a way to do this programatically? When I explode the pipe, reduces the pipe down to its primitives, but I want to retain the pipe.. not sure how to proceed manually, or implement via the API...
// FYI - the following are as held as member variables
// List<KeyValuePair<string, string>> pipeProperties;
// private Point3d position;
// private Point3d centerOfPipe;
// private double extrudeHeight;
// private double outsideDiameter;
// private double wallThickness;
// private double pipeLength;
// private Vector3d pipeVector;
private void CreateEnt(Entity ent)
{
// Scale the text height...
Extents3d geometricExtents = ent.GeometricExtents;
Point3d point3d = new Point3d();
double mHeight = this.m_height;
Vector3d vectorTo = point3d.GetVectorTo(geometricExtents.MaxPoint);
double y = mHeight / vectorTo.Y;
ent.TransformBy(Matrix3d.Scaling(y, point3d));
using (Transaction tr = this.m_db.TransactionManager.StartTransaction())
{
try
{
BlockTableRecord btr = tr.GetObject(this.m_db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
ent.SetDatabaseDefaults();
// Extrude this region just beyond the thickness of the pipe...
var pSolid = new Solid3d { RecordHistory = true };
pSolid.Extrude(ent as Region, extrudeHeight, 0.0);
// Move this region to the center point of the pipe, and move it down so it is vertically center justified...
var centerJustPoint = new Point3d(centerOfPipe.X, centerOfPipe.Y, centerOfPipe.Z - (extrudeHeight / 4.0));
pSolid.TransformBy(Matrix3d.Displacement(centerJustPoint - Point3d.Origin));
// Now the text region is by default oriented so that the text is laying down flat. Hard code transform to be "vertical" so the
// text region is up.
// ** how do I figure out the proper orientation of the text region to match the orientation of the pipe...??
Matrix3d matrix = Matrix3d.Rotation(Math.PI / 2, Vector3d.XAxis, centerJustPoint);
pSolid.TransformBy(matrix);
// Add this solid to the model...
btr.AppendEntity(pSolid);
tr.AddNewlyCreatedDBObject(pSolid, true);
// Create the cylinder that will be subtracted from the text regoin, and move it to the center point of the pipe..
var cyl = new Solid3d { RecordHistory = true };
var radius = (outsideDiameter / 2.0);
cyl.CreateFrustum(pipeLength, radius, radius, radius);
cyl.TransformBy(Matrix3d.Displacement(centerOfPipe - Point3d.Origin));
// Now this cylinder and text region is simply using the default orientation. Manually hard code to orientate it, just like above,
// so that it matches the text orientation..
// ** obviouslly this is wrong and won't handle, for example, vertical pipes.. how do I align this and the text to the orientation
// of the pipe.
Matrix3d matrix2 = Matrix3d.Rotation(Math.PI / 2, Vector3d.YAxis, centerOfPipe);
cyl.TransformBy(matrix2);
// Lots of test code here to try to orientate / align the cylinder and text to the pipe... see previous post that describes the approaches
// that I attempted, but couldn't figure out...
btr.AppendEntity(cyl);
tr.AddNewlyCreatedDBObject(cyl, true);
// Subtract the cylinder from the text region..
pSolid.BooleanOperation(BooleanOperationType.BoolSubtract, cyl);
}
catch
{
this.m_isValid = false;
}
finally
{
tr.Commit();
}
}
}
// ** how do I figure out the proper orientation of the text region to match the orientation of the pipe...??
using (Transaction tr = this.m_db.TransactionManager.StartTransaction())
{
try
{
BlockTableRecord btr = tr.GetObject(this.m_db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
ent.SetDatabaseDefaults();
// Extrude this region just beyond the thickness of the pipe...
var textSolid = new Solid3d { RecordHistory = true };
textSolid.Extrude(ent as Region, extrudeHeight, 0.0);
// Using ECS
Plane plane = new Plane(pipeEcs.CoordinateSystem3d.Origin, pipeEcs.CoordinateSystem3d.Xaxis, pipeEcs.CoordinateSystem3d.Yaxis);
Matrix3d matrix = Matrix3d.WorldToPlane(plane);
textSolid.TransformBy(matrix);
// Add this solid to the model...
btr.AppendEntity(textSolid);
tr.AddNewlyCreatedDBObject(textSolid, true);
// Create the cylinder that will be subtracted from the text regoin, and move it to the center point of the pipe..
var cyl = new Solid3d { RecordHistory = true };
var radius = (outsideDiameter / 2.0);
cyl.CreateFrustum(pipeLength, radius, radius, radius);
cyl.TransformBy(matrix);
btr.AppendEntity(cyl);
tr.AddNewlyCreatedDBObject(cyl, true);
}
catch
{
this.m_isValid = false;
}
finally
{
tr.Commit();
}
}
The green arrows shows the start and end of the vectors that are drawn, (start point of pipe, and to origin)
Here are the values from the debugger:Code - C#: [Select]
origin {(-1986.9832609598,4489.18265730619,0)} // Point3d origin = pipeEcs.CoordinateSystem3d.Origin; pipeEcs {((0.999997248002804,0.00234605771834044,0,-1986.9832609598),(-0.00234605771834044,0.999997248002804,0,4489.18265730619),(0,0,1,0),(0,0,0,1))} xvec {(9.99997248002804,-0.0234605771834044,0)} yvec {(0.0234605771834044,9.99997248002804,0)} zvec {(0,0,10)} this.position {(-1986.983261,4489.182657,0)} // this is the pipe's start point.
Hr.m.. very strange that the pipe's start point (this.position) isn't exactly the same as the pipeEcs.CoordinateSystem3d.Origin (or is that normal?)
You can either rotate your cylinder to the text first then transform it to the pipeI couldn't figure this out, .. I could move it to the start point of the pipe just fine, but couldn't figure out the transform / rotation to get it to align with the pipe. So then I tried:
or you can create a circle at the text start point, set the normal to Vector3d.XAxis (to extrude along text xAxis) and Extrude() with a height to be just longer than the text
Returns whether items in the history should be drawn when the sysvar SHOWHIST is 1.Try setting SHOWHIST to 2 after running the method.
Thanks once again MickD. I think I've finally got it. Now I just need to tweak the text placement. Your assistance was very much appreciated!