I would like to try solving the polygon diagonals problem without resorting to the explode method. The polygon is rotated in space and has all different z coordinates. After much searching, I still cannot find a way to isolate the actual xyz coordinates of the 4 vertices from VBA methods. The coordinates property returns only 8 items for a 4 sided poly; the z is ignored. Not only that, but the x and y are projections, not the actual xy values of the vertex.
What appears to be a likely solution is to change the coordinate system to be parallel to the face of the polygon. This forces the z values to be zero, and the xy coordinates found using the coordinates method. I then have the points I need to draw the diagonals. Mind you, I still don't have the true WCS coords of the vertices. I have to transform back to world and use the startpoints of the lines for that.
I can use the tools --> new UCS --> object menu in Acad to create a UCS parallel to the poly face. Trouble is I have 30,000 polylines. Doing each poly interactively is unreasonable. So I have to go into VBA. I can find no easy way to emulate the tools --> new UCS --> object technique.
This leads to the VBA translate coordinates method. VBA help gives the following example of setting the UCS:
Code:
' Create a UCS named "New_UCS" in current drawing
Dim ucsObj As AcadUCS
Dim origin(0 To 2) As Double
Dim xAxisPnt(0 To 2) As Double
Dim yAxisPnt(0 To 2) As Double
' Define the UCS
origin(0) = 2#: origin(1) = 2#: origin(2) = 2#
xAxisPnt(0) = 5#: xAxisPnt(1) = 2#: xAxisPnt(2) = 2#
yAxisPnt(0) = 2#: yAxisPnt(1) = 6#: yAxisPnt(2) = 2#
' Add the UCS to the UserCoordinatesSystems collection
Set ucsObj = ThisDrawing.UserCoordinateSystems.Add(origin, xAxisPnt, yAxisPnt, "New_UCS")
ThisDrawing.ActiveUCS = ucsObj
I don't seem to be able to get past this example. The x and y axis points appear to be the same as the origin point except for xpt(0) and ypt(1). How do I relate this to my polyline? What are the xaxispt =5# and the yaxispt = 6#? These numbers look arbitrary to me.
These are my polyline coords in WCS. Notice the z values:
Code:
LWPOLYLINE Layer: "Diagrid"
Space: Model space
Handle = 2d
Closed
Constant width 0.000000
Extrusion direction relative to UCS:
X=-0.345290 Y=-0.361628 Z= 0.866025
area 16936.199773
perimeter 520.695694
at point X=-6.925254 Y=323.783263 Z= 0.000000
at point X=117.747712 Y=314.871262 Z=45.986571
at point X=126.257091 Y=196.617761 Z= 0.000000
at point X= 1.584124 Y=205.529762 Z=-45.986571
If I could grab these numbers in VBA, I'd be done.
If I do tools --> new UCS --> object I get:
Code:
LWPOLYLINE Layer: "Diagrid"
Space: Model space
Handle = 2d
Closed
Constant width 0.000000
area 16936.199773
perimeter 520.695694
at point X= 0.000000 Y=127.165502 Z= 0.000000
at point X=133.182345 Y=127.165502 Z= 0.000000
at point X=133.182345 Y= 0.000000 Z= 0.000000
at point X= 0.000000 Y= 0.000000 Z= 0.000000
Both of these data sets give me the info I need to draw my lines, but they come from the list window, not VBA. Why can list do it, and VBA not?
I tried the ADN help line. The answer I got is that I should use the coordinates and translate coordinates methods. I knew that already. No help was offered on understanding how these methods work as applied to an actual object like a polyline.
I tried plugging different combinations of my numbers into their code. Nothing I did could create a UCS that was parallel to the poly face.
What am I missing? Can someone show me how to create a parallel UCS to the poly.dwg I have attached?