List handling...

List handling...

Anonymous
Not applicable
194 Views
4 Replies
Message 1 of 5

List handling...

Anonymous
Not applicable
Hi all,
Working with an example, (link posted by Kent a while back), the Sheetmetal.zip Autorun from cbliss site. Q: is, Is how to provide a default selection (the currently active style) in the list box so the user could just hit enter to accept the default.
Any examples anyone?

TIA,
DWP
0 Likes
195 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
The code below is from a example in help. I would suspect that once you get the name of the active style, you could iterate through the list of styles in your listbox or combo until you find a matching one, and set it as the active row in the list. Public Sub SheetMetalStyleDisplay() ' Set a reference to the sheet metal document. ' This assumes a part document is active. Dim oPartDoc As PartDocument Set oPartDoc = ThisApplication.ActiveDocument ' Make sure the document is a sheet metal document. If oPartDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then MsgBox "A sheet metal document must be open." Exit Sub End If ' Get the sheet metal component definition. Because this is a part document whose ' sub type is sheet metal, the document will return a SheetMetalComponentDefinition ' instead of a PartComponentDefinition. Dim oSheetMetalCompDef As SheetMetalComponentDefinition Set oSheetMetalCompDef = oPartDoc.ComponentDefinition ' Iterate through the sheet metal styles. Dim oStyle As SheetMetalStyle For Each oStyle In oSheetMetalCompDef.SheetMetalStyles ' Display information about the style. If oStyle Is oSheetMetalCompDef.ActiveSheetMetalStyle Then Debug.Print "** Active Method **" End If Debug.Print oStyle.Name -- Kent Keller Autodesk Discussion Forum Facilitator "DWP" wrote in message news:19374.1096991045514.JavaMail.jive@jiveforum1.autodesk.com... > Hi all, > Working with an example, (link posted by Kent a while back), the Sheetmetal.zip Autorun from cbliss site. Q: is, Is how to provide a default selection (the currently active style) in the list box so the user could just hit enter to accept the default. > Any examples anyone? > > TIA, > DWP
0 Likes
Message 3 of 5

Anonymous
Not applicable
Thanks Kent,
I did find that in the help the other day. Admittedly, I'm hacking at this as a beginner, but trying to learn something.. LOL. Can anyone tell me if I'm on the right track with the code below? I get a compile error when trying to run it. (on the "set cnt =" line).


Option Explicit
Dim oDoc As PartDocument
Function CurrentsStyle() As String
Set CurrentsStyle = oDoc.ComponentDefinition.ActiveSheetMetalStyle.Name
End Function
Private Sub cbnCancel_Click()
End
End Sub

Private Sub SetStyle_Click()
'If lbxSStyles.Text = "" Then Exit Sub
Dim Index
Index = lbxSStyles.ListIndex + 1
oDoc.ComponentDefinition.SheetMetalStyles(Index).Activate
oDoc.Update
Set oDoc = Nothing
End

End Sub

Private Sub UserForm_Initialize()
' Dim sStyles As SheetMetalStyles
Dim sStyle As SheetMetalStyle
Dim cnt As Single
Set cnt = 0
'Set oDoc = ThisDocument 'ThisApplication.ActiveDocument
For Each sStyle In oDoc.ComponentDefinition.SheetMetalStyles
lbxSStyles.AddItem sStyle.Name
Next
For Each sStyle In oDoc.ComponentDefinition.SheetMetalStyles
If sStyle.Name = CurrentsStyle Then lbxSStyles.Index = cnt Else: Set cnt = 1 + cnt
Next
End Sub

(credit to Cory McConnel for the original code)

Thanks again,
DWP
0 Likes
Message 4 of 5

Anonymous
Not applicable
Hello, Set cnt = 0... the "Set" keyword is for objects only... cnt = 0 will work :-) Scott's rule of thumb "You'll probably need to use the Set keyword if it's not one of the following, Integer, Long(Long Integer), Single(Single precision floating point), Double(Double precision floating point), Currency, String, Boolean, Date and Variant's are the grey area as far as I'm concerned as the hold all sorts. Have a look for Data types in VBA help. Scott "DWP" wrote in message news:30026019.1097005813421.JavaMail.jive@jiveforum2.autodesk.com... > Thanks Kent, > I did find that in the help the other day. Admittedly, I'm hacking at this as a beginner, but trying to learn something.. LOL. Can anyone tell me if I'm on the right track with the code below? I get a compile error when trying to run it. (on the "set cnt =" line). > > > Option Explicit > Dim oDoc As PartDocument > Function CurrentsStyle() As String > Set CurrentsStyle = oDoc.ComponentDefinition.ActiveSheetMetalStyle.Name > End Function > Private Sub cbnCancel_Click() > End > End Sub > > Private Sub SetStyle_Click() > 'If lbxSStyles.Text = "" Then Exit Sub > Dim Index > Index = lbxSStyles.ListIndex + 1 > oDoc.ComponentDefinition.SheetMetalStyles(Index).Activate > oDoc.Update > Set oDoc = Nothing > End > > End Sub > > Private Sub UserForm_Initialize() > ' Dim sStyles As SheetMetalStyles > Dim sStyle As SheetMetalStyle > Dim cnt As Single > Set cnt = 0 > 'Set oDoc = ThisDocument 'ThisApplication.ActiveDocument > For Each sStyle In oDoc.ComponentDefinition.SheetMetalStyles > lbxSStyles.AddItem sStyle.Name > Next > For Each sStyle In oDoc.ComponentDefinition.SheetMetalStyles > If sStyle.Name = CurrentsStyle Then lbxSStyles.Index = cnt Else: Set cnt = 1 + cnt > Next > End Sub > > (credit to Cory McConnel for the original code) > > Thanks again, > DWP
0 Likes
Message 5 of 5

Anonymous
Not applicable
try something like this Private Sub UserForm_Initialize() Dim sStyles As SheetMetalStyles Dim sStyle As SheetMetalStyle Dim cnt As Integer Set oDoc = ThisApplication.ActiveDocument For Each sStyle In oDoc.ComponentDefinition.SheetMetalStyles lbxSStyles.AddItem sStyle.Name If sStyle Is oDoc.ComponentDefinition.ActiveSheetMetalStyle Then cnt = lbxSStyles.ListCount - 1 End If Next lbxSStyles.ListIndex = cnt End Sub -- Kent Keller Autodesk Discussion Forum Facilitator
0 Likes