I want to get the user's exact drawing coordinate system (accurate drawing coordinate system through the shortcut keys such as T, F, V, S, etc. is not the ACS auxiliary coordinate system), change the exact drawing coordinate system, and then change the three-dimensional perspective of my painting CellElement.
In addition, the CellElement I draw needs to rotate around the Z-axis of the exact drawing coordinate system. Now because I can't get a temporary coordinate system, the CellElement I draw is always on the XY plane of the world coordinate system and it always wraps around the world. The coordinate system rotates in the Z axis. I used the elemCell.RotateAboutZ(m_atPoints[0], m_atPoints[1].Y - m_atPoints[0].Y < 0 ? 2 * Math.PI - aa : aa) methods.
I found some methods on the Internet to get the exact drawing coordinate system by calling the MDL function. I have made a DllImport declaration for each function and then called it through PInvokde.
However, it did not have any effect. Please help, thank you!
Here is my code
public void Dynamics(ref Point3d Point, BCOM.View View, MsdDrawingMode DrawMode)
{
if (1 != m_nPoints)
return;
mdlCurrTrans_begin();
mdlCurrTrans_identity();
mdlCurrTrans_getTransforms(ref pMdlToUor, ref pUorToMdl);
mdlCurrTrans_rotateByRMatrix(ref pUorToMdl, 1);
mdlTMatrix_transformPoint(ref m_atPoints[0],ref pUorToMdl);
Point3d[] txtPts = new Point3d[2];
Element[] elems = new Element[8];
Element[] elems3d = new Element[2];
double aa = 0;
m_atPoints[1] = Point;
rMatrix = app.Matrix3dIdentity();
ConeR = myForm.textBox1.Text.ToString() == "" ? 50 : Convert.ToInt16(myForm.textBox1.Text.ToString());
CircleR = 110;
elems[0] = app.CreateArcElement2(null, m_atPoints[0], CircleR, CircleR, rMatrix, 0, 2 * Math.PI);
FenMu = Math.Sqrt((m_atPoints[1].X - m_atPoints[0].X) * (m_atPoints[1].X - m_atPoints[0].X) + (m_atPoints[1].Y - m_atPoints[0].Y) * (m_atPoints[1].Y - m_atPoints[0].Y) + (m_atPoints[1].Z - m_atPoints[0].Z) * (m_atPoints[1].Z - m_atPoints[0].Z));
//长横线
Point3d startPnt1 = app.Point3dFromXYZ(m_atPoints[0].X + CircleR, m_atPoints[0].Y, m_atPoints[0].Z);
Point3d endPnt1 = app.Point3dFromXYZ(m_atPoints[0].X + CircleR + 140, m_atPoints[0].Y, m_atPoints[0].Z);
elems[1] = app.CreateLineElement2(null, ref startPnt1, ref endPnt1);
//LineElement oLine1 = app.CreateLineElement2(null, ref startPnt1, ref endPnt1);
//app.ActiveModelReference.AddElement(oLine1);
//竖线
Point3d startPnt2 = app.Point3dFromXYZ(startPnt1.X + 140 / 2, m_atPoints[0].Y, m_atPoints[0].Z);
Point3d endPnt2 = app.Point3dFromXYZ(startPnt1.X + 140 / 2, m_atPoints[0].Y + 82.5, m_atPoints[0].Z);
elems[2] = app.CreateLineElement2(null, ref startPnt2, ref endPnt2);
//短横线
Point3d startPnt3 = app.Point3dFromXYZ(startPnt1.X + (140 - 80) / 2, startPnt1.Y + 82.5, startPnt1.Z);
Point3d endPnt3 = app.Point3dFromXYZ(startPnt1.X + (140 - 80) / 2 + 80, startPnt1.Y + 82.5, startPnt1.Z);
elems[3] = app.CreateLineElement2(null, ref startPnt3, ref endPnt3);
Point3d endPnt4 = endPnt1;
endPnt4.Y -= 55;
elems[4] = app.CreateArcElement2(null, endPnt4, CircleR / 2, CircleR / 2, rMatrix, 0, 0.5 * Math.PI);
//字母
Point3d basePt2 = app.Point3dFromXYZ(m_atPoints[0].X, m_atPoints[0].Y, m_atPoints[0].Z);
TextElement oText = app.CreateTextElement1(null, "C", ref basePt2, ref rMatrix);
oText.TextStyle.Width = 110;
oText.TextStyle.Height = 110;
oText.TextStyle.Justification = MsdTextJustification.CenterCenter;
//oText.TextStyle.Font = app.ActiveDesignFile.Fonts.Find(MsdFontType.WindowsTrueType, "宋体");
oText.TextStyle.Font = app.ActiveSettings.TextStyle.Font;
oText.LineWeight = 4;
elems[5] = oText;
//小圆柱
Point3d topPt = m_atPoints[0];
topPt.Y += 95;
elems[6] = app.CreateConeElement1(null, ConeR, ref m_atPoints[0], ConeR, ref topPt, ref rMatrix);
//大圆柱
Point3d topPt1 = m_atPoints[0];
topPt1.Y += 105;
elems[7] = app.CreateConeElement1(null, ConeR + 20, ref topPt, ConeR + 20, ref topPt1, ref rMatrix);
CellElement elemCell = app.CreateCellElement1("NoteCoordCell", ref elems, ref m_atPoints[0]);
aa = Math.Acos((m_atPoints[1].X - m_atPoints[0].X) / FenMu);
if (!myForm.cbAbslevel.Checked)
{
mdlCurrTrans_end();
elemCell.RotateAboutZ(m_atPoints[0], m_atPoints[1].Y - m_atPoints[0].Y < 0 ? 2 * Math.PI - aa : aa);
}
else {
mdlCurrTrans_end();
elemCell.RotateAboutZ(m_atPoints[0], 0);
}
elemCell.Redraw(DrawMode);
if (MsdDrawingMode.Normal == DrawMode)
{
app.ActiveModelReference.AddElement(elemCell);
}
}
![]()