2017-11-15 3 views
-1

Dies ist mein erster Beitrag, der um Hilfe mit Code bittet, den ich geschrieben habe, bitte um Klärung, wenn Sie ihn brauchen! Ich versuche Punktdaten aus CATIA V5 zu exportieren. Zur Zeit habe ich ein Makro, das die Benutzerauswahl eines geometrischen Satzes von Punkten übernimmt und Position exportiert, aber ich möchte auch den Symboltyp und die Farbe exportieren. Der angegebene CATIA-Beispielcode zeigt, wie auf visuelle Eigenschaften als VisProperties mit einem ausgewählten Element zugegriffen wird, und ich habe versucht, dies anzupassen, um meine Automatisierungskörper zu übernehmen. Meine Frage ist, wie exportiere ich Farbe und Symboltyp aus Automationskörpern? Hier ist das, was ich bisher:Symbol und Farbe von CATIA-Punkten können nicht exportiert werden

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 
+2

Willkommen bei SO. Ich konnte keine Frage finden, können Sie bitte klären, welche Art von Hilfe Sie suchen? Bitte lesen> [Wie zu fragen] (https://stackoverflow.com/help/how-to-ask) –

+1

Dumm mir, ich bearbeitet den Beitrag mit Klarstellung. Danke, dass du das auf David gezeigt hast! –

+0

Bitte stellen Sie sicher, um hilfreiche Antworten zu verbessern und markieren Sie die beste Antwort. Das ist unsere Währung! –

Antwort

2

VisProperties ist eine Eigenschaft des Selection-Objekts.

Also, was Sie tun müssen, ist nach Ihrer ersten Auswahl, setzen Sie alle Punkte Objekte in Auswahl nacheinander, um die Informationen zu erhalten.

Also, aus der Aufnahme, nachdem Sie den geometrischen Satz wählen, so etwas wie folgt aus:

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 

Dies setzt voraus, dass alles, was Sie sind Punkte in Ihrem geometrisches Set haben. Wenn nicht, müssen Sie jedes Objekt in der HybridShapes-Auflistung nur nach Punkten filtern.

+0

Das hat perfekt funktioniert. Das entscheidende Bit war: sSel.Add obj –

Verwandte Themen