美文网首页狮猿社CATIA
CATIA VBA AddNewLineNormal

CATIA VBA AddNewLineNormal

作者: 锦囊喵 | 来源:发表于2020-02-03 14:38 被阅读0次

    原文链接
    最终代码

    Sub CATMain()
        Dim col1 As Collection
        Set col1 = New Collection
        Dim arr1(1000) As Variant
        Dim arr2(2) As Variant
        Dim partDocument1 As PartDocument
        Set partDocument1 = CATIA.ActiveDocument 
        Dim part1 As part
        Set part1 = partDocument1.part
        Dim objSPAWkb As Workbench
        Set objSPAWkb = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench") 
        Dim hybridBodies1 As HybridBodies
        Set hybridBodies1 = part1.HybridBodies 
        Dim hybridBody1 As HybridBodySet 
        hybridBody1 = hybridBodies1.Item("Imported Points")Dim hybridBody2 As HybridBodySet 
        hybridBody2 = hybridBodies1.Item("laser_tracker")Dim hybridShapes1 As HybridShapes
        Set hybridShapes1 = hybridBody1.HybridShapesDim hybridShapes2 As HybridShapesSet 
        hybridShapes2 = hybridBody2.HybridShapesDim hybridShapeAssemble2 As HybridShapeAssembleSet 
        hybridShapeAssemble2 = hybridShapes2.Item("Join.1")Dim reference2 As Reference
        Set reference2 = part1.CreateReferenceFromObject(hybridShapeAssemble2)Set objMeasurable2 = objSPAWkb.GetMeasurable(reference2)
        Dim f As HybridShapeFactorySet 
        f = part1.HybridShapeFactory h = 0
        For i = 1 To hybridShapes1.Count      
            If InStr(hybridShapes1.Item(i).Name, "Point.") Then
                Set objHShape1 = hybridShapes1.Item(i)
                Set reference1 = part1.CreateReferenceFromObject(objHShape1)
                Set l = f.AddNewLineNormal(reference2, reference1, 0, 100, True)        hybridBody1.AppendHybridShape l
                l.Compute
                Dim direction(2)
                l.GetDirection direction
                col1.Add direction
                For k = 0 To 2
                    arr2(k) = direction(k)
                Next
                arr1(h) = arr2
                h = h + 1
            End If
        Next
    End Sub
    

    另一个片段

    Dim partDocument1 As PartDocument
    Set partDocument1 = CATIA.ActiveDocument
     
    Dim part1 As Part
    Set part1 = partDocument1.Part
     
    Dim bodies1 As Bodies
    Set bodies1 = part1.Bodies
     
    Dim body1 As Body
    Set body1 = bodies1.Item("PartBody")
     
    Dim shapes1 As Shapes
    Set shapes1 = body1.Shapes
     
    Dim pad1 As Pad
    Set pad1 = shapes1.Item("Pad.2")
     
    Dim sel As Selection
    Set sel = partDocument1.Selection
     
    sel.Clear
    sel.Add pad1
    sel.Search "Topology.Face;sel"
     
    For i = 1 To sel.Count
       Debug.Print sel.Item(i).Reference.Name
    Next
    

    中间代码

    Sub normal_lines()
    Dim partDocument1 As PartDocument
    Set partDocument1 = CATIA.ActiveDocument 
    Dim part1 As part
    Set part1 = partDocument1.part
    
    Dim objSPAWkb As WorkbenchSet
    objSPAWkb = CATIA.ActiveDocument.GetWorkbench("SPAWorkbench") 
    Dim hybridBodies1 As HybridBodies
    Set hybridBodies1 = part1.HybridBodies 
    Dim hybridBody1 As HybridBody
    Set hybridBody1 = hybridBodies1.Item("KC_Points")
    
    Dim hybridShapes1 As HybridShapes
    Set hybridShapes1 = hybridBody1.HybridShapes
    Dim f As HybridShapeFactory
    Set f = part1.HybridShapeFactory
    
    Dim bodies1 As Bodies
    Set bodies1 = part1.Bodies
    For i = 1 To hybridShapes1.Count
        
    If InStr(hybridShapes1.Item(i).Name, "Point.") Then 
                 
    Set objHShape1 = hybridShapes1.Item(i)       
    Set reference1 = part1.CreateReferenceFromObject(objHShape1) 
                 
    For j = 2 To part1.Bodies.Count 
                       
    Dim body1 As Body           
    Set body1 = bodies1.Item(j) 
                         
    Dim shapes1 As Shapes           
    Set shapes1 = body1.Shapes   
                       
    Dim solid1 As Solid           
    Set solid1 = shapes1.Item(1)     
                     
    Dim reference2 As Reference           
    Set reference2 = part1.CreateReferenceFromObject(solid1) 
             
    Set objMeasurable2 = objSPAWkb.GetMeasurable(reference2)
    Dim distance As Double           
    distance = objMeasurable2.GetMinimumDistance(reference1)
    
    If distance = 0 Then
                               
    Set l = f.AddNewLineNormal(reference2, reference1, 0, 1, True)               
    hybridBody1.AppendHybridShape l               
    l.Compute 
                                 
    Dim direction(2)               
    l.GetDirection direction   
                           
    End If     
                 
    Next 
         
    End If
       
    Next
     
    End Sub
    

    最初代码

    Sub normal_lines()
     
    Dim partDocument1 As PartDocument
    Set partDocument1 = CATIA.ActiveDocument
     
    Dim part1 As Part
    Set part1 = partDocument1.Part
     
    Dim hybridBodies1 As HybridBodies
    Set hybridBodies1 = part1.HybridBodies
     
    Dim hybridBody1 As HybridBody
    Set hybridBody1 = hybridBodies1.Item("Geometrical Set.1")
     
    Dim hybridShapes1 As HybridShapes
    Set hybridShapes1 = hybridBody1.HybridShapes
     
    Dim hybridShapeExtrude1 As HybridShapeExtrude
    Set hybridShapeExtrude1 = hybridShapes1.Item("Extrude.1")
     
    Dim f As HybridShapeFactory
    Set f = part1.HybridShapeFactory
     
    For i = 1 To hybridShapes1.Count
       If InStr(hybridShapes1.Item(i).Name, "Point.") Then
    
       Set l = f.AddNewLineNormal(part1.CreateReferenceFromObject(hybridShapeExtrude1), part1.CreateReferenceFromObject(hybridShapes1.Item(i)), 0, 1, True)
    hybridBody1.AppendHybridShape l
       l.Compute
       End If
    Next
     
    End Sub
    

    相关文章

      网友评论

        本文标题:CATIA VBA AddNewLineNormal

        本文链接:https://www.haomeiwen.com/subject/qtuhxhtx.html