无法导出 CATIA 点的符号和颜色

Can't Export Symbol and Color of CATIA points

这是我第一次 post 就我编写的代码寻求帮助,如果您需要,请要求澄清! 我正在尝试从 CATIA V5 导出点数据。目前我有一个宏,它需要用户选择一组几何点并导出位置,但我也想导出符号类型和颜色。 CATIA 给出的示例代码显示了如何访问视觉属性作为 VisProperties 并选择了一个项目,我试图对其进行调整以采用我的自动化机构。 我的问题是,如何从自动化主体导出颜色和符号类型?这是我目前拥有的:

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

VisProperties 是一个 属性 的 Selection 对象。

所以你需要做的就是在你最初的selection之后,把所有的点对象一个一个的放入selection中去获取信息。

所以,从你之后 select 开始几何集,像这样:

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

这假设您拥有的只是几何集中的点。否则,您必须仅针对点过滤 HybridShapes 集合中的每个对象。