I am currently working on relaying geometric coordinates from a wireframe in Catia to VB.NET to a text file. In order to do this my first step is to get the XYZ coordinates of each point of my wireframe geometry in Catia and store it in a variable in VB.NET. Utilizing some code I found in a forum discussion I was able to select a point in Catia and get its coordinates into a VB.NET variable. However, reading the XYZ’s of multiple points in a polyline has proven to be a much more difficult challenge for me. After scouring through the deep rooted trees of classes, objects, properties, and methods in the Catia Automation Help I have come up with a very roundabout yet workable VB.NET solution.
Using the GetElements sub method of HybridShapePolyline I am able to return an arrray of the elements (points) of the polyline. The difficult part was figure out how to store each element into a point instance so that I could use the Point sub method GetCoordinates to return the XYZ’s of each point.
The GetCoordinates constructor asks for “oCoordinates as Array”. The first road bump was figuring out that that the “o” before “Coordinates” stands for output (as opposed to when there is an “i” for input), thus the constructor should be passed an array to store the values that are returned by GetCoordinates. It seems pretty simple now, but this was the first Method I had used that asked for an output object in the constructor and it took me an hour or so to come to the above realization.
The GetElements sub method of HybridShapePolyline resulted in another deep exploration through the Catia Automation Help. At first I attempted to plug the elements returned by GetElements directly into GetCoordinates to no avail. After some debugging I found that GetElements does not return a point, but rather it returns a reference to a point, thus I could not run a Point sub method such as GetCoordinates.
So here’s where my code got a little clunky. In order to turn the references to points into actual points, I searched for a Point object that could somehow reference the reference to the point to create a point with identical coordinates. Using the HybridShapeFactory sub method AddNewPointCoordWithReference I was able to reference the reference to the point and offset it by 0,0,0. VB.NET is then able to run GetCoordinates on my new Point that references the reference to the point on the polyline for which I am attempting to get coordinates. A bit roundabout, but it was a satisfying feat at the time. I am sure Jonatan and Ben will be able to cut the fat on this code and leave it at 2 or 3 lines.
‘cycle through each element (point) of the HybridShapePolyline
For i As Integer = 1 To myWireFrame.NumberOfElements
‘create ptXYZ array to hold xyz coordinates of point
Dim ptXYZ(2) As Object
‘set items of ptXYZ to equal XYZ coordinates of myPoint
Dim myWireFrameElement As Reference ’= Nothing
‘get reference to points of selected wireframe
myWireFrame.GetElement(i, myWireFrameElement, Nothing)
‘create point object offset 0,0,0 from reference to point on polyline
wireFramePoint = myHSFactory.AddNewPointCoordWithReference(0,0,0,myWireFrameElement)
‘create physical point in Catia for debugging purposes
‘assign point coordinates to ptXYZ array
‘convert units from mm to feet
Dim xft As Double = ptXYZ(0)*0.0032808399
Dim yft As Double = ptXYZ(1)*0.0032808399
Dim zft As Double = ptXYZ(2)*0.0032808399
Console.Writeline(“X= “ & xft & ” Y= “ & yft & ” Z= “ & zft)