What's new

User Interaction & Dialogues

DavidJ

Administrator
Staff member
I've successfully written a small number of quite basic scripts, starting by adapting sections from the existing scripts of others. On my last script I managed to use a 'Win.UtilityDialog' successfully - I now want to extend the functionality, and I haven't found a usage of Win dialogs that I can copy/adapt to suit my purpose. I may need to use 2 separate dialogs, or maybe I can use a single but more advanced dialog...

So far I'm struggling to find a clear explanation of dialogs that are available to me, and then how to use them. Can anyone suggest a good place to start - either web based or a book?

Thanks in advance.
 

idslk

Alibre Super User
Hello David,

if you do a forum search :) you will get some results...one is Fretboardmaker, but there are a lot of others too.
Another way is to ask a little more precise. What do you want you achieve?

Regards
Stefan
 

DavidJ

Administrator
Staff member
Thanks Stefan - I've seen similar ones to that to get to where I'm at today.

More precise - OK I want user to click on a part (within assembly), then display the current values of part properties for selected part , which user can then edit/commit. Ideally edit in the same dialogue where the initial/current values are displayed (if that is possible).

I've already done this where user chooses part and enters property values into empty fields (using Win.UtilityDialog ), but it doesn't display the current values.

Everything I've found so far regarding dialogs has to be worked back from the particular example (or is incomplete) - I haven't found any clear documentation.

I'd really like to understand WHICH dialogues (or alternative user interaction devices) are available, and then find instructions for using each one, so I can decide which is the best option(s) and then set up my usage.

I have some ideas on how I might approach this, some good documentation of what is supported would save a lot of trial and error.
 

albie0803

Alibre Super User
Is this the sort of thing you are after?

Win = Windows()
Options = []
Options.append([None, WindowsInputTypes.Label, 'Enter value below from your model']) #[0]
Options.append(["Click Hole/Shaft Edge", WindowsInputTypes.Edge, None]) #[3]

Values = Win.OptionsDialog("Hole/Shaft Sizer", Options, 250)

E = Values[1] # Edge Value

G = E.Name
CylDia = E.Diameter
CylRad = CylDia / 2

Win.InfoDialog("The hole/shaft diameter is: " + str(CylDia), 'Value')
 

DavidJ

Administrator
Staff member
Albie - not really, but thanks anyway. You may have confirmed my suspicion that I'll have to tackle this in 2 stages.

You've pointed out dialog types I hadn't picked up on before (Win.OptionsDialog & Win.InfoDialog) so that's useful.
 

DavidJ

Administrator
Staff member
Is it possible to have a dialog that is the 'child' of an initial dialog? or maybe have a primary field (to select part) then have secondary field which can display the current value of some properties, and allow these to be edited.

I can find a little basic description, but that's mainly from looking at example scripts. I can't find so far a clear explanation of available dialog types and needed values to define them.

Albie - how do the index values work in your example above? I think I'm missing something fundamental there..
 

DavidJ

Administrator
Staff member
Have found a bit more information in the Windows Class Reference of the Alibre Script help file - I may be beginning to see some light (or is that a train coming).

I'm sure this will all seem trivial eventually. This just confirms my belief that Scripting is not for most users.

Can I use 'SetInputValue' or 'SetStringList' to update the property fields in my dialog after selecting a part ? - the documentation is minimal, and I don't see how the use of these lines up with any kind of dialog box
 
Last edited:

idslk

Alibre Super User
Hello David,

shall it look like this:
Code:
#create a Windows object
Win = Windows()

# Sample use of the InfoDiaalog
#First define the 2 parameters for the dialog
Message = 'let`s start with a simple question'
Title = 'My first message to a user'

#Call the dialog
Win.InfoDialog(Message,Title)

#Sample use of the QuestionDialog
#Attention, this dialog has a return value
#First define the 2 parameters for the dialog
Question = 'Do you like AlibreSkript?'
Title = 'My first question to a user'

#Not neccessary in AlibreSkript. Define the return value
Answer = None

#Call the dialog
Answer = Win.QuestionDialog(Question,Title)

#Do something with the return value
if Answer == True:
  #Now the second use for the InfoDialog
  #I can use new variable names. but i am to lazy ;-)
  Message = 'You will have a bright future'
  Title = 'My second message to a user'
  Win.InfoDialog(Message,Title)
