Code:
'---------------------------------------------------------------------------------------
' Procedure : CreateNewPart
' Author : jherzog
' Date : 08.12.2016
' Time : 22:02
' Languages : VBA 6.5
' V5-Release: V5R19/21
' Purpose : create sketch and 3d-surf based on sketch
' Parms : -
' Ret. Value: -
'
' Syntax : CreateNewPart_4
'
' Prereqs : open catia session
' Remarks : sketch support plane(axis-plane) is defined in script
'---------------------------------------------------------------------------------------
'
Sub CreateNewPart_4()
Dim oADP As Part
Dim oPB As AnyObject
Dim oHB As HybridBody
Dim oSel ' As Selection
Dim oHSF As HybridShapeFactory
Dim oHSPC0 As HybridShapePointCoord
Dim oRef0 As Reference
Dim oSketchPln As Plane
Dim oRefPln As Reference
Dim oSK ' As Sketch
Dim oSKRef As Reference
Dim oF2D ' As Factory2D
Dim oHSEx As HybridShapeExtrude
Dim arrPt2D(5)
Dim oSpln2D As Spline2D
Dim oHSDir ' As HybridShapeDirection
Dim oAxSyst As AxisSystem 'axis system for measuring angles
Dim XY_Plane As Reference
Dim XZ_Plane As Reference
Dim YZ_Plane As Reference 'create new part
CATIA.Documents.Add ("Part")
Set oADP = CATIA.ActiveDocument.Part
Set oSel = CATIA.ActiveDocument.Selection
oSel.Clear
'hide origin planes
oSel.Add oADP.OriginElements.PlaneXY
oSel.Add oADP.OriginElements.PlaneYZ
oSel.Add oADP.OriginElements.PlaneZX
oSel.VisProperties.SetShow catVisPropertyNoShowAttr
oSel.Clear
'create axis
Set oAxSyst = oADP.AxisSystems.Add()
oADP.UpdateObject oAxSyst
oAxSyst.IsCurrent = True
'define ref planes
Set XY_Plane = oADP.CreateReferenceFromBRepName("RSur:(Face:(Brp:(" & oAxSyst.Name & ";1);None:();Cf11:());WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", oAxSyst)
Set XZ_Plane = oADP.CreateReferenceFromBRepName("RSur:(Face:(Brp:(" & oAxSyst.Name & ";3);None:();Cf11:());WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", oAxSyst)
Set YZ_Plane = oADP.CreateReferenceFromBRepName("RSur:(Face:(Brp:(" & oAxSyst.Name & ";2);None:();Cf11:());WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", oAxSyst)
'create/set and show geoset
Set oPB = oADP.Bodies.Item(1)
If oADP.hybridBodies.Count = 0 Then
Set oHB = oADP.hybridBodies.Add
Else
Set oHB = oADP.hybridBodies.Item(1)
End If
oSel.Add oHB
oSel.VisProperties.SetShow catVisPropertyShowAttr
oSel.Clear
'create/hide sketch plane
Set oHSF = oADP.HybridShapeFactory
Set oSketchPln = oHSF.AddNewPlaneOffset(XZ_Plane, 0#, True)
oHB.AppendHybridShape oSketchPln
oSel.Add oSketchPln
oSel.VisProperties.SetShow catVisPropertyNoShowAttr
oSel.Clear
oADP.Update
'create sketch
Set oSK = oHB.HybridSketches.Add(oSketchPln)
Set oF2D = oSK.OpenEdition
'create spline
Set arrPt2D(0) = oF2D.CreateControlPoint(0, 0)
Set arrPt2D(1) = oF2D.CreateControlPoint(20, 10)
Set arrPt2D(2) = oF2D.CreateControlPoint(40, -10)
Set arrPt2D(3) = oF2D.CreateControlPoint(70, 15)
Set arrPt2D(4) = oF2D.CreateControlPoint(100, -15)
Set oSpln2D = oF2D.CreateSpline(arrPt2D)
oSK.CloseEdition
oADP.Update
'create extruded surf
Set oHSDir = oHSF.AddNewDirection(oSketchPln)
Set oSKRef = oADP.CreateReferenceFromObject(oSK)
Set oHSEx = oHSF.AddNewExtrude(oSKRef, 30#, 0#, oHSDir)
oHB.AppendHybridShape oHSEx
oADP.Update
End Sub