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!

Centerline of a wire Macro 1

Status
Not open for further replies.

Runningkls

Mechanical
Apr 20, 2023
3
US
Hello,
I'm wondering if anyone can help me with a CATIA V5 macro to calculate the centerline of a wire/tube.
Ideally I'd like to have the macro make a spline in a geometrical set that follows the centerline so I can measure its length.

Any help would be appreciated.

Thank you
 
Replies continue below

Recommended for you

Hi Runningkls.

Autodesk's Fusion360 (like a CATIA macro) that measures and creates centerlines for pipes and harnesses.
Link
1_o9b9hy.png


Please feel free to use it if you have any use for it. Originally, it was requested by a Japanese user, so it only displays in Japanese, but it can be modified to display in other languages as well.

Fusion360 does not allow import/export of curves, but we have created an add-in for that purpose.
Link

I think it is possible to create a centerline using the same algorithm, but since CATIA's macros do not expose as much functionality as the Fusion360 API, I do not think it is possible to create a centerline in the same way.
 
Assuming the wire is actually swept properly this should work. Also, you will need a GSD (HDX) license for the surfacing operations.

1. 'Extract' the outside surface of the wire/tube.
2. Create an 'Isoparametric curve' that runs along the length of the surface (this operation can be found nested under the 'Spline' operation on the 'Wireframe' toolbar).
3. Create a 'Sweep' using the following settings:
Profile type: Line​
Subtype: With reference surface​
Guide curve 1: Isoparametric curve from step 2​
Reference surface: Extracted surface from step 1​
Angle: 90°​
Length1: The radius of your wire/tube​
4. 'Extract' the edge of the sweep that is at the center of your tube/wire.
5. Complete! Measure your CL.
2023-04-20_17_15_39-CATIA_V5_-_Part1.CATPart_ggu7qv.png


2023-04-20_17_20_26-Swept_Surface_Definition_txkq2a.png
 
It was so long ago that I had forgotten about it.
Please see the data available here.
Link

1_cnnw1s.png

Create two Isoparameters and two Sweeps on top of the pipe geometry.
The intersect between these two surfaces becomes the centerline.
In this method, the centerline can be obtained even if the radius is unknown or not constant.

This is not a macro, but it should improve your work efficiency by making a power copy of this.
 
Thank you for your solutions.
Unfortunately, I'm only looking for a macro, not a general workflow as I already have a workflow I can power copy.
 
Try this one for me :)

Oh and also for using this macro, open your part document. Select wire or tube whatever u want. Then start the macro

Code:
Sub CalculateWireCenterline()
    ' Get the active part document
    Dim partDoc As PartDocument
    Set partDoc = CATIA.ActiveDocument
    
    ' Get the active part
    Dim part As Part
    Set part = partDoc.Part
    
    ' Get the active wire or tube
    Dim wireOrTube As HybridShape
    Set wireOrTube = part.Selection.Item(1).Value
    
    ' Create a centerline curve
    Dim centerline As HybridShape
    Set centerline = part.HybridShapeFactory.AddNewCurve
    centerline.SetAsCenterline wireOrTube
    
    ' Update the part
    part.Update
    
    ' Select the centerline
    part.Selection.Clear
    part.Selection.Add centerline
    part.Selection.VisProperties.SetRealColor 255, 0, 0 ' Set color to red (optional)
    
    ' Refresh the display
    part.Update
    
    ' Show a message box with the centerline length
    MsgBox "Centerline Length: " & centerline.Length
    
    ' Clear the selection
    part.Selection.Clear
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top