Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

GRREAD Learning Curve

8 REPLIES 8
Reply
Message 1 of 9
scot-65
649 Views, 8 Replies

GRREAD Learning Curve

I have the following statement which allows the user to continue

selecting a point on the screen until an entity is selected:

 

(while (not (setq a (entsel "\n Select object to array: "))))

 

However this is inside a larger loop where the intention is to

select [Enter] that would allow the user to terminate the program.

 

It looks like GRREAD is the solution, however I am not fluent with this.

 

I need the ability to continue looping until an entity is found

or exit the loop by either right-click of the mouse or [Enter]

on the keyboard.

 

Any help would be appreciated.

 

Scot-65

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


8 REPLIES 8
Message 2 of 9
Kent1Cooper
in reply to: scot-65


@scot-65 wrote:

.... 

It looks like GRREAD is the solution, however I am not fluent with this.

 

I need the ability to continue looping until an entity is found

or exit the loop by either right-click of the mouse or [Enter]

on the keyboard.

....


I think what you really want is to evaluate the ERRNO System Variable, because it can give feedback about object selection.  I'm not sure about making it work with right-clicking, but if it's good enough for Enter/space to end it, here's one way that can be done:

 

...
  (while (not done)
    (setvar 'errno 0)
    (setq esel (entsel "\nSelect {...whatever...}, or <exit>: "))
    (if
      (and
        (= (getvar 'errno) 0); picked on something
        (setq ent (car esel) edata (entget ent))
        (....test other things about the selected object, e.g. entity type, unlocked Layer, etc. ....)
      ); and
      (progn ; then for outer if [valid object selected]
        (command "_.undo" "_begin")
        ; ....do whatever it is you want to do....
        (command "_.undo" "_end")
      ); progn
      (if (= (getvar 'errno) 52); else for outer if

        (setq done T); inner then -- errno=52 if Enter/space at (entsel) prompt; stops (while)
        (prompt "\nNothing selected, or not {whatever criteria} --"); inner else --

          ; errno=7 if missed pick, but also ends up here if validity tests fail
      ); inner if [else for outer if]
    ); outer if
  ); while
....

Kent Cooper, AIA
Message 3 of 9
scot-65
in reply to: Kent1Cooper

I have restructured what I have to include a keyword to eXit,

however this solution is not what I really want to do, and it

sticks when the user either misses the entity or right-click,

and then tries to eXit:

 

    (initget "eXit")
    (while (not (setq a (entsel "\n Select object to array or [eXit]: "))))

 

?


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 4 of 9
dbroad
in reply to: scot-65


@scot-65 wrote:

    (initget "eXit")

    (while (not (setq a (entsel "\n Select object to array or [eXit]: "))))


(initget "eXit")
(while
(and
(setq a (entsel "\n Select object to array or [eXit]: "))
(/= a "eXit"))
;;body of while loop...
)

Architect, Registered NC, VA, SC, & GA.
Message 5 of 9
Kent1Cooper
in reply to: scot-65


@scot-65 wrote:

I have restructured what I have to include a keyword to eXit,

....


I confess to being curious as to why you would want a keyword for exiting a routine like that.  It requires the user to type both the X and Enter/space, whereas if you let Enter/space end it with something like that ERRNO check, they can do the same without being required to type the X.  You may as well spare them the eXtra keystroke.

 

I can see using a keyword for that, if eXiting is one among several options they might choose, and Enter needs to be reserved for their accepting an offered default option:

 

(initget "Some OTher OPtions eXit")

(while

  (and

    (setq a (entsel "\n Select object to array or [Some/OTher/OPtions/eXit] <Some>: "))

....

Kent Cooper, AIA
Message 6 of 9
dbroad
in reply to: dbroad

In addition to what Kent said, the initget is in the wrong place.  It will only work the first time through the loop if it is outside the loop.  Since entsel returns nil if nothing is picked, only a prompt change would be needed. "Select object to array or enter to exit:"

 

(while
(and
(not(initget "eXit"))
(setq a (entsel "\n Select object to array or [eXit]: "))
(/= a "eXit"))
;;body of while loop...
)

 

Architect, Registered NC, VA, SC, & GA.
Message 7 of 9
Kent1Cooper
in reply to: dbroad


@dbroad3 wrote:

In addition to what Kent said, the initget is in the wrong place.  It will only work the first time through the loop if it is outside.... 

(while
  (and
    (not(initget "eXit"))
    (setq a (entsel "\n Select object to array or [eXit]: "))
....


Right you are, and somewhere in the back of my mind, I knew that.  I have some routines that do just that, with the (not) wrapper around the (initget) function because (initget) returns nil, so you need the (not) around it to switch the return to T and keep the (and) function going, and you need the (initget) inside the (while) loop so it applies to the (entsel) function every time through.

Kent Cooper, AIA
Message 8 of 9
scot-65
in reply to: dbroad

DBroad was the closest.

 

The initget was placed inside.

This is the final snippet:

 

    (while (and (not (initget "eXit"))
                (not (setq a (entsel "\n Select object to array or [eXit]: ")))));while
    (if (and a (= a "eXit")) (setq a nil sd 0) );if
 

The above snippet will allow the user to continue selecting a point on the

screen until an entity is found or to terminate the program.

[the "and a" protects the use of "Esc" on the keyboard, my attention to details].

 

What is this used for?

I am developing a program that has a dialog interface.

The program is to array an arched brick soldier (or rowlock) on a building's elevation.

The dialog sets up the brick spacing, option for color or layer direct of the array object,

select an object to array, choose array direction ccw/cw, and finally select the (bottom) ARC.

Once this is done, the routine will repeat the Select Object and Select Arc steps without

the dialog interface until the "eXit" option is used.

I was hoping for [Enter]/right-click and not "eXit" - that's why the post.

 

Scot-65

 


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 9 of 9
dbroad
in reply to: scot-65

Scot,

What version are you using? Seems like the path array object in Autocad 2012 and 2013 would be easier to use and adjustable after the fact.

Architect, Registered NC, VA, SC, & GA.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost