# Bug ZwCAD2017 COM intefrace for TranslateCoordinates

Janusz8660

Assistant Engineer

posts: 12

Registered: 2016-1-11

Message 1 of 6

Bug ZwCAD2017 COM intefrace for TranslateCoordinates
12-03-2017 11:34 . pm   |   View his/her posts only
Hello again,
I found error in COM/VBA method TranslateCoordinates when try converting coordinates OCS -> WCS:

pOcs=Poly2d.Coordinate(0)
pOcs(2)=Poly2d.Elevation

point3d=ActiveDocument.Utility.TranslateCoordinates(pOcs,zcOcs,zcUcs,1,Poly2d.Normal);
returned var is undefined:

Probably error exist only in context OCS->WCS.
I checked conversion coordinates UCS->WCS and all is ok:

point3d=ActiveDocument.Utility.TranslateCoordinates(pOcs,zcOcs,zcUcs,1,nil);
returned var is correct

- check this error/bug and anticipate solving time.
- suggest alternate method to get WCS coordinates for LwPolyline points when normal isn't 0/0/1 and UCSORG is other than (0,0,0)

J.

posts: 425

Registered: 2015-6-9

Message 2 of 6

13-03-2017 12:02 . pm   |   View his/her posts only

Hello, we check the TranslateCoordinates by the following example from, and it works OK. Could you provide a test example for us to check? Thanks.

Sub TestTranslateCoordinates()
' Create a polyline in model space.
Dim points(0 To 14) As Double

' Define the 2D polyline points
points(0) = 0: points(1) = 1: points(2) = 1
points(3) = 0: points(4) = 2: points(5) = 1
points(6) = 0: points(7) = 2: points(8) = 2
points(9) = 0: points(10) = 2: points(11) = 3
points(12) = 0: points(13) = 4: points(14) = 4

' Create a light weight Polyline object in model space

' Find the X and Y coordinates of the
' first vertex of the polyline
Dim firstVertex As Variant
firstVertex = plineObj.Coordinate(0)

' Find the Z coordinate for the polyline
' using the elevation property
firstVertex(2) = plineObj.Elevation

' Change the normal for the pline so that the
' difference between the coordinate systems
' is obvious.
Dim plineNormal(0 To 2) As Double
plineNormal(0) = 0#
plineNormal(1) = 1#
plineNormal(2) = 2#
plineObj.Normal = plineNormal

' Translate the OCS coordinate into WCS
Dim coordinateWCS As Variant
coordinateWCS = ThisDrawing.Utility.TranslateCoordinates _
(firstVertex, acOCS, acWorld, 1, plineNormal)

' Display the coordinates of the point
MsgBox "The first vertex has the following coordinates:" _
& vbCrLf & "OCS: " & firstVertex(0) & ", " & _
firstVertex(1) & ", " & firstVertex(2) & vbCrLf & _
"WCS: " & coordinateWCS(0) & ", " & _
coordinateWCS(1) & ", " & coordinateWCS(2)
End Sub

Janusz8660

Assistant Engineer

posts: 12

Registered: 2016-1-11

Message 3 of 6

13-03-2017 05:38 . pm   |   View his/her posts only

Please check results for cases :

1. OCSvertex2d=[3,1]
Elevation=1.5
planeNormal=[0,0,-1]

ZwCAD return WCS: [3.0 ,1.0, 1.5] ' ERROR!
Acad return WCS: [-3.0,1.0,-1.5] ' OK!

2. OCSvertex2d=[3,1]
Elevation=1.5
planeNormal=[0,-1,0]

ZwCAD return WCS: [3.0 ,1.0, 1.5] ' ERROR!
Acad return WCS: [3.0,-1.5, 1.0] ' OK!

J.

Janusz8660

Assistant Engineer

posts: 12

Registered: 2016-1-11

Message 4 of 6

27-03-2017 05:50 . am   |   View his/her posts only
Post Last Edit by Janusz8660 at 2017-3-27 06:02

Jeffrey, any progress in checking this data?

I prepare script for checking case 1 :

Sub TestTranslateCoordinates()
' Create a polyline in model space.
Dim points(0 To 14) As Double

' Define the 2D polyline points
points(0) = 3: points(1) = 1: points(2) = 1
points(3) = 0: points(4) = 2: points(5) = 1
points(6) = 0: points(7) = 2: points(8) = 2
points(9) = 0: points(10) = 2: points(11) = 3
points(12) = 0: points(13) = 4: points(14) = 4

' Create a light weight Polyline object in model space

plineObj.Elevation = 1.5

' Find the X and Y coordinates of the
' first vertex of the polyline
Dim firstVertex As Variant
firstVertex = plineObj.Coordinate(0)

' Find the Z coordinate for the polyline
' using the elevation property
firstVertex(2) = plineObj.Elevation

' Change the normal for the pline so that the
' difference between the coordinate systems
' is obvious.
Dim plineNormal(0 To 2) As Double
plineNormal(0) = 0#
plineNormal(1) = 0#
plineNormal(2) = -1#
plineObj.Normal = plineNormal

' Translate the OCS coordinate into WCS
Dim coordinateWCS As Variant
coordinateWCS = ThisDrawing.Utility.TranslateCoordinates _
(firstVertex, acOCS, acWorld, 1, plineNormal)

' Display the coordinates of the point
MsgBox "The first vertex has the following coordinates:" & vbCrLf & _
"OCS: " & firstVertex(0) & ", " & firstVertex(1) & " + Elevation:" & firstVertex(2) & vbCrLf & _
"PlaneNormal: " & plineNormal(0) & ", " & plineNormal(1) & ", " & plineNormal(2) & vbCrLf & _
"OCS->WCS: " & coordinateWCS(0) & ", " & coordinateWCS(1) & ", " & coordinateWCS(2)
End Sub

Janusz8660

Assistant Engineer

posts: 12

Registered: 2016-1-11

Message 5 of 6

27-03-2017 06:00 . am   |   View his/her posts only
Post Last Edit by Janusz8660 at 2017-3-27 06:04

ZWCAD return 3 ,1 , 1.5

Should -3.0,1.0,-1.5

posts: 425

Registered: 2015-6-9

Message 6 of 6

29-03-2017 02:09 . pm   |   View his/her posts only