Lua - prompt and wait for selection?
2021-09-25, 4:23 (This post was last modified: 2021-10-10, 7:51 by David Manley.)
	2021-09-25, 4:23 (This post was last modified: 2021-10-10, 7:51 by David Manley.)
		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):
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
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
	
	
	
	
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
 
       
       
 

 
 
 
			

 
 
 
 
			 , an issue which will be solved in Alpha 2 though.
 , an issue which will be solved in Alpha 2 though.![[Image: 400x298.png]](https://bricksafe.com/files/djm/djm_public_documents/ldorg/linkage_shadow_library.png/400x298.png)
![[Image: macro_with_animation.png]](https://bricksafe.com/files/djm/djm_public_documents/ldorg/macro_with_animation.png)