. net AutoCAD secondary development, PDF printing, UCS conversion to DCS coordinate system


When developing pdf printer with c# AutoCAD, the printing position deviation will be encountered. By querying the data, because of different coordinate systems, UCS coordinates are used for drawing and DCS coordinates are used for printing.

According to the check data, there are three solutions:

First: Reference http://bbs.mjtd.com/thread-169479-1-1.html , for the case where the view direction is parallel to the Z axis, point3d pttarget = application GetSystemVariable(“TARGET”); Then subtract the X and Y values of pttarget from the X and Y values of the print range.

Second: Reference https://www.jixie5.com/jiaocheng/476.html , restore target to the default value: 0,0,0 in the drawing.

Third: Reference https://www.cnblogs.com/suncoolcat/p/3395455.html , use the acedtrans() function in ObjectARX for coordinate conversion. In this reference article, the CAD version used is before cad2014, corresponding to that after cad2014, and the calling method is changed to:

[DllImport("accore.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedTrans")]
private static extern int acedTrans(double[] point, IntPtr fromResbuf, IntPtr toResbuf, int displacement, double[] result);

Other methods remain unchanged.

The fourth one is to use autodesk.com directly without using COM library AutoCAD. Internal. The ucstodisplay function converts UCS into DCS coordinates to print drawings