Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*Expert Elite*
scot-65
Posts: 2,163
Registered: ‎12-11-2003
Message 1 of 9 (357 Views)

GRREAD Learning Curve

357 Views, 8 Replies
10-02-2012 08:54 AM

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
Dyslexia is a permanent physical disability that cannot be seen.
Introverts is proof that there is indeed intelligent life on this planet.
*Expert Elite*
Kent1Cooper
Posts: 5,393
Registered: ‎09-13-2004
Message 2 of 9 (346 Views)

Re: GRREAD Learning Curve

10-02-2012 09:48 AM 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
*Expert Elite*
scot-65
Posts: 2,163
Registered: ‎12-11-2003
Message 3 of 9 (318 Views)

Re: GRREAD Learning Curve

10-02-2012 03:37 PM 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
Dyslexia is a permanent physical disability that cannot be seen.
Introverts is proof that there is indeed intelligent life on this planet.
*Expert Elite*
dbroad
Posts: 1,551
Registered: ‎08-16-2007
Message 4 of 9 (275 Views)

Re: GRREAD Learning Curve

10-03-2012 06:00 AM 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...
)

*Expert Elite*
Kent1Cooper
Posts: 5,393
Registered: ‎09-13-2004
Message 5 of 9 (272 Views)

Re: GRREAD Learning Curve

10-03-2012 06:15 AM 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
*Expert Elite*
dbroad
Posts: 1,551
Registered: ‎08-16-2007
Message 6 of 9 (263 Views)

Re: GRREAD Learning Curve

10-03-2012 06:43 AM 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...
)

 

*Expert Elite*
Kent1Cooper
Posts: 5,393
Registered: ‎09-13-2004
Message 7 of 9 (257 Views)

Re: GRREAD Learning Curve

10-03-2012 08:26 AM in reply to: dbroad

dbroad 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
*Expert Elite*
scot-65
Posts: 2,163
Registered: ‎12-11-2003
Message 8 of 9 (236 Views)

Re: GRREAD Learning Curve

10-03-2012 03:45 PM 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
Dyslexia is a permanent physical disability that cannot be seen.
Introverts is proof that there is indeed intelligent life on this planet.
*Expert Elite*
dbroad
Posts: 1,551
Registered: ‎08-16-2007
Message 9 of 9 (231 Views)

Re: GRREAD Learning Curve

10-03-2012 05:04 PM 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.

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.