Can't figure out why attributes won't save or properly update
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've created something similar to the attribute helper that's more streamlined to my custom needs. The problem I'm running into is that the Attributes only sort of update and usually don't stick with the part after they theoretically have been saved. Sometimes yes mostly not though and I don't know why.
I've added a zip file of an example. Let me know if there's any trouble loading the *.frm or *.frx from the zip file. The only thing tricky to running it should be that each item selected currently needs to have a custom iproperty "Model_Number" or there may be an error.
The userform acts as a gui to add attributes. If I have a group of items in an assy selected I should be able to add attributes and read the current attributes. I have buttons "Update Selection" which supposedly update the value selected (combo box) or inputted (text box) to all the items selected. I have an update button to update all the attributes just to the current item. "Update All" updates what's currently shown to all items selected. Next and Back load the next or last item in a set. This (in theory) allows me to select many items and quickly change the "Group" attribute from "Furniture" to "Electrical" etc.
Any feedback or suggestions would be greatly appreciated even if they don't directly solve the problem.
Here's the code for the form just in case it's needed.
Dim ocSelected As ObjectCollection
Dim docCurrent As Document
Dim coCurrent As ComponentOccurrence
Dim lngCurrentID As Long
Private Sub UpdateSelection(strAttbName As String, strAttbVal As String)
Dim coOcc As ComponentOccurrence
For Each coOcc In ocSelected
Call UpdateAttribute(coOcc, strAttbName, strAttbVal)
Next coOcc
End Sub
Private Sub CheckIfEndOrBeginOcc()
If lngCurrentID = 1 Then
cmdbttnBack.Enabled = False
Else
cmdbttnBack.Enabled = True
End If
If lngCurrentID = ocSelected.Count Then
cmdbttnNext.Enabled = False
Else
cmdbttnNext.Enabled = True
End If
End Sub
Private Sub GetSelectedObjects(ocSelectedOccs As ObjectCollection)
Dim i As Long
Dim coDoc As ComponentOccurrence
For i = 1 To docCurrent.SelectSet.Count
If docCurrent.SelectSet.Item(i).Type = kComponentOccurrenceObject Then
ocSelectedOccs.Add docCurrent.SelectSet.Item(i)
End If
Next i
End Sub
Private Function TestIfNoneSelected() As Boolean
If docCurrent.SelectSet.Count < 1 Then
TestIfNoneSelected = True
Else
TestIfNoneSelected = False
End If
End Function
Private Sub PopulateData()
Dim attbstsTemp As AttributeSets
Set attbstsTemp = coCurrent.AttributeSets
Dim attbstTemp As AttributeSet
If attbstsTemp.NameIsUsed("Full") Then
Set attbstTemp = attbstsTemp.Item("Full")
Dim attbTemp As Inventor.Attribute
For Each attbTemp In attbstTemp
If attbTemp.Name = ("Group") Then
cmbbxGroup.Value = attbTemp.Value
ElseIf attbTemp.Name = ("Note1") Then
txtbxNote1.Value = attbTemp.Value
ElseIf attbTemp.Name = ("Note2") Then
txtbxNote2.Value = attbTemp.Value
End If
Next attbTemp
End If
Dim docLoaded As Document
Set docLoaded = coCurrent.Definition.Document
Dim propstsLoaded As PropertySets
Set propstsLoaded = docLoaded.PropertySets
Dim propstLoaded As PropertySet
Set propstLoaded = propstsLoaded.Item("User Defined Properties")
Dim propLoaded As Property
Set propLoaded = propstLoaded.Item("Model_Number")
lblModelNum.Caption = propLoaded.Value
End Sub
Private Sub UpdateOcc()
Dim attbstsTemp As AttributeSets
Set attbstsTemp = coCurrent.AttributeSets
Dim attbstTemp As AttributeSet
Set attbstTemp = attbstsTemp.Item("Full")
Dim attbTemp As Inventor.Attribute
For Each attbTemp In attbstTemp
If attbTemp.Name = ("Group") Then
attbTemp.Value = cmbbxGroup.Text
ElseIf attbTemp.Name = ("Note1") Then
attbTemp.Value = txtbxNote1.Value
ElseIf attbTemp.Name = ("Note2") Then
attbTemp.Value = txtbxNote2.Value
End If
Next attbTemp
End Sub
Private Sub UpdateAttribute(coComponent As ComponentOccurrence, _
strAttbName As String, strAttb As String)
Dim attstsSets As AttributeSets
Set attstsSets = coComponent.AttributeSets
Dim attstSet As AttributeSet
Dim attbAtt As Inventor.Attribute
Dim strSetName As String
strSetName = "Full"
If attstsSets.NameIsUsed(strSetName) = True Then
Set attstSet = attstsSets.Item(strSetName)
Else
attstsSets.Add (strSetName)
Set attstSet = attstsSets.Item(strSetName)
End If
If attstSet.NameIsUsed(strAttbName) = True Then
attstSet.Item(strAttbName).Value = strAttb
Else
Set attbAtt = attstSet.Add(strAttbName, kStringType, strAttb)
End If
End Sub
Private Sub cmdbttnBack_Click()
lngCurrentID = lngCurrentID - 1
Set coCurrent = ocSelected.Item(lngCurrentID)
Call CheckIfEndOrBeginOcc
Call PopulateData
End Sub
Private Sub cmdbttnNext_Click()
lngCurrentID = lngCurrentID + 1
Set coCurrent = ocSelected.Item(lngCurrentID)
Call CheckIfEndOrBeginOcc
Call PopulateData
End Sub
Private Sub cmdbttnGroupUpdateSel_Click()
Call UpdateSelection("Group", cmbbxGroup.Text)
End Sub
Private Sub cmdbttnNote1UpdateSel_Click()
Call UpdateSelection("Note1", txtbxNote1.Value)
End Sub
Private Sub cmdbttnNote2UpdateSel_Click()
Call UpdateSelection("Note2", txtbxNote2.Value)
End Sub
Private Sub cmdbttnUpdate_Click()
Call UpdateOcc
End Sub
Private Sub cmdbttnUpdateAll_Click()
Dim coTemp As ComponentOccurrence
For Each coTemp In ocSelected
Call UpdateOcc
Next coTemp
End Sub
Private Sub UserForm_Initialize()
With cmbbxGroup
.AddItem ("Furniture")
.AddItem ("Audio")
.AddItem ("Electrical")
.AddItem ("Paint")
End With
Set ocSelected = ThisApplication.TransientObjects.CreateObjectCollection
Set docCurrent = ThisApplication.ActiveDocument
If TestIfNoneSelected() Then
MsgBox ("Nothing Selected")
'unload me
'exit sub
Else
Call GetSelectedObjects(ocSelected)
End If
lngCurrentID = 1
Set coCurrent = ocSelected.Item(lngCurrentID)
Call CheckIfEndOrBeginOcc
Call PopulateData
End Sub