Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Export Catia V5 CatPart points coordinates and corresponding bodie's names into csv or excel 3

Status
Not open for further replies.

Pawel Chil

Automotive
Apr 19, 2018
10
Hello every one,

I want in Catia V5 CatPart to export coordinates of all points and corresponding bodie's names.
I have a macro where I can export only points or only names. I can't join it in this way that receive a list where I see which point coordinates belongs to which body(name).
Can anybody help me?
Thanks in advance!
Below a macro for only point's coordinates.

sub catmain()

set objexcel=CreateObject("Excel.Application")

objexcel.Visible=True

Set objWorkbook= objexcel.workbooks.Add()

set objsheet1=objWorkbook.sheets.item(1)

objsheet1.name="Points_Coordinates"

dim coords(2) as variant

CATIA.ActiveDocument.Selection.Search "( CATPrtSearch.Point),all"




for i=1 to catia.activedocument.selection.count

set selection=catia.activedocument.selection

set element=selection.item(i)

set point=element.value

point.getcoordinates(coords)

objsheet1.cells(i+1,1)=point.name

objsheet1.cells(i+1,2)=coords(0)

objsheet1.cells(i+1,3)=coords(1)

objsheet1.cells(i+1,4)=coords(2)
objsheet1.cells(i+1,5)=element.name

next

end sub
 
Replies continue below

Recommended for you

Add this before the "next" statement:

Code:
Set parentObject = Point.Parent
Do
    If TypeName(parentObject) = "HybridBody" Or TypeName(parentObject) = "Body" Then
        objsheet1.cells(i + 1, 5) = parentObject.Name
        Exit Do
    Else
        Set parentObject = parentObject.Parent
    End If
    'safe check
    If TypeName(parentObject) = "Part" Then
        Exit Do 'you've went to far up and reached the Part itself.
    End If
Loop

L.E.: I didn't test this but it should work. Let me know.
 
I have added this row within your for-next loop:
objsheet1.cells(i + 1, 6) = Point.Parent.Parent.name

regards,
LWolf
 
LWolf said:
objsheet1.cells(i + 1, 6) = Point.Parent.Parent.name

That might fail if the point is not directly under a HybridBody but under a feature (which is under a feature and so on) inside the HybridBody.

