Catia Macro : Measurable.GetPoint() not able to get XYZ Co-ordinates
Catia Macro : Measurable.GetPoint() not able to get XYZ Co-ordinates
(OP)
Hello Friends
Measurable.GetPoint() is not giving me the co-ordinates in most of the cases. I have tested the code on many computers with different catia versions. In most of the cases it fails to report the co-ordinates(On One PC it does works).
But to my surprise if I create out-Process macro out of same code It works without any problem. I am not able to find root cause of the solution
Below is my VBA code
Below is the output of sample run
Can Anyone help me out !
Measurable.GetPoint() is not giving me the co-ordinates in most of the cases. I have tested the code on many computers with different catia versions. In most of the cases it fails to report the co-ordinates(On One PC it does works).
But to my surprise if I create out-Process macro out of same code It works without any problem. I am not able to find root cause of the solution
Below is my VBA code
CODE --> VBA
Option Explicit
Sub CatMain()
Dim MyDoc 'As Document
Set MyDoc = CATIA.ActiveDocument
If Not (TypeName(MyDoc) = "PartDocument") Then
MsgBox "This Command Works only on Part Documants", vbCritical, "Error"
End
End If
Dim MySelection 'As Selection
Set MySelection = MyDoc.Selection
Dim Status As String
Dim vFilter(0)
vFilter(0) = "HybridBody"
MySelection.Clear
Status = MySelection.SelectElement2(vFilter, "Select Geometric Set Containing 3D Points", True)
If Status = "Cancel" Then
End
End If
Dim MyHybridBody 'As HybridBody
Set MyHybridBody = MySelection.Item(1).Value
If MyHybridBody.HybridShapes.Count = 0 Then
MsgBox "Geometric Set is Empty", vbCritical, "Error"
End
End If
Dim TheSPAWorkbench 'As SPAWorkbench
Set TheSPAWorkbench = MyDoc.GetWorkbench("SPAWorkbench")
Dim MyPoint 'As Point
Dim Reference1 'As Reference
Dim TheMeasurable 'As Measurable
Dim coords(2)
Dim i As Integer
On Error Resume Next
For i = 1 To MyHybridBody.HybridShapes.Count
Set MyPoint = MyHybridBody.HybridShapes.Item(i)
Set Reference1 = MyDoc.Part.CreateReferenceFromObject(MyPoint)
Set TheMeasurable = TheSPAWorkbench.GetMeasurable(Reference1)
TheMeasurable.GetPoint (coords)
If Err.Number = 0 Then
Debug.Print (coords(0)) + ", " + CStr(coords(1)) + ", " + CStr(coords(2))
Else
Debug.Print "Error in Getting XYZ from " + MyHybridBody.HybridShapes.Item(i).Name
Err.Clear
End If
Next
End Sub Below is the output of sample run
CODE --> Output
, , , , , , Error in Getting XYZ from Line.1 Error in Getting XYZ from Plane.1 , , , ,
Can Anyone help me out !





RE: Catia Macro : Measurable.GetPoint() not able to get XYZ Co-ordinates
Of course you will get errors, you have lines and planes in that Geo Set, you can't get point coordinates from them....
A plane doesn't have points and for the line end points you have to define them in another way...check documentation please.
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Catia Macro : Measurable.GetPoint() not able to get XYZ Co-ordinates
Geometric set also contains 3d points. The macro returns empty values as shown in output with spaces and commas for same.
I am not concerned about anything other then points. That was just sample output.
RE: Catia Macro : Measurable.GetPoint() not able to get XYZ Co-ordinates
CODE --> catvba
Sub CatMain() On Error Resume Next Dim docPart As Document Dim myPart As Part Dim hybBodies As HybridBodies Dim hybBody As HybridBody Dim hybShapes As HybridShapes Dim hybShape As HybridShape Dim arrXYZ(2) Dim s As Long Const Separator As String = ";" Set docPart = CATIA.ActiveDocument 'If no doc active If Err.number <> 0 Then MsgBox "No Active Document", vbCritical Exit Sub End If Dim was(0) Set userSel = CATIA.ActiveDocument.Selection was(0) = "HybridBody" userSel.Clear aText = userSel.SelectElement2(was, "Select Geometrical Set", True) Set hybBody = userSel.Item(1).Value Set hybShapes = hybBody.HybridShapes ' Search HybridShapes (Point 3D) For s = 1 To hybShapes.Count Set hybShape = hybShapes.Item(s) 'Extract coord hybShape.GetCoordinates arrXYZ MsgBox ((hybShapes.Parent.Name) & Separator & (hybShape.Name) & Separator & _ arrXYZ(0) & Separator & _ arrXYZ(1) & Separator & _ arrXYZ(2) & vbLf) Next s End SubRegards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: Catia Macro : Measurable.GetPoint() not able to get XYZ Co-ordinates
The above code is working for me. However I am yet to understand what is problem with measurable.getpoint
RE: Catia Macro : Measurable.GetPoint() not able to get XYZ Co-ordinates
the solution is
TheMeasurable.GetPoint coords
not
TheMeasurable.GetPoint (coords)
indocti discant et ament meminisse periti
RE: Catia Macro : Measurable.GetPoint() not able to get XYZ Co-ordinates
The silly mistake done by me
Thanks Itsmyjob for pointing it out.