Get Contour of WeldBead

By Xiaodong Liang

The WeldBead object provides the two faces which generates the weld, and also provides the faces that define the geometric result of the weld bead: WeldBead.BeadFaces

The following is a small demo that get the faces, add them as a client graphics.

Public Sub test()
   
    ‘get document and definition
    Dim oDoc As AssemblyDocument
    Set oDoc = ThisApplication.ActiveDocument
 
    Dim oCompDef As AssemblyComponentDefinition
    Set oCompDef = oDoc.ComponentDefinition
   
    ‘if this is a weld document
    If oCompDef.Type = kWeldmentComponentDefinitionObject Then
        Dim wcd As WeldmentComponentDefinition
        Set wcd = oCompDef
    Else
        Exit Sub
    End If
  
    ‘ get one weld bead
    Dim oWB As WeldBead
    Set oWB = wcd.Welds.WeldBeads(1)
 
    On Error Resume Next
    Dim oClientGraphics As ClientGraphics
    Set oClientGraphics = oCompDef.ClientGraphicsCollection.Item("weldbead")
    If Err.Number = 0 Then
        ‘delete the older client graphics, if any
        On Error GoTo 0
        oClientGraphics.Delete
        ThisApplication.ActiveView.Update
    End If
  
    Err.Clear
    On Error GoTo 0
  
   ‘ create a client graphics
    Set oClientGraphics = oCompDef.ClientGraphicsCollection.Add("weldbead")
  
    ‘add graphics node
    Dim oSurfacesNode As GraphicsNode
    Set oSurfacesNode = oClientGraphics.AddNode(1)
   
    ‘add the face of WeldBead.BeadFaces
    Dim oSurfaceGraphics As SurfaceGraphics
    Dim oEachWeldFace As Face
    For Each oEachWeldFace In oWB.BeadFaces
      Set oSurfaceGraphics = oSurfacesNode.AddSurfaceGraphics(oEachWeldFace)
    Next
   
    ‘set graphics’ color. assume “Magenta” exists in the document
    oSurfacesNode.Appearance = oDoc.Assets("Magenta")
   
    ‘transform the client graphics to a location
     Dim oTransGeom As TransientGeometry
    Set oTransGeom = ThisApplication.TransientGeometry

    Dim oV As Vector
    Set oV = oTransGeom.CreateVector(10, 10, 10)

    Dim oM As Matrix
    Set oM = oTransGeom.CreateMatrix()
    Call oM.SetTranslation(oV)

    oSurfacesNode.Transformation = oM
   
    ‘update the view
    ThisApplication.ActiveView.Update

End Sub

image


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading