trying to understand the lisp logic

trying to understand the lisp logic

GeryKnee
Advocate Advocate
965 Views
15 Replies
Message 1 of 16

trying to understand the lisp logic

GeryKnee
Advocate
Advocate

The following code seems to have serious errors but i can't understand where the code is crashing:


(vl-load-com)


(defun fnInsertOnInsP ( BlockName )
(if
(setq pt (getpoint "\nSpecify insertion point: "))
(command "_.-insert" (strcat "*" BlockName) "_NONE" pt "" "")
)
)

 


(defun c:xx ( / BlockName)
(setq cmde (getvar "cmdecho"))
(setvar "cmdecho" 0)
(if (setq BlockName getString( "\nSpecify block name: "))
(progn
(fnInsertOnInsP BlockName)
(command "_.layer" "F" "1" "")
)
)
(setvar "cmdecho" cmde)
)

 

0 Likes
Accepted solutions (2)
966 Views
15 Replies
Replies (15)
Message 2 of 16

-didier-
Advisor
Advisor
Accepted solution

Bonjour @GeryKnee 

 

a good habit to take is to use bbcode to format code on the forum.

this being said I think the error comes from layer "1" whose existence is not checked by the code.

I don’t quite understand what the purpose is of freezing layer 1 but I propose this solution to keep the spirit of the program

(vla-load) : this command is useless in "pure" Autolisp

Amicalement

 

(defun fnInsertOnInsP (BlockName)
  (if
    (setq pt (getpoint "\nSpecify insertion point: "))
     (command "_.-insert" (strcat "*" BlockName) "_NONE" pt "" "")
  )
)

(defun c:xx (/ BlockName)
  (setq cmde (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  (if (setq BlockName (getString "\nSpecify block name: "))
    (progn
      (fnInsertOnInsP BlockName)
      (if (not (tblsearch "layer" "1"))
        (command "_.layer" "_N" "1" "_F" "1" "")
        (command "_.layer" "_F" "1" "")
        )
    )
  ) 
  (setvar "cmdecho" cmde)
)
Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

Message 3 of 16

Kent1Cooper
Consultant
Consultant

Do you use this when Layer 1 is the current Layer?  That would cause trouble, since the current Layer can't be frozen.

 

@-didier- 's suggestion, that the problem might be not checking whether Layer 1 exists, I think is not valid, because a Layer command can be given the name of a non-existent Layer for many of the options without any problem -- a message will go by that it didn't find any matching Layer name(s), but it will just return to the main Layer prompt.

Kent Cooper, AIA
Message 4 of 16

GeryKnee
Advocate
Advocate

I try to undestand the lisp logic.

And also, I try to write some routines to automate my work.

Of course, if a layer not exists, or if the routine is full of unexpected errors those will be caused the time proccedure called , during the code execution , must be refernced at this time.

But if there's not syntax error, the language checker (the autocad system) must continue loading the .lsp file instead of ignore the next codes.

Thank you very much for your help Sir,

Regards,

Gery.

 

0 Likes
Message 5 of 16

GeryKnee
Advocate
Advocate

Hello Kent,

As i answered to -didier- , the problem is not what happens during the execution.

The problem is that the lisp language checker cancels the defun and any other following, at the time the .lsp file is embedding lisp commands to autocad system.

That's an abnormal logic of interpreeter.

Anyway, after the code replaced by -didier- update, interpreetes embedds it normaly.

Thanks,

Gery.

0 Likes
Message 6 of 16

-didier-
Advisor
Advisor

Bonjour @GeryKnee 

 

a parenthesis seems to be the cause of the malfunction

 

Snag_1034de1b.png

Does it work better when modified?

 

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

0 Likes
Message 7 of 16

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

The following code seems to have serious errors but i can't understand where the code is crashing:

....

  (if (setq BlockName getString( "\nSpecify block name: "))

....


[He got in before me by a minute, but anyway....]  That would be the problem.  The left parenthesis that is after the word getString should be before it.  See whether only that correction also fixes it for you.

Kent Cooper, AIA
0 Likes
Message 8 of 16

GeryKnee
Advocate
Advocate

Sorry Sir,

I added after your code the following :


(defun c:xxxx(/)
(command "xx") ;; your code
(princ)
)

 

and i get the answer

xx Unknown command "XX". Press F1 for help.

How sould I call the xx from another defun ??

Thanks,

Gery.

0 Likes
Message 9 of 16

Kent1Cooper
Consultant
Consultant
Accepted solution

@GeryKnee wrote:

....

I added after your code the following :


(defun c:xxxx(/)
(command "xx") ;; your code
(princ)
)

 

and i get the answer

xx Unknown command "XX". Press F1 for help.

How sould I call the xx from another defun ??

....


You can use AutoLisp (command) functions only with actual AutoCAD native command names.  The way to run a (defun C:...)-defined command is this:

 

(C:XX)

Kent Cooper, AIA
Message 10 of 16

GeryKnee
Advocate
Advocate

Yes,

Exactly that is the reason.

Thanks.

So, i need a compiler to look for those errors.

Is there any compiler for lisp to check errors???

0 Likes
Message 11 of 16

GeryKnee
Advocate
Advocate

OK Kent.

The road to learn lisp is difficult.

I remenber my life 40 years ago when started pascal.

But i used to continue walk on hard roads. 

Thank you for your help.

Gery.

0 Likes
Message 12 of 16

Moshe-A
Mentor
Mentor

@GeryKnee ,

 

AutoLISP is based on an interpreter module that check for syntax errors at load\run time and that's include missing or miss placed opening/closing parentheses. 

 

so calling the (command) function as you did is legal syntax until it is run by the interpreter.

 

Moshe

 

  

Message 13 of 16

GeryKnee
Advocate
Advocate

Thanks Moshe-A,

Maybe a promoted visual lisp environment for writing and checking lisp routines is necessary.

regards,

Gery.

0 Likes
Message 14 of 16

Kent1Cooper
Consultant
Consultant

@GeryKnee wrote:

.... Maybe a promoted visual lisp environment for writing and checking lisp routines is necessary. ....


Read about the >VLISP command<.

Kent Cooper, AIA
0 Likes
Message 15 of 16

Sea-Haven
Mentor
Mentor

A lot of us use NOTEPAD++ it is a text editor with a lot of options one being it recognises lisp and dcl, it will show you bracket pairs so very helpful, with errors like your getstring ( correctgetstring . There is the ability to type code and then run it using the attached lisp.

 

The obvious also is to use VLIDE when debugging your code it has various error indicators.

 

There are multiple tutorials how to use Lee-mac.com has a good one.

0 Likes
Message 16 of 16

GeryKnee
Advocate
Advocate

Hello Sea.Heaven.

Can you Inform me how it works??

The Steps of instalation and how i'll use it.

Thanks,

Gery.

 

0 Likes