1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Script dialog help please

Discussion in 'Alibre Script' started by albie0803, Sep 15, 2020.

  1. albie0803

    albie0803 Alibre Super User

    Is there a way to have the next field highlight in a dialog window when a value is added?

    Could it be added to the below Example. I'm sure someone here wrote it but I couldn't find it with a forum search.

    ScriptName = 'Test Window'
    print("\n"*20) # lazy mans clear console
    Win = Windows()
    # called when an input changes in the dialog window
    def InputChanged(Index, Value):
        print("You changed index %s!" %Index)
        # do things here depending on value
        if Index == Index_Boolean:
            print("You changed Boolean Value to %s!" %Value)
    # updates the user interface based on the current selections made
    def UpdateUserInterface():
        for i in range(len(Options)):
            if i not in DoNotDisable:
    #            Win.DisableInput(i)
    # define options to show in dialog window
    Options = []
    DoNotDisable =[]
    Options.append(['String', WindowsInputTypes.String, 'String'])
    Options.append(['Integer', WindowsInputTypes.Integer, 0])
    Options.append(['Real', WindowsInputTypes.Real, 0.0])
    Options.append(['Boolean', WindowsInputTypes.Boolean, True])
    DoNotDisable.append( len(Options)-1) # add this boolean to the DoNotDisable list to test it
    Index_Boolean = len(Options) -1 # get the index of the previous item appended even if you put more above it
    Options.append(['Face', WindowsInputTypes.Face, None])
    #Options.append(['Faces', WindowsInputTypes.Faces, None]) # commented out simply because the window got too big
    Options.append(['Plane', WindowsInputTypes.Plane, None])
    #Options.append(['Planes', WindowsInputTypes.Planes, None]) # commented out simply because the window got too big
    Options.append(['Edge', WindowsInputTypes.Edge, None])
    #Options.append(['Edges', WindowsInputTypes.Edges, None]) # commented out simply because the window got too big
    Options.append(['Vertex', WindowsInputTypes.Vertex, None])
    #Options.append(['Vertices', WindowsInputTypes.Vertices, None]) # commented out simply because the window got too big
    Options.append(['Point', WindowsInputTypes.Point, None])
    #Options.append(['Points', WindowsInputTypes.Points, None]) # commented out simply because the window got too big
    Options.append(['Axis', WindowsInputTypes.Axis, None])
    #Options.append(['Axes', WindowsInputTypes.Axes, None]) # commented out simply because the window got too big
    Options.append(['Sketch', WindowsInputTypes.Sketch, None])
    #Options.append(['Sketches', WindowsInputTypes.Sketches, None]) # commented out simply because the window got too big
    #Options.append(['Sketch3D', WindowsInputTypes.Sketch3D, None])
    Options.append(['File', WindowsInputTypes.File, 'File Path including Name Here'])
    Options.append(['Label', WindowsInputTypes.Label, 'Label'])
    DoNotDisable.append( len(Options)-1) # must add all Labels to the DoNotDisable list or you get an error
    Options.append(['SaveFile', WindowsInputTypes.SaveFile, 'SaveFile Path including Name Here'])
    mystringlist = ["test","this",'list']
    Options.append(['StringList', WindowsInputTypes.StringList, mystringlist])
    Options.append(['Image', WindowsInputTypes.Image, 'MaxCellSize.png', 170])
    myURL = ['Click Here!','https://www.google.com/', int('0000ff',16)] # first the text to display, then the url, then a hexidecimal rrggbb color converted into an integer
    Options.append([None, WindowsInputTypes.Url, myURL])
    DoNotDisable.append( len(Options)-1) # must add all Urls to the DoNotDisable list or you get an error
    Options.append(['Folder', WindowsInputTypes.Folder, 'Folder Path Here'])
    # show dialog to user, get inputs
    Values = Win.OptionsDialog(ScriptName, Options, 200, InputChanged, UpdateUserInterface)
    if Values == None:
        print("Canceled... Exiting.")
    # other error checking and program here
  2. NateLiqGrav

    NateLiqGrav Alibre Super User

    Simple answer is no it can't do that. And I wrote that.

    If you want more control over the windows then you need to build your own windows from scratch using standard windows controls - which is far from easy.
  3. idslk

    idslk Alibre Super User

    You can use the "TAB"-Key, not the same, but helps a little bit...
  4. albie0803

    albie0803 Alibre Super User

    Thanks guys.
  5. DavidJ

    DavidJ Alibre Super User Staff Member

    I suspect this is a very similar question to Albie's - so I won't be surprised if the answer is 'no'.

    I successfully have a script which uses a Win.UtilityDialog to allow user to select a part from the assembly and set some properties for it.

    After setting the properties for the first part selected, the user has to click in the first field (part) of the dialog to make it 'active' again, before it's possible to choose the next part to work with.

    I'd like to avoid the user having to make the extra click in the part selection field to get it active again. Rather they could just click on the next part.

    I would assume this must be possible as the filed is highlighted (active) when the dialog first opens - so if the dialogue can be 're-set' to make the first field active that would be ideal.

    So in summary - I'd like to add to the end of my routine that sets the values for the part properties, some code to return focus / active state to the initial field of the dialogue.

    Is this possible? Can anyone point me to an example?
  6. idslk

    idslk Alibre Super User

    win = Windows()
    def repeatbeat():
      options = []
      options.append(["An Axis", WindowsInputTypes.Axis, None]) #[0]
      options.append(["Your name", WindowsInputTypes.String, 'David']) #[1]
      values = win.OptionsDialog('Do it again Sam!', options, 280)
      if values == None:
        sys.exit('User canceled')
      return values
    loop = 1
    while loop == 1:
      values = repeatbeat()
      for nr,value in enumerate(values):
        print 'Value',nr,':',value
      again = win.QuestionDialog('See console for printed values...\nanother one?','Really?')
      if again == False:
        loop = 0
  7. DavidJ

    DavidJ Alibre Super User Staff Member

    Thanks Stefan

    I'll have to play around to see if I can tweak that structure to maintain the functionality I already have, whilst adding the active field re-set...
    Currently the part selection populates the various property fields, which can then be edited and set.

    I may be back with follow up question(s)...
  8. NateLiqGrav

    NateLiqGrav Alibre Super User

    You may be interested in using OptionsDialog with the InputChangedCallback and UpdateUserInterfaceCallback functions and using the following Windows functions:
  9. DavidJ

    DavidJ Alibre Super User Staff Member

    Thanks Nate - I have already used the callbacks and SetInputValue successfully (with the UtilityDialog ). For some reason I couldn't set the contents of the Part field that way - Stefan's approach to re-initialize the dialog seems to have promise.

    I'll get there eventually.
  10. DavidJ

    DavidJ Alibre Super User Staff Member

    I think I'll have to admit defeat - I've achieved almost all that I want to in the script except that after clicking the 'Set Property' button, I'd like the 'Target Part' field of the dialog to become active again, ready to choose the next part. Ideally I'd like it to retain the part from the previous selection - but active and empty would be almost as good.

    I've borrowed various good ideas from both Stefan and Nate, in getting this far.

    My attempts with Stefan's method from post #6 seem to need an extra user action to 'break the flow' (his QuestionDialog) - the user might as well simply click in the Target Part field to make it active again.... maybe I'm missing something.

    I hope there is some way achieve this -

    Script as it stands is attached : NOTE - it runs in v22 (say build 22037). It requires a file 'FavMat.txt' to be stored in the same folder as the script - each line of the file should hold the exact name of a favourite material from the Material Library (either standard or Custom). These materials populate the drop down of materials to assign.

    [EDIT - example FavMat.txt file added ]

    Attached Files:

    Last edited: Sep 30, 2020
  11. idslk

    idslk Alibre Super User

    at minimum: you've not delivered a FavMat.txt to test...
    Here another Sample...

    Attached Files:

  12. DavidJ

    DavidJ Alibre Super User Staff Member

    Stefan - I did make it clear that FavMat is required - I mistakenly thought it would be easier to let people use their own favourites. I'll go back and add a sample file that works just with Alibre Standard Materials.

    Your new script still has the extra steps that end user must go through - so is not of any benefit over where I got to previously. I did try adapting your earlier example.
  13. idslk

    idslk Alibre Super User

    Which Steps?
    This script is to show how you get an empty, highlighted first input field. Nothing more!
  14. idslk

    idslk Alibre Super User

    Here another sample...

    Attached Files:

  15. DavidJ

    DavidJ Alibre Super User Staff Member

    Stefan - that last one is promising, apart from the strange behaviour on the first cycle,

    The extra question step has been removed.

    I have great difficulty following the program flow - and picking up the differences that slight changes make. I'm sure it's all too obvious to you - but without comments / explanation I'm simply copying without understanding.

    If I get time, I'll try again based on that, to see if I can iron out the remaining problem.

    Thank you!

Share This Page