Command from lisp into tool palette does not work correctly on the first call, but works on the subsequent calls

Command from lisp into tool palette does not work correctly on the first call, but works on the subsequent calls

spyros.n7
Contributor Contributor
431 Views
6 Replies
Message 1 of 7

Command from lisp into tool palette does not work correctly on the first call, but works on the subsequent calls

spyros.n7
Contributor
Contributor

Hi, I am facing a weird issue with a command from a lisp I created and the tool palette.

 

My lisp (which I have heavily stripped down for demo/debugging purposes) just creates a rectangle from 2 points. From this lisp I created a tool which I placed in a palette. In the properties of the tool, I set the layer to my liking. The problem is that when I use this tool for the 1st time when I open Autocad, the rectangle is not created on the specified layer, but in whatever the current layer is. But every subsequent time I use the tool, either is the same drawing or in a new drawing, the rectangle is drawn on the correct layer (the one that is specified inside the tool properties)! This works correctly until I close autocad. Next time I open it, the same happens. The 1st time the layer is wrong, all subsequent times the layer is correct.

 

In sort, the steps to reproduce are:

 

1. Open Autocad.

2. Load the attached lisp file.

3. Create a line or whatever tool in a palette.

4. In the tool properties, set use flyout to no and change the command string to this ^C^C_topogridcross

5. In the tool properties, set the layer to any layer you like, except 0 or the current layer of your drawing.

6. Use the tool. --> You should get the rectangle on the wrong layer.

7. Use the tool again. --> You should now get the rectangle on the correct layer!

8. Create a new drawing. Use the tool. --> You should get the rectangle on the correct layer!

9. Close Autocad.

10. Repeat steps 1-8. --> You should see the same results.

 

Can anyone explain what's going on? It's driving me crazy. I guess something is not set correctly or initialized when I first use the command from the lisp file, but what is it? And how is it set automatically after the first call?

 

0 Likes
Accepted solutions (1)
432 Views
6 Replies
Replies (6)
Message 2 of 7

Sea-Haven
Mentor
Mentor

Maybe a little rearrange press Enter to exit when asked for point 1

 

(vl-load-com)
(regapp "AcAecLayerStandard") ; For being able to set layer description


(defun C:topogridcross ( / *error* x1 y1 x2 y2 pt1 pt2)

  (defun *error* (msg) ; restore osnap mode in case of error or cancelation
    (if (not (member msg '("Function cancelled" "quit / exit abort")))
      (princ (strcat "\nError: " msg))
    )
    (princ)
  )

    ;pick first point of the grid
  (while (setq pt1 (getpoint "\n Give 1st point: ")
    x1 (car pt1)
    y1 (cadr pt1))
    ;pick second point of the grid
    (setq pt2 (getpoint "\n Give 2nd point: ")
    x2 (car pt2)
    y2 (cadr pt2))
    (command "rectangle" (list x1 y1) (list x2 y2))
  )
(princ)
)

 

0 Likes
Message 3 of 7

spyros.n7
Contributor
Contributor

Hi, thanks but still doesn't work. Same behavior.

 

Does it work for you? were you able to reproduce the issue I described?

 

What are we looking for as the cause of the problem? I happen to be a programmer, but this kind of behavior is very strange to me...

 

Regards.

0 Likes
Message 4 of 7

Moshe-A
Mentor
Mentor
Accepted solution

@spyros.n7  hi,

 

First of all you are right, it looks like it's a bug in tools palette and the solution i found for this is to modify the command string tools palette:

 

^C^Clayer m ccccc c N ccccc; topogridcross

 

copy & paste the above macro into command string field. 

 

replace ccccc with your preferred layer

replace N with color number (1 for read, 2 for yellow, 3 for green....)

 

if it's hard to modify it on the command string field, modify the command in your notepad than copy & paste it.

 

and if i may advice a more well design for your topogridcross command 😀

 

enjoy

moshe

 

 

(defun c:topogridcross (/ *error* pt1 pt2)

  (defun *error* (msg) ; restore osnap mode in case of error or cancelation
   (if (not (member msg '("Function cancelled" "quit / exit abort")))
      (princ (strcat "\nError: " msg))
   )
    (princ)
  )

  (while (and
	  (setq pt1 (getpoint "\nPick 1st point: "))
	  (setq pt2 (getcorner pt1 "\nPick second point: "))
        )
    (command "._rectangle" "_none" pt1 "_none" pt2)
  )

 (princ)
)

 

 

 

 

 

 

 

Message 5 of 7

ВeekeeCZ
Consultant
Consultant

It's weird. But it's just the RECTANG. No other command. So I guess... PLINE seems more than a convenient substitution.

 

BTW it's so weird that if you use LINE and RECTANG right behind each other, the layer is applied to LINE but not to RECTANG.

Message 6 of 7

spyros.n7
Contributor
Contributor
Hi, thanks for the workaround. So, where am I supposed to report this bug? I 've never done this before.

Also, thanks for the optimization of the code, but as I wrote in my first post, this is part of a bigger lisp, that does way more than creating a rectangle. I stripped it down for demo purposes. I 'll find a way to include your suggestion to my code though.

Thanks.
0 Likes
Message 7 of 7

Moshe-A
Mentor
Mentor

@spyros.n7 ,

 


@spyros.n7 wrote:
Hi, thanks for the workaround. So, where am I supposed to report this bug? I 've never done this before.



>> AutoDesk Bug Report << 

 

 

0 Likes