LDCad Lua - prompt and wait for selection?


Lua - prompt and wait for selection?
#1
Hi Roland,

another LDCad scripting question for you.

I'm trying to write a script which will loop, prompt the user to select a particular part and then wait until the part is selected before moving to the next prompt/part selection. Looking through the sample Lua scripts, they seem to expect any part selections to be done prior to invoking the macro. But I'd like to have a script which will prompt the user as they go, so they don't have to remember the order in which to select the parts.

The Lua script I am using is invoked as a macro and looks something like this (it has been simplified to assist in understanding its purpose):
Code:
    -- Clear the current selection (if there is one).
  local selected_item_lo = ldc.session.getCurrent():getSelection()
  if (selected_item_lo ~= nil) then
    selected_item_lo:remove()
  end
    -- Prompt for the appropriate part.
  prompt_ls =
  {
    'Select the part/subfile which drives the rotation.'
  }
  linkage_phase_si = linkage_phase_si + 1
  ldc.dialog.runMessage(prompt_ls[linkage_phase_si]);
    -- Loop until an item is selected.
  repeat
    selected_item_lo = ldc.session.getCurrent():getSelection()
  until (selected_item_lo:getRefCount() == 1)
  ldc.dialog.runMessage('Done')

Basically, the intention of the script is to display a message dialog and, once the dialog is closed, wait until the user selects a part. However, when attempting to run this macro, the console open and displays the message
Code:
"linkage_parts_select_gf" execution exceeded the maximum duration of 250ms.

linkage_parts_select_gf is the name of my macro containing the script.

Is there a "proper" way to achieve what I'm wanting to do (i.e. wait until a part is selected) using the LDCad Lua scripting?

Regards,

David
Reply
« Next Oldest | Next Newest »



Messages In This Thread
Lua - prompt and wait for selection? - by David Manley - 2021-09-25, 4:23

Forum Jump:


Users browsing this thread: 9 Guest(s)