Dynamic Control of Parameters

Dynamic Control of Parameters

Anonymous
Not applicable
607 Views
11 Replies
Message 1 of 12

Dynamic Control of Parameters

Anonymous
Not applicable
Hello,
I have created an Add-In (VB.NET using Visual Studio 2005) which accesses an Inventor assembly. I have been able to read in parameter values and display them for the user. I am trying to provide a "slider" which allows the user to change values dynamically while viewing the results in real-tiime.

For example I have a box on top of a cylinder with a parameter defining an angular constraint value.

I have placed a TrackBar on a VB Form and set the min value to 0 and the max value to 6.2 (approx 360 degrees in radians knowing that parameter values will be in radians). I then created a ValueChanged event procedure for the trackBar object and added the following code:

oDoc = oApp.ActiveDocument
oCompDef = oDoc.ComponentDefinition
'I used a listBox to define variable "SelectedManip"
oCompOcc = oCompDef.Occurrences.ItemByName(SelectedManip)
oSubDef = oCompOcc.Definition
oSubParams = oSubDef.Parameters
oModelParams = oSubParams.ModelParameters
oModelParams.Item("Manip01_Angle").Value = TrackBar1.Value
'I created a text box on the form to provide angular feedback to the user.
TextBoxAngle.Text = TrackBar1.Value
oDoc.Update()

I find that it woks but only triggers once, moving the Inventor assembly and then stopping untill I try and drag the TrackBar again. I want to use this technique to allow users to interactively adjust parameters.

I would be grateful if someone could explain how to enable smooth control of the values.

Thank you.

Chris
0 Likes
608 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable
the ValueChanged event may only fire when the mouse is released. You might look for a different event, maybe an OnDrag event?
0 Likes
Message 3 of 12

Anonymous
Not applicable
Hi Josh,

I thought along similar lines so I commented out the Inventor related code and just left the TrackBar updating the text field on the VB form. It worked great and interactively as I dragged left to right. I therefore assume that the trackBar object is constantly sending a changing value as I drag.

Thanks
0 Likes
Message 4 of 12

Anonymous
Not applicable
Depending on if the form is modal or modeless, it may be blocking Inventor from processing the oDoc.Update() call. You could try putting a Do Events statement after the oDoc.Update()
0 Likes
Message 5 of 12

Anonymous
Not applicable
Hi Josh,

The vb form is Modeless so the user can interact with the Inventor assembly.

Are you suggesting I place the oDoc.Update() within a Do While loop? VB doesn't recognise a "Do Events" statement.

I had considered that I should use a Do While statement but why does the text file update OK?

Regards

Chris
0 Likes
Message 6 of 12

Anonymous
Not applicable
don't know about VB.NET, but VBA (thru Inventor) has a DoEvents function. You would call this from your Form after calling oDoc.Update(). This is only a guess, but it might work...

(from help)
DoEvents passes control to the operating system. Control is returned after the operating system has finished processing the events in its queue and all keys in the SendKeys queue have been sent.
0 Likes
Message 7 of 12

Anonymous
Not applicable

In VB.NET

 


size=2>System.Windows.Forms.Application.DoEvents()

 

 

If you place the following statement at the very
top of the form's code window (above the class declaration), you can shorten the
above to just DoEvents().

 

Imports
System.Windows.Forms.Application

 

 

 

 

don't know about VB.NET, but VBA
(thru Inventor) has a DoEvents function.  You would call this from your
Form after calling oDoc.Update().  This is only a guess, but it might
work...

(from help)
DoEvents passes control to the operating system.
Control is returned after the operating system has finished processing the
events in its queue and all keys in the SendKeys queue have been
sent.
0 Likes
Message 8 of 12

Anonymous
Not applicable
Hello Neil and Josh,

Thank you for the clarification. Unfortunately this didn't enable the TrackBar to continuously change and update the parameter values. I am sure this must be simple but I can't see it.

If anyone is able to interactively adjust a parameter value using the TrackBar on a VB form (or similar control) I would be grateful for the code.

Thank you.

Chris
0 Likes
Message 9 of 12

Anonymous
Not applicable
Hi,

Curiously I replaced the trackBar with a HScrollBar and it worked, without the DoEvents as well. However I would prefer to use the TrackBar because the Ticks aid the user in setting values and it looks more appropriate.

Any advise gratefully received.

Regards

Chris
0 Likes
Message 10 of 12

Anonymous
Not applicable
This code works for me. I have a form with a track bar and a part open that
contains a parameter named "Length". As I move the track bar the length of
the part is changing.

Private invApp As Inventor.Application
Private invPartDoc As Inventor.PartDocument

Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TrackBar1.Scroll
Dim invParam As Inventor.Parameter
invParam = invPartDoc.ComponentDefinition.Parameters.Item("Length")

invParam.Expression = TrackBar1.Value
invPartDoc.Update()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
invApp = GetObject(, "Inventor.Application")
invPartDoc = invApp.ActiveDocument
End Sub
--
Brian Ekins
Autodesk Inventor API

wrote in message news:5546759@discussion.autodesk.com...
Hi,

Curiously I replaced the trackBar with a HScrollBar and it worked, without
the DoEvents as well. However I would prefer to use the TrackBar because the
Ticks aid the user in setting values and it looks more appropriate.

Any advise gratefully received.

Regards

Chris
0 Likes
Message 11 of 12

Anonymous
Not applicable
One more thing. I wrote it using VB 2005 Express and the type of project is
a standalone windows application.
--
Brian Ekins
Autodesk Inventor API
0 Likes
Message 12 of 12

Anonymous
Not applicable
Thank you Brian,

I will try it later today and let you know.

Regards

Chris
0 Likes