GetWeldmentState Error

GetWeldmentState Error

Snivek
Enthusiast Enthusiast
1,199 Views
5 Replies
Message 1 of 6

GetWeldmentState Error

Snivek
Enthusiast
Enthusiast

I have been struggling with the code below which ran flawlessly at one time. The code is for looking through all the views on each sheet and if the view is a preparation view and is also a base view, then it adds a balloon to the view, renames the view based on the balloon and turns the view label on. It runs great until someone changes the item number in the parts list and saves the change back to the BOM. If they just change the item number without saving the changes back to the BOM, it continues to run fine. I have tried everything I can think of to make sure the model and drawing are up to date before labeling but without success. It errors at GetWeldmentState. Error attached.

 

Inventor Pro 2018.2

Visual Studio 2015

    Public Sub labeltext(ThisApplication As Inventor.Application)
        Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument
        Dim weld As WeldmentStateEnum = Nothing
        Dim comp As Object = Nothing
        Dim oView As DrawingView
        Dim bal As Balloon
        Dim currentsheet As Sheet = oDrawDoc.ActiveSheet
        Dim oSheet As Sheet

        Try
            For Each oSheet In oDrawDoc.Sheets
                For Each oView In oSheet.DrawingViews
                    Dim oModel As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
                    If oModel.SubType = "{28EC8354-9024-440F-A8A2-0E0E55D635B0}" Then 'Weldment
                        If oModel.Dirty Then
                            MsgBox("Model is dirty!")
                            Try
                                Dim conn As VDF.Vault.Currency.Connections.Connection = makeconnection()
                                Dim vm As VDF.Vault.Currency.Entities.FileIteration = Nothing
                                vm = getFileIteration(oModel.DisplayName, conn)
                                If Not vm.IsCheckedOutToCurrentUser Then
                                    Dim fpa As String = oModel.FullFileName
                                    fpa = fpa.Substring(0, fpa.LastIndexOf("\"))
                                    checkout(oModel.DisplayName, oModel.FullFileName, fpa, conn)
                                End If
                            Catch
                            End Try
                            oModel.Rebuild()
                            oModel.Update()
                            oModel.Save()
                        End If
                        oDrawDoc.Update()
                        oDrawDoc.Save()
                        comp = CType(oModel, Object)
                        If oView.DrawingCurves.Count > 0 Then
                            oView.GetWeldmentState(weld, comp)
                        Else
                            oView.Delete()
                            GoTo 100
                        End If
                        If oView.ViewType = DrawingViewTypeEnum.kStandardDrawingViewType And weld = WeldmentStateEnum.kPreparationsWeldmentState Then
                            If Not oView.Name.StartsWith("DETAIL - ITEM") Then
                                Dim oDC As DrawingCurve = oView.DrawingCurves.Item(1)
                                Dim oLP As ObjectCollection = g_inventorApplication.TransientObjects.CreateObjectCollection
                                Dim oGI As GeometryIntent = oSheet.CreateGeometryIntent(oDC)
                                oLP.Add(oGI)
                                bal = oSheet.Balloons.Add(oLP)
                            End If
                            For Each bal In oSheet.Balloons
                                If bal.ParentView.Name = oView.Name Then
                                    Dim itm As String = bal.BalloonValueSets.Item(1).ItemNumber.ToString
                                    Dim qty As String = bal.BalloonValueSets.Item(1).ReferencedRow.BOMRow.ItemQuantity.ToString
                                    If Not oView.Name = ("DETAIL - ITEM " & itm & vbLf & qty & " REQUIRED") Then
                                        oView.Name = ("DETAIL - ITEM " & itm & vbLf & qty & " REQUIRED")
                                        oView.ShowLabel = True
                                    End If
                                    itm = Nothing
                                    qty = Nothing
                                End If
                            Next
                        End If
                    End If
100:
                    oDrawDoc.Update()
                    oDrawDoc.Save()
                    comp = Nothing
                    weld = Nothing

                Next
            Next
        Catch ex As Exception
            MessageBox.Show(ex.ToString, "Error", MessageBoxButtons.OK)
        End Try

    End Sub
0 Likes
1,200 Views
5 Replies
Replies (5)
Message 2 of 6

Snivek
Enthusiast
Enthusiast

A few more details and findings. First, I noticed I had a line that should have been there comp=Ctype(oModel, Object). I removed that line with no change. Second, I tried to comment out the portion to check if the model is dirty and if so, update and save. When debugging, I get the standard dialog that these files need saved. If I click yes to the drawing and no to the model, it asks me again, to which I again so no to the model. Then the rest of the code runs fine. If I click yes to the model, then I get the error again at the getweldmentstate line. If I close and open the drawing back up, I can run it again with no error. This leads me to believe that changing the item number and saving the changes to the BOM is somehow effecting the component occurrence but I don't see how.

I also forgot to mention I am using Windows 10. But I have many other users using Windows 7 and are getting the same error.

0 Likes
Message 3 of 6

chandra.shekar.g
Autodesk Support
Autodesk Support

@Snivek,

 

Can you please provide sample and assembly file to reproduce error? Please make sure that files are non confidential.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 6

Snivek
Enthusiast
Enthusiast

@chandra.shekar.g,

I have attached some files. Again the code is visual studio and produced as an add-in. The code runs on a button click. Thanks for looking at it. I have been scratching my head for days as to why it would error.

0 Likes
Message 5 of 6

Snivek
Enthusiast
Enthusiast

@chandra.shekar.g,

Any luck? Do you need anything else? I have not been able to make any progress on this.

 

Thank you.

0 Likes
Message 6 of 6

chandra.shekar.g
Autodesk Support
Autodesk Support

@Snivek,

 

In Drawing document, GetWeldmentState API fails on changing and saving Model document. This behaviour is reproducible and change request (INVGEN - 17324 - GetWeldmentState API fails on changing and saving Model document in Drawing document) is created with engineering team for the same.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes