Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VLA-SENDCOMMAND: what's up with this?

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
Anonymous
1466 Views, 12 Replies

VLA-SENDCOMMAND: what's up with this?

my current code:

;Collapse wire number leader in ACE (this command requires a special (standard command call) command call:(C: XXX)
(defun C:CL ()
 (setq old_snap_mode (getvar "snapmode")) 

 (setvar "snapmode" 0)
 (vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "AEWIRENOLEADER C\n"))

 (setvar "snapmode" old_snap_mode)
);end CL

 

I am trying to find old snapmode, save it, turn snapping off, run the AEWIRENOLEADER with the collapse function, then return the snapmode to it's previous value. This does not happen with above code. Right now this code has snap mode turned on while trying to collapse leaders, which doesn't work if they were not put on the grid (which they never are).

 

Its as if the VLA-SENDCOMMAND always runs last, no matter what order it is in.

 

Anyone have any thoughts as to why vla-sendcommand won't allow the final setvar to happen?

or why it seems to happen before the vla-command call?

 

 

12 REPLIES 12
Message 2 of 13
dbroad
in reply to: Anonymous

If the command is not working:

I am not familiar with the  AEWIRENOLEADER command.  Is it a built in AutoCAD command, a LISP command, or an ARX command?  If LISP or ARX, then you may have to make sure it's loaded first.  With LISP, you would call the function as (c:AEWIRENOLEADER) rather than as a command.  With ARX, you may need to have its full name, including its module.

 

If the execution order is the only issue:

note that the vla-send-command may execute asynchronously.  Do you have to use the vla-send-command to run the command?  If so, consider using vla-send-command for everything  or force synchronization by using reactors to reset the variables or to wait.

Architect, Registered NC, VA, SC, & GA.
Message 3 of 13
darrell.l.gregg
in reply to: dbroad

I don't know if I have to use vla-sendcommand, it was a suggestion from these forums. documentation is weak for lisp programming. trying to self teach.

 

Message 4 of 13
dbroad
in reply to: darrell.l.gregg

It appears to be an ARX command.  Try (C:AEWIRENOLEADER) instead of (vla-send-command.....)

 

You will need to use the (command ...) function to send command line arguments to the C:AEWIRENOLEADER function.

Architect, Registered NC, VA, SC, & GA.
Message 5 of 13
Anonymous
in reply to: dbroad

I can get the command to run but can't pass it the "C" using (c:aewirenoleader).

I tried:

(COMMAND (C:AEWIRENOLEADER) "c" ""), i tjust starts the command but doesn't go into collapse mode which is what I need to happen.

I can't pass any arguements to (c:aewirenoleader) (eg (c:aewirenoleader C)) it fails for too many arguments.

I tried (command c:aewirenoleader "C" "") and that just failed for bad argument value, duh.

 

 

maybe I'm being dense...?

 

 

 

 

Message 6 of 13
dbroad
in reply to: Anonymous

your program beginning

...

...

(c:aewirenoleader)

(command "c")

...

your program end

Architect, Registered NC, VA, SC, & GA.
Message 7 of 13
Anonymous
in reply to: dbroad

that doesn't work on the command line...

I issued: (c:aewirenoleader)(command "C")<return>

it started the command, but did not pass the "C" to it, so it is in create leader mode, not collapse leader mode.

 

I also tried to issue the (command "C") after the command has started, that causes the "can't reenter lisp" error.

 

Message 8 of 13
p_mcknight
in reply to: Anonymous

As I understand it using the cla-sendcommand method is the only way to do what you want.  If you look at the help on this command you will see when it changes to asynchronous behavior.  You might try throwing your snap reset into the sendcommand string.  It would look something along the line of

 

(vla-get-activedocument (vlax-get-acad-object)) (strcat "AEWIRENOLEADER C (setvar \"snapmode\" old_snap_mode) "))

 

This will run your aewire command and then execute the nested lisp statement from the command line.

Message 9 of 13
p_mcknight
in reply to: p_mcknight

It looks like you can also get rid of the strcat.

Message 10 of 13
p_mcknight
in reply to: p_mcknight

And I missed the vla-sendcommand at the beginning of the statement.

Message 11 of 13
Anonymous
in reply to: p_mcknight

I have been fiddling in many ways to make this idea work... but so far no luck...

the biggest problem is that it puts the setvar in during the aewirenoleader command execution...

 

(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "AEWIRENOLEADER C\n (setvar \"snapmode\" orig_grid_mode)"))

didn't work

 

(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "AEWIRENOLEADER C\n"))
(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "(setvar \"snapmode\" orig_grid_mode)"))

also didn't work, both of these cause the setvar command to be put on the command line while aewirenoleader is running, which makes aewirenoleader not doing anything until you hit return which thens causes the error: cannot reenter lisp, but it lets aewirenoleader continue but won't set the snapmode back to the way it was before we started our fun.

 

I don't know much about reactors but maybe that suggestion would work... steep learning curve for me on that though...

 

I was thinking the vlr-command-reactor might work...

Unfortunately the help is confusing me a bit..

 

Message 12 of 13
dbroad
in reply to: Anonymous

Darrell,

Sorry for wasting your time.  Technically calling a lisp command and then managing that lisp command from the calling program is unsupported and generally discouraged.  I understand you are trying to wrap the lisp command with a snap toggle though which may have merit if you never ever want snap on during that command.  I just generally work with a small snap increment that doesn't interfere with my work.

In any case, this reactor hack workaround might work.  Since I don't have autocad electrical, I am guessing.  It skips the first lisp ended event (exiting the calling program) and triggers at the end of the second lispended event.  Of course if you use a cancel during the called lisp, it won't work as written and would need additional code.  Also, it might not respond correctly to an undo.

I have verified though that the sendcommand method is asynchronous. The command stack is not affected until after the program has finished.  It has been that way for quite a while.  I tested on AutoCAD 2012.

 

(defun restoresnap (r l)
  (if (zerop (car (vlr-data r)))
    (progn
      (vlr-remove r)
      (setvar "snapmode" (cdr(vlr-data r)))
      )
    (vlr-data-set r (cons 0 (cdr (vlr-data r))))
    )
  )

(defun C:CL ()
  (vl-load-com)
  (vlr-lisp-reactor (cons 1 (getvar "snapmode")) '((:vlr-lispended . restoresnap)))
  (setvar "snapmode" 0)
  (vla-sendcommand (vla-get-activedocument(vlax-get-acad-object)) "AEWIRENOLEADER C\n")
  (princ)
  );end CL

 

Architect, Registered NC, VA, SC, & GA.
Message 13 of 13
Anonymous
in reply to: dbroad

dbroad,

learning is never a waste of time.

that code seems to work.

now I have to backwards engineer to understand how it works, thanks!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost