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

时间:2017-11-15 14:17:05

标签: vba catia

这是我第一篇要求帮助编写代码的帖子,如果您需要,请询问澄清!    我正在尝试从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

1 个答案:

答案 0 :(得分:2)

VisProperties是Selection对象的属性。

所以你需要做的是在初步选择之后,逐个选择所有的点对象来获取信息。

因此,在选择几何图形集之后,请选择以下内容:

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集合中的每个对象进行过滤。