AutoLISP "command" function problem

Started by maweilian, February 19, 2009, 12:57:02 PM

Previous topic - Next topic

maweilian

I'm relatively new to OpenDCL.  I have run into a snag on an application I am working on.  I have a modeless dialog box.  When a text button is clicked the following event handler kicks in:


;;define action when the insert button is clicked
(defun c:partlibmain_PartLibMain_Insert_OnClicked (/ Dwgname)
  (setq Dwgname (dcl_ListBox_GetSelectedItems partlibmain_PartLibMain_ListBox1))
  (plsub:InsertBlock Dwgname)
);end defun


The event handler above calls the following subroutine (plsub:InsertBlock) which is shown below:


;;;Subroutine for inserting a block into the current drawing
(defun plsub:InsertBlock (Dwgname / Dwgpath insertpt)
  ;;save current objects snap settings
  (setq oldosmode (getvar 'OSMODE))
  ;;construct the path of the drawing selected
  (if Parent
    (setq Dwgpath (strcat "G:\\Blocks\\" Parent "\\" Child "\\" DwgName ".dwg"))
    (setq Dwgpath (strcat "G:\\Blocks\\" Child "\\" DwgName ".dwg"))
  );end if
  (setq insertpt (getpoint "Specify an insertion point: "))
  ;;turn off object snaps
  (setvar "OSMODE" 0)
  ;;insert the block
  (command "._insert" Dwgpath insertpt 1 1 0 "")
  ;;Restore object snaps
  (setvar "OSMODE" oldosmode)
);end defun


Once the code executes the "(command "._insert" ..."  line the application bombs and the AutCAD command line reads: "Error: invalid AutoCAD command: nil; reset after error".

What am I missing?

Thanks,
Will

BazzaCAD

Select the Text Button & have a look at the "Event Invoke" property & change it to 1

Quote
This property controls whether event handlers are called synchronously or asynchronously. A synchronous call causes the dialog code to wait until the event handler returns before resuming; an asynchronous event call allows the dialog code to continue running, and the event handler is not executed until AutoCAD is ready to process commands. This property is hidden and ignored for controls on modal forms.

Value Meaning
0 Synchronous
1 Asynchronous

Event handlers that are called synchronously are limited in what they can safely do, because they run while the dialog code is in a suspended state and AutoCAD is unable to process commands. For example, it is not possible to call the AutoLISP (command) function from a synchronous event handler.

Asynchronous event handlers in most cases will not execute until after the event that triggered it has passed, however an asynchronous event handler can safely call the AutoLISP (command) function to process AutoCAD commands. When a modeless dialog control's event handlers need to use the AutoLISP (command) function, the Event Invoke property for the control must be set to 1.

Any events that have return values are always called synchronously (otherwise the return value would be lost). Events called from modal forms are always called synchronously, since modal forms by their nature prevent AutoCAD from executing commands while they are active. Event handlers in these cases must conform to the requirements for synchronous events regardless of the Event Invoke property setting.

a.k.a.
Barry Ralphs
barryDOTralphsATgmailDOTcom

maweilian

Thanks, that worked!  Learning more about OpenDCL every day!  Thanks again.