Search code examples
vbacatia

Can't Export Symbol and Color of CATIA points


This is my first post asking for help with code I've written, please ask for clarification if you need it! I am trying to export point data from CATIA V5. Currently I have a macro which takes user selection of a Geometric Set of points and exports position but I also want to export the symbol type and color. The CATIA given example code shows how to access visual properties as VisProperties with one item selected and I've tried to adapt that to take my automation bodies. My question is, how do I export color and symbol type from automation bodies? Here is what I have so far:

Language="VBSCRIPT"

Sub CATMain()

Dim oPartDoc As Part
On Error Resume Next
Set oPartDoc = CATIA.ActiveDocument.Part    
If Err.Number <> 0 Then                   
Message = MsgBox("Sorry, This script works with a CATPart as Active 
document", vbCritical, "Error")
Exit Sub
End If

    ' What do want to select

    Dim EnableSelectionFor(0)
    EnableSelectionFor(0) = "HybridBody"

    ' Reset the Selection

    Set sSEL = CATIA.ActiveDocument.Selection
    sSEL.Clear

 ' Define Selection

    MsgBox "Please Select the Geometrical Set that contains Points"

    UserSelection = sSEL.SelectElement2(EnableSelectionFor,  "Please select 
another Geometrical Set", False)
    ' Evaluation if the selectio is correct or not
    If UserSelection <> "Normal" Then
        MsgBox "Error with the selection"
        Exit Sub
Else
Set ohybridbody = sSEL.Item(1).Value

    MsgBox "The Geometrical Set selected is : " & ohybridbody.Name 

    End If
'//Defining collection arrays

ReDim acoord(2)
Dim symbol
Dim r, g, b

'//initializing symbol and color collection arrays, may be wrong?

symbol=CLng(0)
r=CLng(0)
g=CLng(0)
b=CLng(0)



'---------------------------------------------------------------------------
-----
'   The location of the result file
'---------------------------------------------------------------------------
-----
Dim filename As String

filename = CATIA.FileSelectionBox("Where do you want to save the result 
file", "*.txt", CatFileSelectionModeSave)

Set Datos = CATIA.FileSystem.CreateFile(filename & ".txt" , True)

Set ostream = Datos.OpenAsTextStream("ForAppending")

ostream.Write ("Points Extraction from " & oPartDoc.Name & ".CATPart" & 
Chr(10))
ostream.Write (" "& Chr(10))
ostream.Write ("The selected Geometrical Set was : " & ohybridbody.Name & 
Chr(10))
ostream.Write (" "& Chr(10))

'////Selection of points within geometrical set
Set oshapes = ohybridbody.HybridShapes

'///this part may be wrong
Set visproperties1=oshapes.VisProperties

'///Loop to run on each point in geometrical set
For i = 1 To oshapes.Count
oshapes.Item(i).GetCoordinates acoord

'////Trying to access visual properties , def wrong here
visproperties1.Item(i).GetSymbolType symbol
visproperties1.Item(i).GetRealColor r, g, b

'/////Writing to file

Set reference1 = oshapes.Item(i)

ostream.Write (reference1.Name & Chr(0009) & acoord(0) & Chr(0009) & 
acoord(1) & Chr(0009) & acoord(2) & Chr(0009) & symbol & Chr(0009) & r & 
Chr(0009) & g & Chr(0009) & b & Chr(0009) & Chr(10))

Next

ostream.Close

MsgBox  "Points Exported :" & (i-1) & "x" & Chr(10) & Chr(10) & "Please 
Check the following file for result : " &  chr(10) &  chr(10) & filename &  
chr(10)&  chr(10) & "Process finished" 

End Sub

Solution

  • VisProperties is a property of the Selection object.

    So what you need to do is after your initial selection, put all the point objects into selection one by one to get the information.

    So, taking up from after you select the geometrical set, something like this:

    Set ohybridbody = sSEL.Item(1).Value
    
    'clear the selection  
    sSel.Clear
    
    for i = 1 to oHybridBody.HybridShapes.Count
        Set obj = oHybridBody.HybridShapes.Item(i)
        obj.GetCoordiates coords
        sSel.Add obj
        sSel.VisProperties.GetSymbolType symbol
        sSel.VisProperties.GetRealColor r, g, b
        ....  output your results....
        sSel.Clear 
    Next
    

    This assumes that all you have are points in your geometrical set. If not you have to filter each object in the HybridShapes collection for points only.