Author Topic: Problem with redefining command  (Read 2541 times)

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 343
Problem with redefining command
« on: July 26, 2012, 07:58:09 AM »
Hello everyone,
I wrote the following code:

Code: [Select]
(defun undefine-command (cname)
   (if (getcname cname)
     (progn
        (setvar "cmdecho" 0)
        (command "._UNDEFINE" cname)
     )
   )
)

(defun purgenew ()
  (alert "HELLO")
  (command "_.purge")
)


(defun c:test ()
  (undefine-command "_purge")
  (undefine-command "_-purge")
  ;--------------------------
  (defun c:purge ( )
    (purgenew "si")
  )

  (defun c:elimina ( )
    (purgenew "si")
  )

  (defun c:-elimina ( )
     (purgenew "-")
  )

  (defun c:-purge ( )
     (purgenew "-")
  )

  (defun c:_-purge ( )
     (purgenew "-")
  )
  ;--------------------------
)

I have a problem you describe with the following steps:

1. I open AutoCAD
2. Load the file lisp
3. Start the command "PURGE" ok! is the normal AutoCAD command
4. Starting c: test
5. Start the command "PURGE" ok! the purge command is redefined
6. I open a new drawing
7. Start the command "PURGE" unknown command, why?


Whereas I have opened a new file and I have not loaded the file lisp and I've never started the test function, I expected it to be started normally PURGE command in AutoCAD.

Can you help me to achieve this solution?
thanks

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Problem with redefining command
« Reply #1 on: July 26, 2012, 11:35:36 AM »
Lisp is loaded only into the current drawing, while ARX/DotNet commands are instantiated for ACad as a whole. So you need to have your lisp loaded automatically - IMO best is to load it from the ACadDoc.LSP file. Also you'll need to run the c:test function as soon as loaded - so it defines the new purge command as soon as loaded for a DWG file.

Alternatively if you only want to turn on this feature of yours, then use vl-load-all instead of a normal load. Also still needed to run the c:test. Just add the following to the end of your LSP file:
Code: [Select]
(c:test)
Unfortunately the vl-propagate only applies to variables, not defuns. Otherwise it might have been possible to define new commands in other DWGs as well.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lupo76

  • Bull Frog
  • Posts: 343
Re: Problem with redefining command
« Reply #2 on: July 26, 2012, 03:29:20 PM »
Hello irneb,
thanks for the answer, but I want to do exactly the opposite.

I would like to start the command c: test manually only when I need to redefine the PURGE command.
When I open a new file I would use the original command of autocad.
Unfortunately, however, the commands are unknown in this case  :cry:

Also: there is a lisp function that restores the original command in AutoCAD?

PKENEWELL

  • Bull Frog
  • Posts: 319
Re: Problem with redefining command
« Reply #3 on: July 26, 2012, 03:40:31 PM »
Try This:

Code: [Select]
(command "_.REDEFINE" "_purge")
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt

Lupo76

  • Bull Frog
  • Posts: 343
Re: Problem with redefining command
« Reply #4 on: July 26, 2012, 04:00:04 PM »
perfect,
I tried the command _.REDEFINE in google, but probably was using the wrong search terms.

thanks