Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IFRs on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Plane

yamaCad

Mechanical
Jan 12, 2025
13
I'm trying create a plane from selected axis but I'm missing something so It can' create it. I record a macro for this but it takes like axis2 how can I get my axis selected? Because I'm not work with main axis. After selecting axis macro will create plane from selected axis. Or can start from xy direction or z direction of selected axis.

Recorded is like this:

Code:
Language="VBSCRIPT"

Sub CATMain()

Set partDocument1 = CATIA.ActiveDocument

Set part1 = partDocument1.Part

Set hybridShapeFactory1 = part1.HybridShapeFactory

Dim axisSystem1
' No resolution found for the object axisSystem1...

Set reference1 = part1.CreateReferenceFromBRepName("RSur:(Face:(Brp:(AxisSystem.2;1);None:();Cf11:());WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)", axisSystem1)

Set hybridShapePlaneOffset1 = hybridShapeFactory1.AddNewPlaneOffset(reference1, 20.000000, False)

Set hybridBodies1 = part1.HybridBodies

Set hybridBody1 = hybridBodies1.Item("kesme_celigi")

hybridBody1.AppendHybridShape hybridShapePlaneOffset1

part1.InWorkObject = hybridShapePlaneOffset1

part1.Update

End Sub

Here is my code:

Code:
Sub CATMain()

    Dim partDoc
    Set partDoc = CATIA.ActiveDocument

    Dim part
    Set part = partDoc.Part

    Dim hsf
    Set hsf = part.HybridBodies

    Dim geomSet
    Set geomSet = hsf.Add()
    geomSet.Name = "kesme_celigi"

    Dim selection
    Set selection = partDoc.Selection
    MsgBox "select axis"
    
    Dim status
    status = selection.SelectElement2(Array("AnyObject"), "select", False)

    If status = "Normal" Then
        Dim selectedAxis
        Set selectedAxis = selection.Item(1).Value


        If TypeName(selectedAxis) = "AxisSystem" Then
            Dim factory
            Set factory = part.HybridShapeFactory

            Dim xyPlane
            Set xyPlane = factory.AddNewPlaneExplicit(selectedAxis.GetItem("XY Plane"))

            geomSet.AppendHybridShape xyPlane
            part.Update
        Else
            MsgBox "select axis"
        End If
    Else
        MsgBox "selection canceled"
    End If
End Sub
 

Part and Inventory Search

Sponsor