CATIA Macro : Extracting Point Coordinate in a Sub Geometrical Set
CATIA Macro : Extracting Point Coordinate in a Sub Geometrical Set
(OP)
Hi all
i'm new in catia macro programming. what i'm working on now is extracting points coordinates from CATPart.
my problem now is how to extract point in a sub geometrical set.
refer picture below (point 1 in geometrical set.2)
i only manage to extract point from 'parent geometrical set' (geometrical set.1)

here is my code for now. do comment what i can improve the current code. i have really basic programming skill.
tq in advance :)
i'm new in catia macro programming. what i'm working on now is extracting points coordinates from CATPart.
my problem now is how to extract point in a sub geometrical set.
refer picture below (point 1 in geometrical set.2)
i only manage to extract point from 'parent geometrical set' (geometrical set.1)

here is my code for now. do comment what i can improve the current code. i have really basic programming skill.
tq in advance :)
CODE --> CATscript
Sub CATMain()
Dim ActDoc As Object
Set ActDoc = CATIA.ActiveDocument
Dim part1 As Object
Set part1 = ActDoc.Part
Dim hybridBodies1 As Object
Set hybridBodies1 = part1.HybridBodies
For geometSet = 1 To hybridBodies1.Count
Dim hybridBody1 As Object
Set hybridBody1 = hybridBodies1.Item(geometSet)
Dim hybridShapes1 As Object
Set hybridShapes1 = hybridBody1.HybridShapes
For geometElem = 1 To hybridShapes1.Count
Dim point1
Set point1 = hybridShapes1.Item(geometElem)
On Error Resume Next
Dim coordArray(2)
Dim sel As Object
Set sel = ActDoc.selection
sel.Add (point1)
sel.Clear
point1.GetCoordinates coordArray
p=0
msgbox "Point: " & point1.Name & vbNewLine & "X : " & coordArray(p) & vbNewLine & "Y: " & coordArray(p+1) & vbNewLine & "Z: " & coordArray(p+2)
p + 1
Next 'geometElem
Next 'geometSet
End Sub 




RE: CATIA Macro : Extracting Point Coordinate in a Sub Geometrical Set
CODE --> CATScript
Sub CATMain() Dim iAnswer iAnswer = MsgBox ("You need to select first your points" & Chr(10) & "Click OK if you already done the selection or Cancel to EXIT", vbOKCancel) if iAnswer = vbCancel Then Exit Sub Else Dim oWindow Set oWindow = CATIA.ActiveWindow 'create text file sPath = "C:\Temp" sName = "\Points_coord_for_" & oWindow.Caption & ".TXT" sFile = sPath & sName Dim oFileOut 'As File Set oFileOut = CATIA.FileSystem.CreateFile(sFile, True) Dim oStream 'As TextStream Set oStream = oFileOut.OpenAsTextStream("ForWriting") Dim mySelection as Selection Set mySelection = Catia.ActiveDocument.Selection Dim Selection as integer Selection = mySelection.count oStream.Write ( "Point_name" & ";" & "X-Coord" & ";" & "Y-Coord" & ";" & "Z-Coord" & Chr(10)) Dim I as integer Dim oPointCoord(2) as CATSafeVariant Dim oSelElem as Object For I = 1 to Selection Set oSelElem = mySelection.Item(I) oSelElem.Value.GetCoordinates (oPointCoord) text = oPointCoord(0) & ";" & oPointCoord(1) & ";" & oPointCoord(2) oStream.Write (mySelection.Item(I).Value.name &";" & oPointCoord(0)& ";"& oPointCoord(1)&";"& oPointCoord(2) &";" &Chr(10)) Next oStream.Close End If End SubRegards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: CATIA Macro : Extracting Point Coordinate in a Sub Geometrical Set
Already tested your code,
Instead of selecting the point one by one, I want it to run automatically.
The geometrical set also has another item in there (circle and line)
or can you point out what is the problem in my code?
Hope you can advise.
Thank you
RE: CATIA Macro : Extracting Point Coordinate in a Sub Geometrical Set
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: CATIA Macro : Extracting Point Coordinate in a Sub Geometrical Set
thanks for the feedback.
my problem is to search for sub geometrical set. if all the point in main geometrical set, my code can capture the points.
how to search for all geometrical sets?
can you point out how? apparently when i'm using hybridbodies, it will only capture main geometrical set.
thanks in advance
RE: CATIA Macro : Extracting Point Coordinate in a Sub Geometrical Set
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: CATIA Macro : Extracting Point Coordinate in a Sub Geometrical Set
Use
CODE --> CATScript
Regards,
Maddy
RE: CATIA Macro : Extracting Point Coordinate in a Sub Geometrical Set
your function works! thanks!
@fernando
i think i get the idea, will try work on it later
RE: CATIA Macro : Extracting Point Coordinate in a Sub Geometrical Set
With a small modification, as I said.
CODE --> CATScript
Sub CATMain() Dim iAnswer iAnswer = MsgBox ("Macro will select your points" & Chr(10) & "Click OK to continue or Cancel to EXIT", vbOKCancel) if iAnswer = vbCancel Then Exit Sub Else Dim oWindow Set oWindow = CATIA.ActiveWindow 'create text file sPath = "C:\Temp" sName = "\Points_coord_for_" & oWindow.Caption & ".TXT" sFile = sPath & sName Dim oFileOut 'As File Set oFileOut = CATIA.FileSystem.CreateFile(sFile, True) Dim oStream 'As TextStream Set oStream = oFileOut.OpenAsTextStream("ForWriting") Dim I as integer Dim oPointCoord(2) as CATSafeVariant Dim oSelElem as Object Dim partDocument1 As Document Set partDocument1 = CATIA.ActiveDocument Dim selection1 As Selection Set selection1 = partDocument1.Selection selection1.Search "CATPrtSearch.OpenBodyFeature,all" Dim selection2 As Selection Set selection2 = partDocument1.Selection selection2.Search "CATPrtSearch.Point,sel" Dim mySelection as Selection Set mySelection = Catia.ActiveDocument.Selection Dim Selection as integer Selection = selection2.count oStream.Write ( "Point_name" & ";" & "X-Coord" & ";" & "Y-Coord" & ";" & "Z-Coord" & Chr(10)) For I = 1 to Selection Set oSelElem = mySelection.Item(I) oSelElem.Value.GetCoordinates (oPointCoord) text = oPointCoord(0) & ";" & oPointCoord(1) & ";" & oPointCoord(2) oStream.Write (mySelection.Item(I).Value.name &";" & oPointCoord(0)& ";"& oPointCoord(1)&";"& oPointCoord(2) &";" &Chr(10)) Next oStream.Close End If End SubRegards
Fernando
https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...
RE: CATIA Macro : Extracting Point Coordinate in a Sub Geometrical Set
thank you so much for the example.
regards
nmz