else:
  #Now the first use for the ErrorDialog (nearly the same funtion as the InfoDialog, but different symbol...)
  #I can use new variable names. but i am to lazy ;-)
  Message = 'The devil will catch you!'
  Title = 'My first error message to a user'
  Win.ErrorDialog(Message,Title)

and than for all of topics available in the AlibreScript.chm?
upload_2020-6-26_16-24-41.png

Regards
Stefan
 

DavidJ

Administrator
Staff member
Nate - thanks! No I have almost no familiarity with WinForms - I don't really know what is possible, nor what most of the terms mean. I hope I'll get there in the end.

I do get fed up when articles keep telling me Python is so easy, yet miss out basics that I need to know to get anywhere. I've coded in the past and I still routinely configure automation systems - I've found the 'powerful' nature of Python, I'm still waiting for the 'easy' bit to show up.
 

DavidJ

Administrator
Staff member
Stefan,

Thanks - I did find the stuff in the chm file (it probably mean something to those that already understand it).

I can make simple use of the dialogs work - my current challenge is updating the displayed values in response to user input.

Here's my very simple script that allows user to select a part from assembly, then set Number & Description properties (without having to separately edit the part). It works fine, BUT it would be even better if the current values of the properties populated the fields after a part had been selected, and still let the user enter new values.

That's my current challenge.

If I can get the basics to work, I can extend the number of properties that it handles.

[EDIT
Of course there may be a much better way to tackle this - in which case I'm happy to change the approach!
/EDIT]
 

Attachments

  • PropFromAssy.py
    922 bytes · Views: 5
Last edited:

NateLiquidGravity

Alibre Super User
David Maybe you can help me with some confusion. Does the Configuration check box for "Part Data (General Properties)" mean that each configuration could have different Number and description? I can't seem to get that to work with or without Vault.

upload_2020-6-26_14-37-45.png


Also I can't find a way to get the selected configuration of an AssembledPart used in an Assembly. For example an assembly has 1 each PartA - Config<1> (AssembledPart_1) and 1 each PartA - Config<2> (AssembledPart_2)
AssembledPart_1.GetActiveConfiguration() and AssembledPart_2.GetActiveConfiguration() seems to only get the last active configuration of a Part so both say Config<1>.
 

DavidJ

Administrator
Staff member
Nate - this came up only recently at support, and I also noticed something during my experiments with setting properties...

I don't know the history of why, but

'General Properties' are shared across all configurations. (Personally I find this odd).

'Part Data Properties', both Standard and Custom, can be made unique to configurations if the lock is set.

The current label on the lock is misleading.

As you've probably guessed from my own postings, I feel hardly qualified to comment on Script functionality - I find it almost impossible to follow the documentation myself. I know what the description suggests to me that it should return, but I'm not at all confident about that. I'd suggest raising a support ticket, that'll at least get the functionality clarified - and if it isn't working as intended it can be pushed back to Development.
 
