Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

User interaction in VBA

4 REPLIES 4
Reply
Message 1 of 5
yingyinw
813 Views, 4 Replies

User interaction in VBA

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

Tags (2)
4 REPLIES 4
Message 2 of 5
Ralf_Krieg
in reply to: yingyinw

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 GmbH
www.rkw-solutions.com
Message 3 of 5
adam.nagy
in reply to: yingyinw

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
yingyinw
in reply to: adam.nagy

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

Message 5 of 5
adam.nagy
in reply to: yingyinw

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report