×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

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!

*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

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

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

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

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

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

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.

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

I have added this row within your for-next loop:
objsheet1.cells(i + 1, 6) = Point.Parent.Parent.name

regards,
LWolf

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

Quote (LWolf)

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

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

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

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

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

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

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

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

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

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

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.

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

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

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

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 

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

(OP)
thank you very much!!!
Is exactly what I need, works perfectly!!!!
thanks

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

Can someone give me some advice how to modify this code to output the points in Inches?

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

CODE

Inches = objexcel.PointsToInches(points) 

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

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

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?

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

try:
dim coords() as Variant
redim coords(2)

regards,
LWolf

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

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?

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

Nevermind, it works now!

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

Thanks!

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! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close