David Maybe you can help me with some confusion. Does the Configuration check box for "Part Data (General Properties)" mean that each configuration could have different Number and description? I can't seem to get that to work with or without Vault.
Hi Nate -- At the risk of swirling an over-boiling pot, the "tradition" (at least in the USA) dating to (about) WWI is that Parts and Assemblies have a Dash Number that is appended to the Project Number. Thus, "-001" through "-099" were Assemblies and "-002" is (by definition) the Opposite Hand Assembly to "-001," etc. Similarly, "-102" is the Opposite Hand Part to "-101," etc. There used to be a rather long list of such "Dash Number Identities" and their meanings (just ask, I can prove the old machinist's adage about being "as sharp as a drill and twice as boring").

However, in 1995 the American government decided to use an approach recommended by the American Institute of Architecture that (A) eliminated "Dash Numbers" and (B) instituted the "one Part or one Assembly defined by a single "Model" and "Drawing" rule. I am still coming to terms with this approach. [If I had a mind I would only lose it -- but I said if.] -- Lew
 

idslk

Alibre Super User
Hello David,

do you want something like this:
Code:
def SetProps(Values):
  TargetPart = Values[0].GetPart()
  Numb = Values[1]
  Descr = Values[2]
  TargetPart.Number = Numb
  TargetPart.Description = Descr

def Showdata(index,value):
  if index == 0:
    if value != None:
      xpart = value.GetPart()
      Win.SetInputValue(1,xpart.Number)
      Win.SetInputValue(2,xpart.Description)
    else:
      Win.SetInputValue(1,None)
      Win.SetInputValue(2,None)
     
ScriptName = 'Set Part Properties'

Win = Windows()

# define options to show in dialog window
Options = []
Options.append(['Target Part', WindowsInputTypes.Face, None])
Options.append(['Number', WindowsInputTypes.String, None])
Options.append(['Description', WindowsInputTypes.String, None])

# show utility window
Win.UtilityDialog(ScriptName, 'Set Property', SetProps, Showdata, Options, 400)

Regards
Stefan
 

DavidJ

Administrator
Staff member
Stefan,

Thanks - that is what I wanted to achieve!

I was right to look at SetInputValue - having your example makes it so much easier than just the basic information in the chm file. I now see how it is used. Like so many things, it's easy when you know how.

Could you explain why you used WindowsInputTypes.Face rather than WindowsInputTypes.Part ? Is that just the way you prefer to do things, or is there a functional reason why?

I'm also a bit mystified by if index == 0:
I can see that it is checking for index to be zero - but I'm not clear why it has to be checked, or indeed what might change it...

When I can fully understand this, I'll expand it a bit and also look at Nate's Forms suggestion (esepcially as we now know there are different catgories of property data).

David
 

idslk

Alibre Super User
Hello David,

Thanks - that is what I wanted to achieve!
nice to hear that.

Could you explain why you used WindowsInputTypes.Face rather than WindowsInputTypes.Part ? Is that just the way you prefer to do things, or is there a functional reason why?
Functional reason. First thought is obviously Part.
I've tried using Part instead of Face, but it produces odd behaviour while changing selection of Part.
This is a thing where Andy could take a look at...

I'm also a bit mystified by if index == 0:
I can see that it is checking for index to be zero - but I'm not clear why it has to be checked, or indeed what might change it...
The dialog box has a "InputChangedCallback Function (called when an input is changed)" and this Function has two parameter which are handled through to your defined procedure. These two parameter are the index of the changed dialogbox element and the value of this element. The elements of the dialog boxes are numbered.
That's due to they are a list ( Options[n] ).
In this particulary skript you have three elements:
[0] Options.append(['Target Part', WindowsInputTypes.Face, None])
[1] Options.append(['Number', WindowsInputTypes.String, None])
[2] Options.append(['Description', WindowsInputTypes.String, None])
and the defined procedure:
def Showdata(index,value):
If you now change the first element of the box using the mouse selecting a part, this procedure will be call automatically with the parameter (Index = 0 (first options object is face), Face object).
In Showdata i check if the first element (index =0) was changed.
I only want to react to the first element! The other elements sould not trigger any action in the procedure.
With the "part" information i can update the Number and Description. These values can be overwritten throught the user without any reaction of the procedure unless the user hits the button "Set Props" ;-)

Regards
Stefan
 

DavidJ

Administrator
Staff member
Thanks Stefan,

That's quite a lot clearer.

I've played with using Part and also had some very strange behaviour - sometimes it works, then it 'lags' one selection behind the workspace, eventually it stopped working altogether - adding a dummy line to Showdata can have a big effect on the behaviour.

That's a pity, because it's much simpler for user to select part in workspace OR in DE.

Part works fine if not using the on InputChangedCallback.

I did wonder about trying the UpdateUserInterfaceCallback, but I've no idea what that one expects or can do.


One final question (for now) - is it possible to return focus to the field zero after user has clicked 'Set Properties' - so that it is ready to choose the next part?
 

DavidJ

Administrator
Staff member
Using 'Part' - on first selection the instance number (typically <1>) is omitted from the field, subsequent selections include the instance number, but lag one selection behind.

If I add an unnecessary line to write the part back to value 0, then the first selection does show instance, second and subsequent selections still lag one behind. Even when the part shown in the field is lagging behind, the values are updated from the correct part (based on DE/Workspace).

If I remove the InputChangedCallback - selection of parts works as expected. The slight randomness makes me think this might be a timing issue...

[EDIT - if I click in field zero, it updates to the correct value - is there a command I can use to refresh field zero...]
 
Last edited:

DavidJ

Administrator
Staff member
Progress - managed to overcome the 'lag' issue when using parts - not really sure why this works, but add a 'Win.ShowPart' at line 14 seems to have done the trick.

Now to find a way to get focus back to selection window after setting.


[EDIT - had a panic, it stopped working altogether, but re-starting Alibre fixed it ].
 

Attachments

  • SetProps1.py
    815 bytes · Views: 5
Last edited:
Top