Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

CATIA Macro : Extracting Point Coordinate in a Sub Geometrical Set 1

Status
Not open for further replies.

d2z

Automotive
May 1, 2013
6
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)
8699970071_f714d46f47.jpg


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:
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


 
Replies continue below

Recommended for you

Hi

Code:
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 Sub

Regards
Fernando

 
Hello Fernando,

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
 

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




 
Hi,

Use


Code:
[aqua]<html>[/aqua]
Sub CATMain()
Set partDocument1 = CATIA.ActiveDocument
Set part1 = partDocument1.Part
Set hybridBodies1 = part1.HybridBodies
Set hybridBody1 = hybridBodies1.Item("Geometrical Set.1")
GetAllChilds( hybridBody1 )
End Sub

Function GetAllChilds( oParent )
		MsgBox oParent.Name & vblf & oParent.HybridBodies.Count, ,oParent.Name
		If (NOT(oParent.HybridBodies.Count = 0)) Then
			' Loop if it has more than one item inside it
			Set oChild = oParent.HybridBodies.Item(1)
			GetAllChilds( oChild )
		Else
			
		End If
End Function
[aqua]</html>[/aqua]

Regards,
Maddy
 
@maddy
your function works! thanks!


@fernando
i think i get the idea, will try work on it later
 
Hi,

With a small modification, as I said.

Code:
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 Sub

Regards
Fernando

 
@fernando

thank you so much for the example.

regards
nmz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top