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
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
CODE -->
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
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
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
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
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
RE: Export Catia V5 CatPart points coordinates and corresponding bodie's names into csv or excel
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
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
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
CODE -->
RE: Export Catia V5 CatPart points coordinates and corresponding bodie's names into csv or excel
Is exactly what I need, works perfectly!!!!
RE: Export Catia V5 CatPart points coordinates and corresponding bodie's names into csv or excel
RE: Export Catia V5 CatPart points coordinates and corresponding bodie's names into csv or excel
CODE
Skip,
Just traded in my OLD subtlety...
for a NUance!
RE: Export Catia V5 CatPart points coordinates and corresponding bodie's names into csv or excel
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
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
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
I removed the dim coords() as Variant completely and kept the redim coords(2) line, it works perfectly.
Thanks!