読者です 読者をやめる 読者になる 読者になる

C#ATIA

↑タイトル詐欺 主にCATIA V5 の VBA

指定したエッジをセンターラインとするパイプ形状の作成マクロ

ご質問頂いていたエッジを指定してパイプ形状を作成するマクロです。

色々と不足している部分はありますが、ご参考になれば。

Dim PartDoc As PartDocument
Dim oPart As Part
Dim HBody As HybridBody
    
Sub CATMain()
    Set PartDoc = CATIA.ActiveDocument
    Set oPart = PartDoc.Part
    
    Dim oSel 'As Selection
    Set oSel = PartDoc.Selection
    
    Dim FilterType(0)  As Variant
    FilterType(0) = "Edge"
    
    Dim Ref As Reference
    With oSel
        .Clear
        If .SelectElement2(FilterType, "Select", fulse) = "Cancel" Then End
        Set Ref = oPart.CreateReferenceFromBRepName( _
                    GetBrepName(.Item(1).Value.Name), .Item(1).Value.Parent)
    End With
    
    Set HBody = oPart.HybridBodies.Add()
    Call SweepCircle(Ref)
End Sub

'SweepCircle
Private Sub SweepCircle(Ref As Reference)

    Dim hybridShapeFactory1 As HybridShapeFactory
    Set hybridShapeFactory1 = oPart.HybridShapeFactory
    
    Dim hybridShapeSweepCircle1 As HybridShapeSweepCircle
    Set hybridShapeSweepCircle1 = hybridShapeFactory1.AddNewSweepCircle(Ref)
    
    With hybridShapeSweepCircle1
        .Mode = 6
        .SmoothActivity = False
        .GuideDeviationActivity = False
        .SetRadius 1, 2#
        .SetbackValue = 0.02
        .FillTwistedAreas = 1
        .C0VerticesMode = True
    End With
    
    HBody.AppendHybridShape hybridShapeSweepCircle1
    oPart.Update
End Sub

'SelectElement用BrapName取得
Private Function GetBrepName(MyBRepName As String) As String
    MyBRepName = Replace(MyBRepName, "Selection_", "")
    MyBRepName = Left(MyBRepName, InStrRev(MyBRepName, "));"))
    MyBRepName = MyBRepName + ");WithPermanentBody;WithoutBuildError;WithSelectingFeatureSupport;MFBRepVersion_CXR15)"
    GetBrepName = MyBRepName
End Function