Select an occurence (user pick)

Select an occurence (user pick)

Anonymous
Not applicable
326 Views
3 Replies
Message 1 of 4

Select an occurence (user pick)

Anonymous
Not applicable
I know that this is an extreme newbie type of question, and I'm embarrassed to even ask. I am attempting to create a little VBA macro that will flush up the origin planes of two components that I select. I am a total "hack" at coding with VBA and am almost totally lost. Cheating from the sample code, I am able to flush up two components in the assebmly with no problem. It gets occurence.item(1) and occurence.item(2) and does it's thing. I want to be able to select which occurences in the assembly, not just get item(1) and item(2) in the assembly. You know, selection sets. That's where I'm lost. Any help would be appriciated.
0 Likes
327 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
The SelectSet is a simple and easy method of selection. The primary
downside is that it forces you to use an Object-Action type of workflow.
That is the end-user first selects the objects and then performs the action.
For this to the work the end-user needs to know what the action is expecting
so they understand what needs to be selected. Here's some example code that
demonstrates getting two selected occurrences. It provides some feedback to
the end-user to help them to learn what is expected.

Public Sub SelectSetSample()
' Make sure an assembly document is active.
If ThisApplication.ActiveDocumentType <> kAssemblyDocumentObject Then
MsgBox "An assembly must be active."
Exit Sub
End If

Dim oAsmDoc As AssemblyDocument
Set oAsmDoc = ThisApplication.ActiveDocument

Dim oSelectSet As SelectSet
Set oSelectSet = oAsmDoc.SelectSet

' Check that there are two occurrences selected.
If oSelectSet.Count <> 2 Then
MsgBox "Two occurrences must be selected."
Exit Sub
End If

If Not TypeOf oSelectSet.Item(1) Is ComponentOccurrence Or _
Not TypeOf oSelectSet.Item(2) Is ComponentOccurrence Then
MsgBox "Tow occurrences must be selected."
Exit Sub
End If

Dim oOcc1 As ComponentOccurrence
Dim oOcc2 As ComponentOccurrence
Set oOcc1 = oSelectSet.Item(1)
Set oOcc2 = oSelectSet.Item(2)

MsgBox "Selected Occurrences: " & oOcc1.Name & ", " & oOcc2.Name
End Sub

--
Brian Ekins
Autodesk Inventor API
0 Likes
Message 3 of 4

Anonymous
Not applicable
At least the user would be clued in as to what they need to do to make it work. Thanls for the reply!
0 Likes
Message 4 of 4

Anonymous
Not applicable
BTW, I did get this routine to work. I like it a lot! For skeletal modeling, it will help out greatly!
I don't like it when skeletal modeling, people ground everything. It's just ugly. Maybe I'm stubborn. This macro fully constrains one object to another based on it's location on the skeleton. No need to ground. So, you bring in the base skeleton (for ease of editing), bring in the components that were derived from the skeleton, select the skeleton and a component, and hit the button. It pops right into place. Yeah, there would be parts that would take conventional constraining, but so what, right?
Not too bad for a non-programming fool like myself.
Thanks again for your help!
0 Likes