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:
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:
, ,
, ,
, ,
Error in Getting XYZ from Line.1
Error in Getting XYZ from Plane.1
, ,
, ,
Can Anyone help me out !