lisp has stopped working

lisp has stopped working

Anonymous
Not applicable
768 Views
4 Replies
Message 1 of 5

lisp has stopped working

Anonymous
Not applicable

I have an interesting problem here. Attached is a lisp I created to help draw roof obstructions for laying out solar arrays. The lisp was working fine until yesterday and will continue to work if I use another lisp before it. I think it's having trouble loading the (vl-load-com) command but I'm unsure how to fix it.

 

Here is what the command line says:

 

Command: obs .undo Current settings: Auto = On, Control = All, Combine = Yes,
Layer = Yes
Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back]
<1>: begin
Command: Unknown command "OBS".  Press F1 for help.
; error: bad argument type: VLA-OBJECT nil
Command:
Command:
Command: _vlide
Command:
Command:
Command:
Command: obs
Layer "FireSetBack" already exists.
Unknown command "OBS".  Press F1 for help.
; error: bad argument type: VLA-OBJECT nil

 

please help

0 Likes
Accepted solutions (2)
769 Views
4 Replies
Replies (4)
Message 2 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

Personally, I always pull (vl-load-com) outside a command definition [either before or after], because you want it done when you load the file [in case it hasn't been done already by something else], but that needs to happen only once, and there's no point in having it done every time you run the command.

 

I think the problem [or one problem] is in this portion:

 

(cond
  (if (tblsearch "LAYER" "FireSetBack")
  (setq OldLayer (getvar "CLAYER"))
(setq OldLayer (getvar "CLAYER"))
   (command "_layer" "n" "FireSetBack" "" ""))
  );cond

 

The last "" Enter at the end of the Layer command is after the Layer command has ended, and that is probably what is causing the Unknown-command errors -- Enter is recalling the last entered command, which was OBS, but inside a (command) function like that it won't recognize custom command names, only native AutoCAD command names.

 

But in addition, that part is not constructed properly.  If I understand what it's meant to do, I think it should be like this:

 

(if (tblsearch "LAYER" "FireSetBack")
  (setq OldLayer (getvar "CLAYER")); then
  (progn ; else -- wrap multiple operations into one argument in a (progn) function

    (setq OldLayer (getvar "CLAYER"))
    (command "_layer" "n" "FireSetBack" "")

  ); progn
); if

 

I would probably pull that setting of the OldLayer variable outside there, anyway, since if it's going to happen regardless, it's not dependent on the result of the test in the (if) function, so you may as well spell it out only once.

Kent Cooper, AIA
Message 3 of 5

hmsilva
Mentor
Mentor
Accepted solution

Hi vivifira,

your code, quickly revised...

 

Hope this helps,
Henrique

EESignature

Message 4 of 5

Anonymous
Not applicable

Thanks you both for your assistance on this. Your code works great Henrique. I was just wondering why it works when I run my other lisp.

0 Likes
Message 5 of 5

hmsilva
Mentor
Mentor

@Anonymous wrote:

Thanks you both for your assistance on this. Your code works great Henrique. I was just wondering why it works when I run my other lisp.


You're welcome, vivifira!
Glad I could help.

Attached your code with some annotations.

Your code first error, is because 'acdoc' variable is not set yet, when you are trying to access 'layer collection' from 'acdoc...

If you run your code affter other code set 'acdoc' as a global variable, your code will run without the '; error: bad argument type: VLA-OBJECT nil' error

 

Hope this helps,
Henrique

EESignature

0 Likes