Hatch Target lisp

Hatch Target lisp

Anonymous
Not applicable
4,149 Views
8 Replies
Message 1 of 9

Hatch Target lisp

Anonymous
Not applicable
Hello, I'm trying to wright a lisp to hatch a target for class. I can't get it to work. here is my script. (defun C:Target () ;capture current environment variables (setq ce (getvar "cmdecho")) ;suppress command echo (setvar "cmdecho" 0) ;get start point and draw Inner circle (setq cp (getpoint "\nCenter point: ")) (command "circle" cp "D" "0.5" ) ;draw second circle (command "circle" cp "D" "1" ) ;draw outer Circle (command "circle" cp "D" "1.5" ) ;Hatch Target (command "hatch" "ansi31" "1" "0" "@" "0.25" "@" "0.25" "@" "0.25" ) ;restore environment (setvar "cmdecho" ce) ;silent exit (princ) ) is this right? it will create the target, but it will not hatch...
0 Likes
Accepted solutions (2)
4,150 Views
8 Replies
Replies (8)
Message 2 of 9

krzysztof.psujek
Advocate
Advocate

Hi,

Firstly you should format your code - to make it easy to read.

Please use {i} insert code - before posting.

 

Secondary:It will be much better if you will more focus on the result you want to.

I mean made better description of what you are expecting the macro will do.

 

I've changed your code but not sure if it is what you wanted.

 

(defun C:Target	(/ ce cp)		
  (setq ce (getvar "cmdecho"))		;capture current environment variables
  (setvar "cmdecho" 0)			;suppress command echo
  (setq cp (getpoint "\nCenter point: "));get start point and draw Inner circle
  (command "_circle" cp "_D" 0.5)	
  (command "_circle" cp "_D" 1)		;draw second circle
  (command "_circle" cp "_D" 1.5)	;draw outer Circle
  (command "_.-hatch"  "_p"   "ansi31"   0.25   0   "_s" (entlast)  ""  "" );Hatch Target
  (setvar "cmdecho" ce)			;silent exit
  (princ)
)

Chris

0 Likes
Message 3 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:
.... ;Hatch Target (command "hatch" "ansi31" "1" "0" "@" "0.25" "@" "0.25" "@" "0.25" ) ....

Welcome to these Forums!

 

Your Hatch command is questionable about selection of those Circles to Hatch them.  If these entries:

 

"@" "0.25" "@" "0.25" "@" "0.25"

 

are supposed to be object selection, it's a peculiar way to do it, the first "@" entry won't find a Circle because it will be at the center, and could find something other than one of the Circles, the other "@" entries don't add anything, and the "0.25" entries work with the direction toward the cursor at the time, so what if it remains at the center location [no direction]?  Try:

 

"@0.25,0"

 

three times instead, or

 

"@0,0.25"

 

or

 

"@0.25<0"

 

or any valid point designation that's sure to land on the Circles.  And finally, you don't complete the selection of items to Hatch -- you need an Enter "" to do that.  Try something like this [untested]:

 

(command "hatch" "ansi31" "1" "0" "@0.25,0"  "@0.25,0" "@0.25,0" "")

 

[And by the way, that's not a "script" -- that word has a specific and different meaning in AutoCAD.]

Kent Cooper, AIA
0 Likes
Message 4 of 9

Anonymous
Not applicable
Hello Chris,

As you can see from my post my name is Eric Simpson.
I am currently going to Bakersfield College to learn AutoDesk.
My goal is to get employment in the CAD industry.
I have been an artist since the day I was born in 1972.
I remember the first Apple computer.
When I was in the 6th grade we had one in our classroom.
I remember this silly program where you were a lemonade sales person...
Anyway,
High school is when they really started the whole computer thing.
Big floppy disk,
And aol.
Man I don't miss downloading anything in those days right...
In my mechanical drawing class when, I was in 10 grade, was the first time I saw a CAD program, about 1988 maybe.
Unfortunately as a 15 year old kid I had no clue what the future could have been if I would had focused my study's in that direction.

Well,
That's a little about me.

You,
I know nothing about you.
Your attitude or demeanor.
It may just be my ignorance to this whole script stuff.
I was just introduced to it Monday April 4,
In my CAD class.
Very recently.
I am still trying to get my head around it.

But, I'll have to tell you,
I'm not exactly sure how to take your "help"
I came off a little snide,
A little snippy maybe?

Now...

Firstly,

I should format my code -
To make it easy to read?

Ok,
Do you mean easer to read then this

defun C:Target (/ ce cp) (setq ce (getvar "cmdecho")) ;capture current environment variables (setvar "cmdecho" 0) ;suppress command echo (setq cp (getpoint "\nCenter point: "));get start point and draw Inner circle (command "_circle" cp "_D" 0.5) (command "_circle" cp "_D" 1) ;draw second circle (command "_circle" cp "_D" 1.5) ;draw outer Circle (command "_.-hatch" "_p" "ansi31" 0.25 0 "_s" (entlast) "" "" );Hatch Target (setvar "cmdecho" ce) ;silent exit (princ) )

???

I'm sure the software can read it with no problem,
As far as readable for me,
That's not very friendly now is it?
I'm writing my script per my instructor.
And that is all I can do for now.
We shall see what my script looks like in a few years, right...

"Please use {i} insert code - before posting"

I'm not sure what this is at all,
You weren't very clear what is at all.

I mean,
I can see you want my to use {i}
to insert code some where.
Insert a code on a help form,
Insert a code in to the CAD program?
I think you need to focus more on the results you are wanting from me.
Remember, I'm a little ignore to it all right now.

"It will be much better if you will more focus on the result you want to."

What are you telling me here?

More focus explaining to the AutoCAD community what I'm wanting my script to do?

If that is what you are saying,
I am truly sorry for that.
I guess I just figured that someone that have been writing scripts could look at it and have a pretty good idea what it is I was trying to achieve.
Basically I need a,
Inner circle,
A second circle,
And an outer circle.
You know like a "target".
Then I need to hatch it.
Inside circle being hatch,
Second circle no hatch,
Outer circle,
That right hatch.
If you've been to Targer lately,
Pull out a bag and look at it.

Thank you for making my code "better".

But I think I got it.

It was just this line,
(command "hatch" "ansi31" "1" "0" "@" "0.25" "@" "0.25" "@" "0.25")

It should have been
command "hatch" "ansi31" "1" "0" "@0,0.25" "@0,.025" "@0,0.25" "")
Explanation
I was off on my coordinate.
I didn't know how far I wanted to go over.
Silly computer...
Works like a top now.

I have to be honest with you Chris...
I know you can't judge a community on one person.
But...
Let's just say.
I had a predicament I was trying to find a solution for.
Not to be criticized on the way I write my script.
Not My ignorance to script,
How I address the community to ask a question.
Or the fact I have two dead bodies buried in my basement...
FYI.
This is California, we don't have basements.

I shall try to figure out what it is you are trying to relay to me
And "try" better next time.

Thank you,
Sincerely
Eric D. Simpson
0 Likes
Message 5 of 9

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:
....
I should format my code -
To make it easy to read?

Ok,
Do you mean easer to read then this

defun C:Target (/ ce cp) (setq ce (getvar "cmdecho")) ;capture current environment variables (setvar "cmdecho" 0) ;suppress command echo (setq cp (getpoint "\nCenter point: "));get start point and draw Inner circle (command "_circle" cp "_D" 0.5) (command "_circle" cp "_D" 1) ;draw second circle (command "_circle" cp "_D" 1.5) ;draw outer Circle (command "_.-hatch" "_p" "ansi31" 0.25 0 "_s" (entlast) "" "" );Hatch Target (setvar "cmdecho" ce) ;silent exit (princ) )

???

I'm sure the software can read it with no problem,
....
"Please use {i} insert code - before posting"

I'm not sure what this is at all,
....

Just to touch on those two:

 

If you were to put that code as it came through into a .lsp file, it would not work, i.e. no, the software would not be able to read it.  A semicolon is a "comment" marker, and it and everything following it on the same line will be ignored, which in this case includes a lot of your operational code.  And most lines start with elements that would be invalid as the beginning of a line of AutoLisp code.  And yes, the breakdown into logical lines also makes it easier, even for experienced code writers, to be able to discern what it's supposed to do.

 

I'm not sure why some people paste code in that's originally in separate lines but it comes out all strung into one continuous paragraphs like that -- it may be browser related or something.  But the following may be relevant:

 

The  { i } is the Insert-Code "button" on the tool bar [between the Spoiler and Emoticon buttons].  If you pick on it and paste your code into that window instead of into the "body" of a message, I think [I'm not positive this is true in all circumstances] that it will retain its line breakdown, solving the first issue at the same time.  It will also retain any indentation [which also sometimes disappears when pasting into the message body], which is also an aid to understanding code structure.

Kent Cooper, AIA
0 Likes
Message 6 of 9

krzysztof.psujek
Advocate
Advocate
Accepted solution

Hi Eric,
I was born in '83. I have wife, two kids,...and 13 years experience with AutoCAD.

I didn't want to offend you. If I did it - sorry for that.
Also maybe my English is so poor that my post sounds for you arrogant.
Belive me - That wasn't my purpose.

I only wanted to give you a clues to make your future posts more precise.
That will guarantee a better and probably quicker responds on it.
As you could see I didn't understand properly your problem but fortunately Kent1Cooper did.
So if you had spent a little more time to create your post you could get solution faster.

 

{i} - that was really poor description - sorry haven't seen then that you are a new member.

I've used it to format code in my post - so you could see the difference.

 

Anyway regards from Poland.
(and sorry for my English)
Chris

 

Message 7 of 9

Anonymous
Not applicable

I seem to be taking the same class as the first person who asked for help.  I have attached .jpg that shows the LISP code and another that shows what I need to accomplish in the way of inserting a hatch pattern into two different areas of the object.

 

The object is a bullseye target that can be set to any diameter selected.  I need to add hatch to the inner circle and one to the outer circle leaving the middle circle empty.

 

How can I accomplish this?

 

Appreciatively,

Jim

0 Likes
Message 8 of 9

DannyNL
Advisor
Advisor

Quick 'n dirty solution

 

(defun c:BullsEye (/ BE_Vars BE_Values BE_CenterPoint BE_Diameter BE_Selection)
   (setq BE_Values (mapcar 'getvar (setq BE_Vars '("CMDECHO" "OSMODE"))))
   (mapcar 'setvar BE_Vars '(0 0))
   (if
      (and
         (setq BE_CenterPoint (getpoint "\nCenter point: "))
         (setq BE_Diameter    (getreal  "\nDiameter    : "))
      )
      (progn
         (setq BE_Selection (ssadd))
         (command "_CIRCLE" BE_CenterPoint "D" BE_Diameter)
         (ssadd (entlast) BE_Selection)
         (command "_CIRCLE" BE_CenterPoint "D" (* BE_Diameter 2))
         (ssadd (entlast) BE_Selection)
         (command "_CIRCLE" BE_CenterPoint "D" (* BE_Diameter 3))
         (ssadd (entlast) BE_Selection)
         (command "-HATCH" "Properties" "ANSI31" "1.0" "0" "Advanced" "Island" "Yes" "Style" "Normal" "" "Select" BE_Selection "" "")
      )
   )
   (mapcar 'setvar BE_Vars BE_Values)
   (princ)
)
Message 9 of 9

Anonymous
Not applicable

DannyNL

 

Thanks for your quick response.  I should have posted the solution (at bottom) I came up with shortly after making my original post.  I changed it a little as I realized that the diameter dimension was for the inner circle and that would make the drawing object outside circle bigger by 3 times.  I actually wanted the outer circle to have the specified diameter.  This solution seems to accomplish what I wanted including restoring environments.

 

Again, I very much appreciate your response.  I most likely will ask for help again (probably many times!) down the road as I am just beginning to learn AUTOCAD.

 

(defun C:bullseyevar ()
	
	;capture current environment variables
	(setq ce (getvar "cmdecho"))
	(setq h1 (getvar "hpang"))
	(setq h2 (getvar "hpname"))
	(setq h3 (getvar "hpscale"))
	(setq c1 (getvar "circlerad"))
	
	;suppress command echo
	(setvar "cmdecho" 0)
	
	;get center point
	(setq cp1 (getpoint "\nSpecify center point: "))
	
	;get diameter
	(setq bdia (getreal "\nSpecify diameter: "))
	
	;set diameter of outer circle, draw circles, boundaries
	(command "circle" cp1 "D" (/ bdia 3))
	(setq x1 (ssget "l"))
	(command "circle" cp1 "D" (/ bdia 1.5))
	(setq x2 (ssget "l"))
	(command "circle" cp1 "D" bdia)
	(setq x3 (ssget "l"))
	
	;apply hatch pattern
	(command "hatch" "ansi31" 1 0 x1 x2 x3 "")
	
	;restore environments
	(setvar "cmdecho" ce)
	(setvar "hpang" h1)
	(setvar "hpname" h2)
	(setvar "hpscale" h3)
	(setvar "circlerad" c1)
	
	;silent exit
	(princ))
0 Likes