- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I've got some code (c#) which allows the user to select a block, and then will explode the block into a collection of points (held in a 3dpointcollection called 'pts'). It will then transform the points such that they are positioned at each vertex of a polyline (denoted 'poly') and also orientated to face along the next segment of the polyline (hopefully you are still with me, the screenshot below should explain a bit better).
All the individual points are stored in a 3dpointcollection called 'MeshPts'. I now want to connect the points in a SubDMesh. I have had a look at Kean's demonstration and have come up with the following, however it doesn't display anything on screen.
int ep = Convert.ToInt32(poly.EndParam);
int[] ptr1 = new int[(pts.Count) * 2 + 1];
int[] ptr2 = new int[(pts.Count) * 2 + 1];
int[] ptr3 = new int[(pts.Count) * 2 + 1];
Int32Collection facearray = new Int32Collection();
for (int i = 0; i < ntri; i++)
{
facearray.Add(3);
facearray.Add(ptr1[i]);
facearray.Add(ptr2[i]);
facearray.Add(ptr3[i]);
}
SubDMesh sdm = new SubDMesh();
sdm.SetDatabaseDefaults();
sdm.SetSubDMesh(meshPts, facearray, 0);
btr.AppendEntity(sdm);
tr.AddNewlyCreatedDBObject(sdm, true);
I'm sort of running blind at the minute as I don't have any experience with meshes, only a very short time spent working with solid3d objects.
Please let me know if anything needs clarifying.
Full code so far is here:
Point3dCollection polyPts = new Point3dCollection();
Polyline3d poly = tr.GetObject(psr1.ObjectId, OpenMode.ForRead) as Polyline3d;
int ep = Convert.ToInt32(poly.EndParam);
for (int q = 0; q <= ep; q++) //Open foreach to iterate through the 3D polyline
{
if(q != poly.EndParam)
{ Point3d pt1 = poly.GetPointAtParameter(q);
int a = q + 1;
Vector3d vec1 = pt1.GetVectorTo(poly.GetPointAtParameter(a));
double angle = Vector3d.XAxis.GetAngleTo(vec1, Vector3d.ZAxis);
foreach (Point3d r in pts)
{
Point3d t = new Point3d();
Vector3d pt1Vec = pt1.GetAsVector();
Vector3d insVec = ins.GetAsVector();
Matrix3d rot = Matrix3d.Rotation(angle, zAz, pt1);
t = r.Add(pt1Vec).Subtract(insVec);
Point3d g = t.TransformBy(rot);
meshPts.Add(g);
} //Close foreach
}
} //close for
foreach (Point3d y in meshPts)
{
DBPoint b = new DBPoint(y);
btr.AppendEntity(b);
tr.AddNewlyCreatedDBObject(b, true);
}
int[] ptr1 = new int[(pts.Count) * 2 + 1];
int[] ptr2 = new int[(pts.Count) * 2 + 1];
int[] ptr3 = new int[(pts.Count) * 2 + 1];
Int32Collection facearray = new Int32Collection();
for (int i = 0; i < ep; i++)
{
facearray.Add(3);
facearray.Add(ptr1[i]);
facearray.Add(ptr2[i]);
facearray.Add(ptr3[i]);
}
SubDMesh sdm = new SubDMesh();
sdm.SetDatabaseDefaults();
sdm.SetSubDMesh(meshPts, facearray, 0);
btr.AppendEntity(sdm);
tr.AddNewlyCreatedDBObject(sdm, true);
Solved! Go to Solution.