Modified the code from the first post.
In the Library :
// // CodeHimBelongaKwb © Mar 2008
[DllImport("acad.exe", CallingConvention=CallingConvention.Cdecl)]
private static extern int acedTrans(
double[] point,
IntPtr fromResbuf,
IntPtr toResbuf,
int displacement,
double[] result
);
/// <summary>
///
/// </summary>
public enum CoOrds
{
WCS = 0,
UCS,
DisplayDCS,
PaperSpaceDCS
}
/// <summary>
///
/// </summary>
/// <param name="PtToTranslate"></param>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static AcGe.Point3d TranslateCoordinates(this AcGe.Point3d PtToTranslate,
CoOrds from,
CoOrds to)
{
AcDb
.ResultBuffer fromResbuf
= new AcDb
.ResultBuffer(new AcDb
.TypedValue(0x138b,
from)); AcDb
.ResultBuffer toResbuf
= new AcDb
.ResultBuffer(new AcDb
.TypedValue(0x138b, to
)); double[] result
= new double[] { 0,
0,
0 };
acedTrans(PtToTranslate.ToArray(),
fromResbuf.UnmanagedObject,
toResbuf.UnmanagedObject,
0,
result
);
return new AcGe
.Point3d(result
); }
The calling routine :
// // CodeHimBelongaKwb © Mar 2008
[AcRx.CommandMethod("TranslatePoint")]
static public void TestPointTranslation()
{
// AcDb.Database db = AcDb.HostApplicationServices.WorkingDatabase;
AcEd.Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
AcGe
.Point3d basePoint
= new AcGe
.Point3d();
ed.WriteMessage("\n Translate Point 0,0,0 from UCS to WCS : "
+ basePoint.TranslateCoordinates(
dbExtensions.CoOrds.UCS,
dbExtensions.CoOrds.WCS ).ToString());
ed.WriteMessage("\n Translate Point 0,0,0 from UCS to DisplayDCS : "
+ basePoint.TranslateCoordinates(
dbExtensions.CoOrds.UCS,
dbExtensions.CoOrds.DisplayDCS ).ToString());
ed.WriteMessage("\n Translate Point 0,0,0 from WCS to UCS : "
+ basePoint.TranslateCoordinates(
dbExtensions.CoOrds.WCS,
dbExtensions.CoOrds.UCS ).ToString());
ed.WriteMessage("\n Translate Point 0,0,0 from WCS to DisplayDCS : "
+ basePoint.TranslateCoordinates(
dbExtensions.CoOrds.WCS,
dbExtensions.CoOrds.DisplayDCS ).ToString());
ed.WriteMessage("\n Translate Point 0,0,0 from DisplayDCS to WCS : "
+ basePoint.TranslateCoordinates(
dbExtensions.CoOrds.DisplayDCS,
dbExtensions.CoOrds.WCS ).ToString());
ed.WriteMessage("\n Translate Point 0,0,0 from DisplayDCS to UCS : "
+ basePoint.TranslateCoordinates(
dbExtensions.CoOrds.DisplayDCS,
dbExtensions.CoOrds.UCS).ToString());
}
Tested in a drawing set up like this ..
Current ucs name: *WORLD*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>: o
Specify new origin point <0,0,0>: 100,100,100
Command: UCS
Current ucs name: *NO NAME*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>: z
Specify rotation angle about Z axis <90>: 20
Command: UCS
Current ucs name: *NO NAME*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>: y
Specify rotation angle about Y axis <90>: -20
Command: UCS
Current ucs name: *NO NAME*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>: x
Specify rotation angle about X axis <90>: 20
Command: UCS
Current ucs name: *NO NAME*
Specify origin of UCS or [Face/NAmed/OBject/Previous/View/World/X/Y/Z/ZAxis] <World>: s
Enter name to save current UCS or [?]: tempTest
Command: _-view
Enter an option [?/Delete/Orthographic/Restore/Save/sEttings/Window]: _seiso
Intersecting Lines Lines on World at 0,0,0
Circle on tempTest at 0,0,0
(vlax-dump-object
(vla-item (vla-get-usercoordinatesystems
(vla-get-activedocument (vlax-get-acad-object))
)
"tempTest"
)
)
; IAcadUCS:
; Property values:
; Application (RO) = #<VLA-OBJECT IAcadApplication 00d74d3c>
; Document (RO) = #<VLA-OBJECT IAcadDocument 01465d38>
; Handle (RO) = "81"
; HasExtensionDictionary (RO) = 0
; Name = "tempTest"
; ObjectID (RO) = 2126872648
; ObjectName (RO) = "AcDbUCSTableRecord"
; Origin = (100.0 100.0 100.0)
; OwnerID (RO) = 2126855224
; XVector = (0.883022 0.321394 0.34202)
; YVector = (-0.431317 0.843013 0.321394)
(trans '(0 0 0) acucs acWorld )
;=> (100.0 100.0 100.0)
(trans '(0 0 0) acucs acDisplayDCS )
;=> (141.421 81.6497 57.735)
(trans '(0 0 0) acWorld acUcs)
;=> (-154.644 -73.309 -26.6672)
(trans '(0 0 0) acWorld acDisplayDCS)
;=> (0.0 0.0 0.0)
(trans '(0 0 0) acDisplayDCS acWorld)
;=> (0.0 0.0 0.0)
(trans '(0 0 0) acDisplayDCS acUcs)
;=> (-154.644 -73.309 -26.6672)
Command: NetLoad
Command: TranslatePoint
Translate Point 0,0,0 from UCS to WCS : (100, 100, 100)
Translate Point 0,0,0 from UCS to DisplayDCS : (141.42135623731, 81.6496580927726, 57.7350269189626)
Translate Point 0,0,0 from WCS to UCS : (-154.643616972843, -73.3090309814871, -26.6671653182726)
Translate Point 0,0,0 from WCS to DisplayDCS : (0,0,0)
Translate Point 0,0,0 from DisplayDCS to WCS : (0,0,0)
Translate Point 0,0,0 from DisplayDCS to UCS : (-154.643616972843, -73.3090309814871, -26.6671653182726)
So, it seems to work ok.
the drawing piccy attached
edit:AC2002 Drawing attached