Message 1 of 6
GetWeldmentState Error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
