×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

CATIA Macro : Extracting Point Coordinate in a Sub Geometrical Set

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

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

Hi

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 Sub 

Regards
Fernando

https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...

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

(OP)
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

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

(OP)

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

Hi,

Use


CODE --> CATScript

<html>
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
</html> 

Regards,
Maddy

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

(OP)
@maddy
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

Hi,

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 Sub 

Regards
Fernando

https://picasaweb.google.com/102257836106335725208
https://picasaweb.google.com/103462806772634246699...

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

(OP)
@fernando

thank you so much for the example.

regards
nmz

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources