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!

CATIA macro for tubes

Status
Not open for further replies.

Gilgamesh99

Automotive
Jun 11, 2013
45
MX
Hi:

Im trying to develop a CATIA V5 R16 Macro to construct a tube based on points (coordinates), lines (based on the points), bend radius and outer/inner diameter. The condition here is that it should have a user interface so the user can introduce the coordinates, bend radius and the outer/inner diameter and when click OK it should automatically construct the tube. Im not completely lost since I know a little VB programation but it is very hard to find information about CATIA macros.

Thanks in advance for your help!
 
Replies continue below

Recommended for you

Hello Gilgamesh99,

Here below you may find some code to start with.
The user shall create a polyline as a path in the Geometrical Set.1 and then run the macro.

Sub CATMain(dBendRadius, dDiameter, dThickness)
Dim oActivePartDoc: Set oActivePartDoc = CATIA.ActiveDocument
Dim oPart As Part: Set oPart = oActivePartDoc.Part
Dim Selection: Set Selection = CATIA.ActiveDocument.Selection: Selection.Clear
Dim varFilter(0) As Variant: varFilter(0) = "HybridShape"
Dim HSPolyline As HybridShapePolyline
Dim HSPElement(1 To 4) As Reference
Dim HSPRadius(1 To 4) As Length
Dim i As Long
Dim HSCircle3D As HybridShapeCircleCtrRad
'Select a Polyline as Path
strReturn = Selection.SelectElement2(varFilter, "Select the Pipe Center Line (a Polyline):", False): If (strReturn = "Cancel") Then Exit Sub
Set HSPolyline = Selection.Item2(1).Value
Set HSCircle3D = HSCCRCreateProfile(HSPolyline, 0.5 * CDbl(dDiameter)) 'Create a 3DCircle for Profile
Call CreatePipe(HSPolyline, HSCircle3D, CDbl(dThickness)) 'Create Rib for Pipe
oPart.Update 'Update Part
Call SetAllRadius(HSPolyline, CDbl(dBendRadius)) 'Set Radius
Call HideObject(HSCircle3D) 'Hide Auxilliary Elements
Call HideObject(HSPolyline)
oPart.Update
End Sub

Function HSCCRCreateProfile(hspPath As HybridShapePolyline, dRadius As Double) As HybridShapeCircleCtrRad
Dim oActivePartDocument As PartDocument: Set oActivePartDocument = CATIA.ActiveDocument
Dim oPart As Part: Set oPart = oActivePartDocument.Part
Dim oHSFactory As HybridShapeFactory: Set oHSFactory = oPart.HybridShapeFactory
Dim oHBodies As HybridBodies: Set oHBodies = oPart.HybridBodies
Dim oHBody As HybridBody: Set oHBody = oHBodies.Item("Geometrical Set.1") 'In Geometrical Set.1
Dim oHShapes As HybridShapes: Set oHShapes = oHBody.HybridShapes
Dim oHSPolyline As HybridShapePolyline: Set oHSPolyline = oHShapes.Item(hspPath.Name) 'Input 1 oHSPolyline=hsPolyline
Dim rRefPath As Reference: Set rRefPath = oPart.CreateReferenceFromObject(oHSPolyline)
Dim lBendRadius As Length
Dim rRefCenterPt As Reference: oHSPolyline.GetElement 1, rRefCenterPt, lBendRadius
Dim HSPlaneNormal As HybridShapePlaneNormal: Set HSPlaneNormal = oHSFactory.AddNewPlaneNormal(rRefPath, rRefCenterPt)
oHBody.AppendHybridShape HSPlaneNormal
Call HideObject(HSPlaneNormal)
oPart.InWorkObject = HSPlaneNormal
Dim rRefSupport As Reference: Set rRefSupport = oPart.CreateReferenceFromObject(HSPlaneNormal)
Dim HSCircle3D As HybridShapeCircleCtrRad
Set HSCircle3D = oHSFactory.AddNewCircleCtrRad(rRefCenterPt, rRefSupport, False, dRadius) 'Input 2
HSCircle3D.SetLimitation 1
oHBody.AppendHybridShape HSCircle3D
oPart.InWorkObject = HSCircle3D
Set HSCCRCreateProfile = HSCircle3D
End Function

Sub CreatePipe(HSPolyline As HybridShapePolyline, HSCircle3D As HybridShapeCircleCtrRad, dThickness As Double)
Dim oPart As Part
Dim oShapeFactory As ShapeFactory
Dim oBody As Body
Dim oReference1, oReference2 As Reference
Dim oRib As Rib
Dim oParameters As Parameters
Dim lenLenght As Length

Set oPart = CATIA.ActiveDocument.Part
Set oBody = oPart.Bodies.Item("PartBody")
oPart.InWorkObject = oBody
Set oShapeFactory = oPart.ShapeFactory
Set oReference1 = oPart.CreateReferenceFromObject(HSCircle3D)
Set oReference2 = oPart.CreateReferenceFromObject(HSPolyline)
Set oRib = oShapeFactory.AddNewRibFromRef(oReference1, oReference2)
oRib.IsThin = True
Set oParameters = oPart.Parameters
Set lenLenght = oParameters.Item(oPart.Name & "\PartBody\" & oRib.Name & "\ThickThin2")
lenLenght.Value = dThickness
Set lenLenght = oParameters.Item(oPart.Name & "\PartBody\" & oRib.Name & "\ThickThin1")
lenLenght.Value = 0#
oPart.Update
End Sub


'UTILITIES
Sub HideObject(obj As Variant)
Dim Selection As Selection
Set Selection = CATIA.ActiveDocument.Selection
Selection.Add obj
Selection.VisProperties.SetShow catVisPropertyNoShowAttr
End Sub

Sub ShowObject(obj As Variant)
Dim Selection As Selection
Set Selection = CATIA.ActiveDocument.Selection
Selection.Add obj
Selection.VisProperties.SetShow catVisPropertyShowAttr
End Sub
Sub SetAllRadius(HSPolyline As HybridShapePolyline, dBendRadius As Double)
Dim HSPNoOfElements As Long
HSPNoOfElements = HSPolyline.NumberOfElements
For i = 2 To HSPNoOfElements - 1
HSPolyline.SetRadius i, dBendRadius
Next i
End Sub


I Hope it helps.

-GEL

Imposible is nothing.
 
Thank you very much.

The interface for this particular macro is great. Unfortunately it doesnt work for me. Im using CATIA V5R16. What can I do?
 
How to use Pipe macro:
[ol 1]
[li]Open a new Part. In the [New Part] dialog box check the [Enable hybrid design] and [Create a geometrical set] option so as to create a Geometrical Set. CATIA will create the Geometrical Set.1[/li]
[li]Move to the GSD Workbench and draw a polyline (not sequence of lines) in Geometrical Set.1[/li]
[li]Run Pipe macro, enter values to the [Macro Parameters] dialog box and click OK.
Note that parameters values shall be consistent to the drawn polyline. This means that if you use only 90 deg bends:[/li]
[ul]
[li]The first and last element of the polyline shall have length > 1*BendRadius.[/li]
[li]All other elements of the polyline shall have length >= 2*BendRadius.[/li]
[li]BendRadius shall be > Diameter (Practically for tubing, BendRadius >= 2.5*Diameter).[/li]
[/ul][li]Select the previously drawn polyline. The tube created.[/li]
[/ol]

Note: If you are going to bend a tube in a specific bending machine and if you use bends other than 90 degs then the above restrictions shall be upgraded. For example, the DBB(Minimum Distance Between Bends) shall take into consideration the Grip Length of the bending machine and the values of the two bending angles.

I hope it helps.
If you like this post then star it!


-GEL
Imposible is nothing.
 
Thank you very much for your support. Unfortunately when I run the macro as you specified, nothing happens (the GUI appears and I enter the values, then click run but nothing happens).

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top