Jump to content

help on cond and repeating command


Lt Dan's legs

Recommended Posts

Just trying to figure out how to do this..

 

(defun C:test (/)
(setq ss (ssget))
(command "_.erase" ss "")
(setq p1 (getpoint "\n**First point**"))
(setq p2 (getpoint p1 "\n**Second point**"))
(command "_.line" p1 p2 nil)
(setq opt (strcase (getstring "\NRepeat Last Command <Yes or No>: ")))
(cond  ((or(= opt "Y")(= opt "YES"))(prompt "\nrepeat last command"))
[color=red];;instead of prompting repeat last command I want it to actually repeat it[/color]
          (T (prompt "\nExiting command"))
 )
(princ)
)

Link to comment
Share on other sites

  • Replies 27
  • Created
  • Last Reply

Top Posters In This Topic

  • Lt Dan's legs

    11

  • alanjt

    6

  • rkmcswain

    5

  • Lee Mac

    5

Top Posters In This Topic

Posted Images

Is this what you are trying to accomplish?

 

(defun c:Test (/ ss p1 p2)
 (if (setq ss (ssget "_:L"))
   (progn
     (command "_.erase" ss "")
     (while (and (setq p1 (getpoint "\nSpecify first point: "))
                 (setq p2 (getpoint p1 "\nSpecify second point: "))
            )
       (command "_.line" "_non" p1 "_non" p2 "")
     )
   )
 )
 (princ)
)

Link to comment
Share on other sites

Not sure exactly which part you want to repeat, but here is one way....

 


(defun C:test (/)
 (setq ss (ssget))
 (command "_.erase" ss "")
 (setq wait T)
 (while wait
   (setq p1 (getpoint "\n**First point**"))
   (setq p2 (getpoint p1 "\n**Second point**"))
   (command "_.line" p1 p2 nil)
   (initget 1 "Y N")
   (setq opt (getkword "\nRepeat Last Command [Yes or No]: "))
   (if (eq "N" opt)
     (setq wait nil)
   )
 )  
 (princ)
)

Link to comment
Share on other sites

Not sure exactly which part you want to repeat, but here is one way....

 


(defun C:test (/)
 (setq ss (ssget))
 (command "_.erase" ss "")
 (setq wait T)
 (while wait
   (setq p1 (getpoint "\n**First point**"))
   (setq p2 (getpoint p1 "\n**Second point**"))
   (command "_.line" p1 p2 nil)
   (initget 1 "Y N")
   (setq opt (getkword "\nRepeat Last Command [Yes or No]: "))
   (if (eq "N" opt)
     (setq wait nil)
   )
 )  
 (princ)
)

 

Looks like you have it. I'll test after lunch.

Link to comment
Share on other sites

For initget

use

 (initget 1 "Y N")
(setq opt (getkword "\nRepeat Last Command [Yes[color=red]/[/color]No]: "))

 

Instead of

 (initget 1 "Y N")
(setq opt (getkword "\nRepeat Last Command [Yes[color=red] or[/color] No]: "))

 

To show a menu (see attached)

Repeat.PNG

Link to comment
Share on other sites

okay I give!!

 

how would I retrieve a block rotation?

(setq ss (ssget "_:s" '((0 . "insert"))))
;;not really knowledgeable on assoc or car functions
;;I did find that rotation = 50

Link to comment
Share on other sites

1) Check for a valid SelSet:

 

(if (setq ss (ssget '((0 . "INSERT"))))
...

 

2) Iterate through the SelSet:

 

Most intuitive is probably something like:

 

(setq counter 0)
(repeat (sslength ss)
 (setq ent (ssname ss counter))
 ...
 (setq counter (1+ counter))
)

 

3) Query the rotation of each entity:

 

(cdr (assoc 50 (entget ent)))

Link to comment
Share on other sites

Most intuitive is probably something like:

 

(setq counter 0)
(repeat (sslength ss)
 (setq ent (ssname ss counter))
 ...
 (setq counter (1+ counter))
)

 

3) Query the rotation of each entity:

 

(cdr (assoc 50 (entget ent)))

 

 

Thank you sir

Link to comment
Share on other sites

It will be in radians.

 

putting the puzzle together

(defun c:test (/ ss counter ent en)
 (setq ss (ssget "_:s" '((0 . "insert"))))
 (setq counter 0)
 (repeat (sslength ss)
  (setq ent (ssname ss counter))
  (setq en (cdr (assoc 50 (entget ent))))
  (setq counter (1+ counter))
  )
 (setq pt (getpoint "\nSpecify Insertion point: "))
 (command "-insert" ent pt "" "" en)
 (princ)
)

I see the problem. I just don't know how to get to the solution... What should I be looking for to get my result?

Link to comment
Share on other sites

As you are dealing with a single block, there is no need to iterate through the selection set in this case - but, you should check for a valid selection as I pointed out.

 

With a single selection you could use ssget with "_:S" as you have, or just use a simple 'entsel' call.

 

Your angle will be in radians, hence you will need to convert it to degrees if you want to use it in a command call. This sub should help in that matter:

 

(defun RtoD ( x )
 (* 180. (/ x pi))
)

Link to comment
Share on other sites

Your angle will be in radians, hence you will need to convert it to degrees if you want to use it in a command call.

 

Or you can add an "r" suffix to specify radians in a command. (i.e.: 1.5r)

Link to comment
Share on other sites

Ooo I didn't know that! Thanks RK :)

 

Of course, if you were going to do that, you would have to convert the radians to a string anyway.... But it can be useful if you are testing something at the command line and you want to enter radians...

Link to comment
Share on other sites

Of course, if you were going to do that, you would have to convert the radians to a string anyway.... But it can be useful if you are testing something at the command line and you want to enter radians...

Yeah, it's a neat trick, but for code, it seems like it's safer to just convert to degrees then to a string (remove any possibilities of rounding errors).

Link to comment
Share on other sites

Yeah, it's a neat trick, but for code, it seems like it's safer to just convert to degrees then to a string (remove any possibilities of rounding errors).

 

 

It's not a trick, AutoCAD was designed to accept "r" for radians, "g" for grads, d for degrees, etc.

 

As far as code goes, I try to avoid converting anything.

If you do though, you can do it in one step using (angtos), but I don't see how this avoids rounding errors.

Link to comment
Share on other sites

It's not a trick, AutoCAD was designed to accept "r" for radians, "g" for grads, d for degrees, etc.

 

As far as code goes, I try to avoid converting anything.

If you do though, you can do it in one step using (angtos), but I don't see how this avoids rounding errors.

Sorry, 'trick' was the wrong choice of words.

 

I meant if one was the convert the radians to a string, then append "R" to it, you could/would open yourself up to rounding issues.

 

I wouldn't convert either, but if one is so inclined to use command, they are forced to feed it degrees or append "R" as you shown.

Link to comment
Share on other sites

Sorry, 'trick' was the wrong choice of words.

 

I meant if one was the convert the radians to a string, then append "R" to it, you could/would open yourself up to rounding issues.

 

I wouldn't convert either, but if one is so inclined to use command, they are forced to feed it degrees or append "R" as you shown.

 

How would you go about making this, Alan? I'm not wanting the full code. Just the function to insert the same block you select.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...