Weld assembly with attributes

Weld assembly with attributes

vanwees
Enthusiast Enthusiast
189 Views
2 Replies
Message 1 of 3

Weld assembly with attributes

vanwees
Enthusiast
Enthusiast

Hi,

 

I am working on automating some drawings. For a weld assembly, I use machining to adjust certain features because my step always varies. Using nifty attributes, I created two attributes: one for left (left = l) and one for right (right = r). I can find these when I search for the attributes in the weld assembly.

However, when I try to find these attributes in the .dwg, I can't locate them, so I'm unable to add dimensions. Does anyone have a solution for creating a drawing with a weld assembly, or should I take a different approach? If it’s a part, I can use the “assign entity name” option.

 

This is the code I want to use bur everytime i got the message "Not all faces found!" , I found it through the following link:

https://www.youtube.com/watch?v=bcOvYc6rNUk

 

 

Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet

Dim oView As DrawingView
oView = oSheet.DrawingViews.Item(1)

' Reference to the assembly in the view
Dim oAssembly As AssemblyDocument
oAssembly = oView.ReferencedDocumentDescriptor.ReferencedDocument

' Reference to the GeneralDimensions on the drawing
Dim oGeneralDims As GeneralDimensions
oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions

' Declare Face1 and Face2 outside the loop
Dim Face1 As Face = Nothing
Dim Face2 As Face = Nothing

' Iterate over all referenced documents within the assembly
Dim oModelDoc As Document
Dim oObjs As ObjectsEnumerator

For i = 1 To oAssembly.ReferencedDocuments.Count
    oModelDoc = oAssembly.ReferencedDocuments.Item(i)

    ' Find Face1 and Face2 via attributes
    oObjs = oModelDoc.AttributeManager.FindObjects("*", "*", "L")
    If oObjs.Count > 0 Then Face1 = TryCast(oObjs.Item(1), Face)

    oObjs = oModelDoc.AttributeManager.FindObjects("*", "*", "R")
    If oObjs.Count > 0 Then Face2 = TryCast(oObjs.Item(1), Face)

    ' Check if both Faces are found
    If Face1 Is Nothing Or Face2 Is Nothing Then
        MessageBox.Show("Not all faces found!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        Return
    End If
Next

' Iterate over the components in the assembly
Dim oCompOcc As ComponentOccurrence
Dim oOccFace1Proxy As FaceProxy
Dim oOccFace2Proxy As FaceProxy

For Each oCompOcc In oAssembly.ComponentDefinition.Occurrences
    ' Create GeometryProxies for the Faces
    oCompOcc.CreateGeometryProxy(Face1, oOccFace1Proxy)
    oCompOcc.CreateGeometryProxy(Face2, oOccFace2Proxy)
    
    ' Get the corresponding drawing curves
    Dim oDrawCurves1 As DrawingCurve
    Dim oDrawCurves2 As DrawingCurve

    oDrawCurves1 = oView.DrawingCurves(oOccFace1Proxy).Item(1)
    oDrawCurves2 = oView.DrawingCurves(oOccFace2Proxy).Item(1)
    
    ' Create GeometryIntents for the dimension
    Dim GI1 As GeometryIntent
    Dim GI2 As GeometryIntent

    GI1 = oSheet.CreateGeometryIntent(oDrawCurves1)
    GI2 = oSheet.CreateGeometryIntent(oDrawCurves2)
    
    ' Determine the position for the dimension
    Dim TextPoint As Point2d
    Dim Xpos As Double
    Dim Ypos As Double

    Xpos = 10
    Ypos = oView.Top + 1

    TextPoint = ThisApplication.TransientGeometry.CreatePoint2d(Xpos, Ypos)

    ' Add the dimension
    Dim oDim1 As GeneralDimension
    oDim1 = oGeneralDims.AddLinear(TextPoint, GI1, GI2)
Next

 

0 Likes
190 Views
2 Replies
Replies (2)
Message 2 of 3

petr.meduna
Advocate
Advocate

Hi,

try to use oAssembly.AllReferencedDocuments instead of oAssembly.ReferencedDocuments.

0 Likes
Message 3 of 3

vanwees
Enthusiast
Enthusiast

Thanks for the reply.

 

I tried using the AllReferencedDocuments, but it doesn't work. It works in a normal assembly, but when I use a weldment, I can't find the attributes anymore.

When I place the same part in a weld assembly, I get the following error message. I have the impression that you need to approach a weldment differently

 

I get the following error message at this line, which I don’t get in a normal assembly

  oCompOcc.CreateGeometryProxy(Face1, oOccFace1Proxy)

Error on line 50 in rule: Dimensions_Face, in document: E0280210.dwg

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))

 

Does somebody knows how to solve this? 

 

 

0 Likes