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!

Best Fit line 2

Status
Not open for further replies.

catiabegginer

New member
Mar 6, 2013
2
US
Dear All,

I'm a new catia user and would have a question for you.

I'm using a mesuring device that produce a set of points in catia.

Does anyone knows a way to trace a best fit line through those points? (like linear regression ).

Thank you in advance for your help.
 
Replies continue below

Recommended for you

In my opinion You need to use a macro that calculate line equation from given points

You need to use method "GetCoordinates" (Member of HybridShapeTypeLib.Point)

Is it Yours school project or You need this for commercial use?

If You are interested in Macros in Catia (Catscripts, Catvba) feel free to send me a message. I will wrote specified macros for free and post it on eng-tips forum
 
Code:
Sub CATMain()

Set ParttDocument1 = CATIA.ActiveDocument
Dim Coord(2)

Set selection1 = ParttDocument1.Selection
PointName = selection1.Item(1).Reference.Name
HybridBodyName = selection1.Item(1).Reference.Parent.Parent.Name
ParttDocument1.Part.HybridBodies.Item(HybridBodyName).HybridShapes.Item(PointName).GetCoordinates Coord

MsgBox " Coordinates  X:" & Coord(0) & "   Y:" & Coord(1) & "   Z:" & Coord(2)
End Sub

Here is a simple code to get coordinates from selected points
You can replace lines:
Code:
PointName = selection1.Item(1).Reference.Name
HybridBodyName = selection1.Item(1).Reference.Parent.Parent.Name
ParttDocument1.Part.HybridBodies.Item(HybridBodyName).HybridShapes.Item(PointName).GetCoordinates Coord

by this one:
Code:
selection1.Item(1).Value.GetCoordinates Coord
It would help to avoid problems with points or geometrical sets with the same names

Lukasz

If You are interested in Macros in Catia (Catscripts, Catvba) feel free to send me a message. I will wrote specified macros for free and post it on eng-tips forum
 
Thanks a lot Lukaszsz for you help.

Your macro works just fine. I have some background in programming in C and Java but none in vbs.

I know i need to create a Type for coord
Then a array of my new type
Collect all the coord in my array.

I tried a bit but without proper knowledge of vbs, i couldnt succeed.

Writing the routine to best fit a line given the coordinates of point shouldnt be a problem.

 
Writing the routine to best fit a line given the coordinates of point shouldnt be a problem.

Not in 2-D, but in 3-Dimensional space Line is referenced by 6 variables, 2 planes intersection (2x3variables) or vector[x,y,z] and passing point (xa,ya,za).

to create array dimensioned as below [number of points, coordinates] try to use this script:

Code:
Sub CATMain()

Set PartDocument1 = CATIA.ActiveDocument
Set selection1 = PartDocument1.Selection
Dim Coord(2)
Dim Crd() As Variant

ReDim Crd(selection1.Count - 1, 2)


For i = 1 To selection1.Count
selection1.Item(i).Value.GetCoordinates Coord
Crd(i - 1, 0) = Coord(0)
Crd(i - 1, 1) = Coord(1)
Crd(i - 1, 2) = Coord(2)
MsgBox " Coordinates of point No: " & i & Chr(10) & " X:" & Crd(i - 1, 0) & "   Y:" & Crd(i - 1, 1) & "   Z:" & Crd(i - 1, 2)
Next i
End Sub

If You are interested in Macros in Catia (Catscripts, Catvba) feel free to send me a message. I will wrote specified macros for free and post it on eng-tips forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top