Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catia Macro : Measurable.GetPoint() not able to get XYZ Co-ordinates

Status
Not open for further replies.

jagandeep

Automotive
May 27, 2013
82
IN
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

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 !
 
Replies continue below

Recommended for you

Ferdo
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.
 
I saw, because I was interested in the past to get such kind of info here is a part of my code (you need to handle the problem of not showing other elements in Geo Set). Code is working also inside a CATProduct

Code:
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 Sub

Regards
Fernando

 
Thanks Dear
The above code is working for me. However I am yet to understand what is problem with measurable.getpoint
 
if you check FAQ you find my script to get xyz to text file.

the solution is

TheMeasurable.GetPoint coords

not

TheMeasurable.GetPoint (coords)



Eric N.
indocti discant et ament meminisse periti
 
My Bad
The silly mistake done by me

Thanks Itsmyjob for pointing it out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top