Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
mostafamahmoudseddek94
1630 Views, 7 Replies

Adding a Balloon using VBA

Hi, 

I have an assembly with an attribute as shown 

mostafamahmoudseddek94_0-1646648411025.png

 

 I want to add a balloon (No. 20) on a specific view  ( detail E) automatically as shown 

mostafamahmoudseddek94_1-1646648527975.png

I am developing a code in VBA but got stuck when I try to execute the following line 

 Set oViewCurves = oView.DrawingCurves(oFaceProxy)

the error message that appears says Method 'DrawingCurves' of object "DetailDrawingView" failed

mostafamahmoudseddek94_2-1646648710246.png

Here is my code to suggest for me an amendment 

Thanks

Sub Balloons()

'Reference the file that's open
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument

'Reference the active Sheet
Dim oSheet As Sheet
Set oSheet = oDrawDoc.Sheets.Item(1)

'Reference the View we want
For i = 1 To oSheet.DrawingViews.Count
    If oSheet.DrawingViews.Item(i).Name = "E" Then
        Dim oView As DrawingView
        Set oView = oSheet.DrawingViews.Item(i)
    End If
Next

'Reference the Asembly Model on that Sheet
Dim oAssemblyDoc As Document
Set oAssemblyDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument

Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry

'reference the assigned attribute on the Assembly Model
Dim oMainObjs As ObjectCollection
Set oMainObjs = oAssemblyDoc.AttributeManager.FindObjects("Balloon", "W01_Outer")

'reference to the Occerrence of tha Assembly Model
Dim oOcc As ComponentOccurrence
Set oOcc = oAssemblyDoc.ComponentDefinition.Occurrences.ItemByName(oMainObjs.Item(1).ContainingOccurrence.Name)

'reference to the Wanted Face
Dim oFace As Face
Set oFace = oMainObjs.Item(1)

'Promote to Proxy Face
Dim oFaceProxy As Inventor.FaceProxy
Call oOcc.CreateGeometryProxy(oFace, oFaceProxy)

'Promote to an DrawingCurve on the View
Dim oCurves As DrawingCurve
Set oViewCurves = oView.DrawingCurves(oFaceProxy)
Set oCurves = oViewCurves.Item(1)

End Sub