Apologies if it works (as stated above, I don't have access to CATIA atm).

Calin
 
Thanks a lot. It works for my Product where all Bodies have right name as "body" but I have to work with AllCatPart created from this Product.
So, my Body names are changed and unpredictable.
Is it possible to write "if" condition in such way:
If TypeName(parentObject) = "contains fragment of the body name"??

regards
 
sorry but I did some confusion...
After converting into AllCatPart I have my POINTS in Geometrical Sets not in Bodies.
So the Point's Parent = GeometricalSet

@LWolf
Your code works but shows either file name or root name(if I put there only one "Parent"

Pawel
 
I don't understand the problem with the code I provided: is there an error? It should return the parent's name regardless of type (Body = Body; GeometricalSet = HybridBody).
 
hi Calin,
there is no error in your code but also no result in Excel when I run it in my AllCatPart.
I need to get:
1- coordinates of points (I already have it)
2-names of GeometricalSets where I have each point

In attachment I saved screen from Catia. Maybe it will make things more clear.
Accordint the screen,I need in Excel a result like this:
Point.2 ;x=...; y=...;z=...;CL_2_Point

I don't know how to get CL_2_Point

regards
Pawel
 
 https://files.engineering.com/getfile.aspx?folder=5fd43b2c-1a69-4fda-87de-520fb3288b4c&file=Screen1.PNG
Please post the whole code including the bit I provided.

L.E. No need. The behavior is different when the point is isolated. I'll return.
 
sub catmain()

set objexcel=CreateObject("Excel.Application")

objexcel.Visible=True

Set objWorkbook= objexcel.workbooks.Add()

set objsheet1=objWorkbook.sheets.item(1)

objsheet1.name="Points_Coordinates"

dim coords(2) as variant

CATIA.ActiveDocument.Selection.Search "( CATPrtSearch.Point),all"


for i=1 to catia.activedocument.selection.count

set selection=catia.activedocument.selection

set element=selection.item(i)

set point=element.value

point.getcoordinates(coords)

objsheet1.cells(i+1,1)=point.name

objsheet1.cells(i+1,2)=coords(0)

objsheet1.cells(i+1,3)=coords(1)

objsheet1.cells(i+1,4)=coords(2)
'objsheet1.cells(i+1,5)=element.name
'objsheet1.cells(i + 1, 6) = Point.Parent.Parent.name

'****************
Set parentObject = Point.Parent
Do
If TypeName(parentObject) = "HybridBody" Or TypeName(parentObject) = "Body" Then
objsheet1.cells(i + 1, 5) = parentObject.Name
Exit Do
Else
Set parentObject = parentObject.Parent
End If
'safe check
If TypeName(parentObject) = "Part" Then
Exit Do 'you've went to far up and reached the Part itself.
End If
Loop
'*******************
next

end sub
 
Here is what you need.

Code:
Sub CATMain()

    Set objexcel = CreateObject("Excel.Application")
    
    objexcel.Visible = True
    
    Set objWorkbook = objexcel.workbooks.Add()
    
    Set objsheet1 = objWorkbook.Sheets.Item(1)
    
    objsheet1.Name = "Points_Coordinates"
    
    Dim coords(2) As Variant
    
    Set Selection = CATIA.ActiveDocument.Selection
    
    Selection.Search "( CATPrtSearch.Point),all"
    
    For i = 1 To Selection.Count
        
        Set Element = Selection.Item(i)
        
        Set Point = Element.Value
        
        Point.GetCoordinates (coords)
        
        objsheet1.cells(i + 1, 1).Value = Point.Name
        
        objsheet1.cells(i + 1, 2).Value = coords(0)
        
        objsheet1.cells(i + 1, 3).Value = coords(1)
        
        objsheet1.cells(i + 1, 4).Value = coords(2)
        'objsheet1.cells(i + 1, 5) = Element.Name
        
        'this is for non-isolated Points
        Set parentObject = Point.Parent
        Do
            If TypeName(parentObject) = "HybridBody" Or TypeName(parentObject) = "Body" Then
                objsheet1.cells(i + 1, 5).Value = parentObject.Name
                Exit Do
            Else
                Set parentObject = parentObject.Parent
            End If
            'safe check
            If TypeName(parentObject) = "Part" Then
                Exit Do 'you've went to far up and reached the Part itself.
            End If
        Loop
        
        'this is for isolated points
        If objsheet1.cells(i + 1, 5).Value = "" Then
            bFound = False
            Set oPart = CATIA.ActiveDocument.Part
            'temporarily rename the point so the proper point is retrieved.
            tmpPointName = "tmpPoint." & i
            Point.Name = tmpPointName
            For ix = 1 To oPart.HybridBodies.Count
                Set oMyHBody = oPart.HybridBodies.Item(ix)
                For jx = 1 To oMyHBody.HybridShapes.Count
                    Set oHShape = oMyHBody.HybridShapes.Item(jx)
                    If oHShape.Name = tmpPointName Then
                        'this is my Point. get the parent's name
                        objsheet1.cells(i + 1, 5).Value = oMyHBody.Name
                        bFound = True
                        Exit For
                    End If
                Next
                If bFound Then Exit For
            Next
            Point.Name = objsheet1.cells(i + 1, 1).Value
        End If
    Next

End Sub
 
thank you very much!!!
Is exactly what I need, works perfectly!!!!
[thanks]
 
Can someone give me some advice how to modify this code to output the points in Inches?
 
Code:
Inches = objexcel.PointsToInches(points)

Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 
Hi all,

I have the same issue (trying to export coordinates to excel) and came across this thread from the search function.

The macro looks like it would fit my needs perfectly but when I try to run it it fails on Line 13 "dim coords(2) As Variant".

I really have no programming experience and was wondering if anyone could point me in the right direction?
 
try:
dim coords() as Variant
redim coords(2)

regards,
LWolf
 
Still the same issue I'm afraid

The full script:

Sub CATMain()

Set objexcel = CreateObject("Excel.Application")

objexcel.Visible = True

Set objWorkbook = objexcel.workbooks.Add()

Set objsheet1 = objWorkbook.Sheets.Item(1)

objsheet1.Name = "Points_Coordinates"

dim coords() as Variant
redim coords(2)

Set Selection = CATIA.ActiveDocument.Selection

Selection.Search "( CATPrtSearch.Point),all"

For i = 1 To Selection.Count

Set Element = Selection.Item(i)

Set Point = Element.Value

Point.GetCoordinates (coords)

objsheet1.cells(i + 1, 1).Value = Point.Name

objsheet1.cells(i + 1, 2).Value = coords(0)

objsheet1.cells(i + 1, 3).Value = coords(1)

objsheet1.cells(i + 1, 4).Value = coords(2)
'objsheet1.cells(i + 1, 5) = Element.Name

'this is for non-isolated Points
Set parentObject = Point.Parent
Do
If TypeName(parentObject) = "HybridBody" Or TypeName(parentObject) = "Body" Then
objsheet1.cells(i + 1, 5).Value = parentObject.Name
Exit Do
Else
Set parentObject = parentObject.Parent
End If
'safe check
If TypeName(parentObject) = "Part" Then
Exit Do 'you've went to far up and reached the Part itself.
End If
Loop

'this is for isolated points
If objsheet1.cells(i + 1, 5).Value = "" Then
bFound = False
Set oPart = CATIA.ActiveDocument.Part
'temporarily rename the point so the proper point is retrieved.
tmpPointName = "tmpPoint." & i
Point.Name = tmpPointName
For ix = 1 To oPart.HybridBodies.Count
Set oMyHBody = oPart.HybridBodies.Item(ix)
For jx = 1 To oMyHBody.HybridShapes.Count
Set oHShape = oMyHBody.HybridShapes.Item(jx)
If oHShape.Name = tmpPointName Then
'this is my Point. get the parent's name
objsheet1.cells(i + 1, 5).Value = oMyHBody.Name
bFound = True
Exit For
End If
Next
If bFound Then Exit For
Next
Point.Name = objsheet1.cells(i + 1, 1).Value
End If
Next

End Sub

Attached is the error message I get. Any ideas?
 
 https://files.engineering.com/getfile.aspx?folder=b9cf39bf-4159-4913-ae0a-1a6fd264e597&file=Capture.JPG
Nevermind, it works now!

I removed the dim coords() as Variant completely and kept the redim coords(2) line, it works perfectly.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor