Hi,
I would like to know if its possible to alter the sketch for a shaft opening via the API. I have the shaft element created and would like to draw X's as the opening symbol into it. Based on the aspect ratio of the opening this should be 1, 2, 3 ... X's.
Here is my code so far:
private static Result DrawX (List<XYZ> CoordList, Document uidoc, Opening o)
{
// Trying to draw the X`s into the shaft
if (CoordList.Count == 4)
{
double l1 = CoordList[1].Subtract(CoordList[0]).GetLength();
double l2 = CoordList[2].Subtract(CoordList[1]).GetLength();
double l3 = CoordList[3].Subtract(CoordList[2]).GetLength();
double l4 = CoordList[0].Subtract(CoordList[3]).GetLength();
double la = 0.0;
if (l1 > l3)
la = l1;
else
la = l3;
double lb = 0.0;
if (l2 > l4)
lb = l2;
else
lb = l4;
double ratio = la / lb;
int NumberXa = 1;
int NumberXb = 1;
if (ratio > 1.0)
{
NumberXa = (int)Math.Round(ratio, 0);
}
else
{
NumberXb = (int)Math.Round(1.0 / ratio, 0);
}
SymbolicCurveArray Xes = new SymbolicCurveArray();
double eta, xi, N1, N2, N3, N4;
XYZ P1, P2, P3, P4;
SketchPlane sk = SketchPlane.Create(uidoc, new Plane(new XYZ(1, 1, 0), new XYZ(0, 0, 0)));
for (int i = 0; i < NumberXa; i++)
{
for (int j = 0; j < NumberXb; j++)
{
xi = 2.0 * ((double)i / (double)NumberXa) - 1.0;
eta = 2.0 * ((double)j / (double)NumberXb) - 1.0;
N1 = 0.25 * (1 - xi) * (1 - eta);
N2 = 0.25 * (1 + xi) * (1 - eta);
N3 = 0.25 * (1 + xi) * (1 + eta);
N4 = 0.25 * (1 - xi) * (1 + eta);
Debug.Assert(N1 + N2 + N3 + N4 > 0.9999);
Debug.Assert(N1 + N2 + N3 + N4 < 1.0001);
P1 = N1 * CoordList[0] + N2 * CoordList[1] + N3 * CoordList[2] + N4 * CoordList[3];
xi = 2.0 * ((double)(i+1) / (double)NumberXa) - 1.0;
eta = 2.0 * ((double)j / (double)NumberXb) - 1.0;
N1 = 0.25 * (1 - xi) * (1 - eta);
N2 = 0.25 * (1 + xi) * (1 - eta);
N3 = 0.25 * (1 + xi) * (1 + eta);
N4 = 0.25 * (1 - xi) * (1 + eta);
P2 = N1 * CoordList[0] + N2 * CoordList[1] + N3 * CoordList[2] + N4 * CoordList[3];
xi = 2.0 * ((double)(i+1) / (double)NumberXa) - 1.0;
eta = 2.0 * ((double)(j+1) / (double)NumberXb) - 1.0;
N1 = 0.25 * (1 - xi) * (1 - eta);
N2 = 0.25 * (1 + xi) * (1 - eta);
N3 = 0.25 * (1 + xi) * (1 + eta);
N4 = 0.25 * (1 - xi) * (1 + eta);
P3 = N1 * CoordList[0] + N2 * CoordList[1] + N3 * CoordList[2] + N4 * CoordList[3];
xi = 2.0 * ((double)i / (double)NumberXa) - 1.0;
eta = 2.0 * ((double)(j+1) / (double)NumberXb) - 1.0;
N1 = 0.25 * (1 - xi) * (1 - eta);
N2 = 0.25 * (1 + xi) * (1 - eta);
N3 = 0.25 * (1 + xi) * (1 + eta);
N4 = 0.25 * (1 - xi) * (1 + eta);
P4 = N1 * CoordList[0] + N2 * CoordList[1] + N3 * CoordList[2] + N4 * CoordList[3];
Xes.Append(uidoc.FamilyCreate.NewSymbolicCurve(Line.CreateBound(P1, P3), sk));
Xes.Append(uidoc.FamilyCreate.NewSymbolicCurve(Line.CreateBound(P2, P4), sk));
}
}
}
return Result.Succeeded;
}
How can I include the additional SymbolicCurves into the origional sketch of the opening?
Any help would be great.
Thanks
Christian
Can't find what you're looking for? Ask the community or share your knowledge.