Creating a hatch into a closed polyline with LISP

Creating a hatch into a closed polyline with LISP

Anonymous
Not applicable
1,818 Views
5 Replies
Message 1 of 6

Creating a hatch into a closed polyline with LISP

Anonymous
Not applicable

Dear all,

 

I want to create a hatch inside a closed polyline with Lisp. Unfortunaly it won't work. My Lisp Code:

 

(defun FKT:ARROW ()

(command "_.pline" '(0 150) '(600 0) '(0 -150) "_c" "")

(setq ENT (entlast))

(command "_hatch" "SOLID" ENT "")

);defun

 

I use AutoCAD 2017. Thanks for all your help.

0 Likes
Accepted solutions (1)
1,819 Views
5 Replies
Replies (5)
Message 2 of 6

j.palmeL29YX
Mentor
Mentor
Accepted solution

This works here:

(defun c:arrow	(/ ent)
  (command "_.pline" '(0 150) '(600 0) '(0 -150) "_c" "")
  (setq ENT (entlast))
  (command "_hatch" "SOLID" ENT "")
  (princ)
)

Jürgen Palme
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 3 of 6

Kent1Cooper
Consultant
Consultant

If you want to use FKT:ARROW as a command you can type in, put a C: before the name:

  (defun C:FKT:ARROW ()

If not, you must use it by entering the function name with enclosing parentheses:

  (FKT:ARROW)

Kent Cooper, AIA
Message 4 of 6

Anonymous
Not applicable

Heureka! - Thanks so much, it works :).

0 Likes
Message 5 of 6

Anonymous
Not applicable

May can you explain me in addition, why does it works this way? What is the meaning of the command (princ) in this case and why do I have to enter the Symbol ENT inside the brackets behind the slash? Thanks for your support!

0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

May can you explain me in addition, why does it works this way? What is the meaning of the command (princ) in this case and why do I have to enter the Symbol ENT inside the brackets behind the slash? Thanks for your support!


 

Neither of those is what makes it work.  It's the c: before the command name that makes it work.

 

The (princ) is referred to as "quiet exit" so that you don't see nil at the Command line after you run it -- see Help about that and (prin1) and (print).  AutoLisp functions/command-definitions return the last thing in them at the end.  This command definition ends with a (command) function, which always returns nil, and that will appear at the Command line and confuse some people if it isn't squelched by ending with a function that does nothing and returns nothing.

 

The (/ ent) is "localizing variables" -- see Help for the (defun) function.  It's not essential, but good practice, and depending on your use of variable names, could prevent different routines interfering with each other.

Kent Cooper, AIA