User interaction in VBA

User interaction in VBA

Anonymous
Not applicable
1,039 Views
4 Replies
Message 1 of 5

User interaction in VBA

Anonymous
Not applicable

Hi, 

 

I have an assembly file with parts assembled, and I want the user to move and position the assembled part into a position as they desire, and then run VBA to extract coordinates information to do further calculation. 

 

So, what I want to do is creat a VBA code that does the following in sequence

1. VBA runs code to assemble the parts (I can do this)

2. go to the autodesk interface and allow user to manipulate the part

3. when user presses a key (e.g. "enter", "space"), the control returns to VBA

4. VBA run some code to extract the coordinates and do some calculations (I can do this too)

 

Can anyone help me with step 2 and 3? I'm hoping there is something like an input box that waits for the user to click ok, before continuing to run the rest of the coding. But I realise that the input boxes and message boxes do not allow users to work on the model in the background. Since I need users to move/rotate the part to the desired position, I can't simply use input and message boxes. 

 

Thanks,

Ying Ying

0 Likes
1,040 Views
4 Replies
Replies (4)
Message 2 of 5

Ralf_Krieg
Advisor
Advisor

Hello

 

Create a User form and display it modeless. So user can interact in Inventor and if he presses the OK-Button (or whatever) in your form, your sceond code part is executed.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes
Message 3 of 5

adam.nagy
Autodesk Support
Autodesk Support

Hi Ying,

 

You could do something like this.

- Create the part you need

- Invoke the placement command

- Watch for the termination of that command and continue with your code

You could just create an instance of this class and call its CreateAndPlacePart function.

Public WithEvents uiEvents As UserInputEvents

' Main function

Public Sub CreateAndPlacePart()

    ' Create the part ....
    
    ' Start watching for the terminate command event

    Set uiEvents = ThisApplication.CommandManager.UserInputEvents
    
    ' Now place the part
    
    Dim cm As CommandManager
    Set cm = ThisApplication.CommandManager
    
    Call cm.PostPrivateEvent(kFileNameEvent, "C:\NewlyCreatedPart.ipt")

    Dim cd As ControlDefinition
    Set cd = cm.ControlDefinitions("AssemblyPlaceComponentCmd")
    
    ' Start the placement
    
    Call cd.Execute
    
End Sub

Private Sub uiEvents_OnTerminateCommand(ByVal CommandName As String, ByVal Context As NameValueMap)
    
    Set uiEvents = Nothing
    
    MsgBox "Placement finished. We can continue with our code"
    
End Sub

I hope this helps.

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 4 of 5

Anonymous
Not applicable

Thanks for helping! I'm currently using Krieg's suggestion to just create a user form to run the parts before and after the user manipulation. I guess it makes sense and it's really easy to do.

 

With regards to Adam's suggestion, I'm not quite sure if you are suggesting to invoke part placement command as in the same command as when we add components to an assembly? Doesn't that only allow you to move the parts around only once? For my case, I want the user to place a part relative to another part, by rotating and moving in 3D space, so it's going to take more than a move-and-drop action. Could you clarify please?

 

Thanks, 

Ying Ying

0 Likes
Message 5 of 5

adam.nagy
Autodesk Support
Autodesk Support

Hi Ying,

 

Sorry, I thought you just wanted to place the component and then continue.

Just ignore my comment then. 🙂

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes