how to end object selection in autolisp

how to end object selection in autolisp

Anonymous
Not applicable
1,593 Views
6 Replies
Message 1 of 7

how to end object selection in autolisp

Anonymous
Not applicable

Hi,

Very new to autolisp.  Very simple question here frustrating the heck out of me.

 

I am trying to select all objects.   It selects all objects but I cannot figure out how to tell it I am done selecting.   In commandline you just press enter and that tells it you are done selecting, but in autolisp it doesnt work

 

I have tried all of the following;

(command "_SELECT" "ALL" "")

(command "_SELECT" "ALL" " ")

(command "_SELECT" "ALL" "" "")

(command "_SELECT" "ALL" "\n")

(command "_SELECT" "ALL" "\r")

(command "_SELECT ALL \n\n")

 

None of those work.   In all cases it says "Expects a point or Window/Last/Crossing/BOX/ALL/Fence/WPolygon/CPolygon/Group/Add/Remove/Multiple/Previous/Undo/AUto/SIngle/SUbobject/Object

Autolisp error: Function cancelled"

 

It then ends the function and command line resumes with a prompt to continue selecting objects

 

How to convince it that I am really done selecting objects?

 

Thanks

 

 

 

1,594 Views
6 Replies
Replies (6)
Message 2 of 7

RedMan77
Collaborator
Collaborator

Maybe we can see your full code for the routine so we can see what you are trying to do to ensure the proper syntax is being used.

0 Likes
Message 3 of 7

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

I am trying to select all objects.   It selects all objects but I cannot figure out how to tell it I am done selecting.   In commandline you just press enter and that tells it you are done selecting, but in autolisp it doesnt work

 

I have tried all of the following;

(command "_SELECT" "ALL" "")

.... 

None of those work.   In all cases it says "Expects a point or .... 

How to convince it that I am really done selecting objects?

.... 


That first one works for me.  Check whether it's giving you that error message in response to the "ALL" or the "" -- might it be a question not of how to tell it you're done, but possibly that somehow it's not accepting the "ALL" as input, that is, the first part is the problem, not the last part?.  In case there might be an undefinition and new definition of the Select command involved, or a language-version issue, try forcing the native command definition [the period prefix] and covering the other-than-English-version possibility for the All option:

(command "_.SELECT" "_ALL" "")

Kent Cooper, AIA
0 Likes
Message 4 of 7

hmsilva
Mentor
Mentor

@Anonymous wrote:

...

 In commandline you just press enter and that tells it you are done selecting, but in autolisp it doesnt work


Hi jdwpv4,

 

try this demo

 

(defun c:demo (/ echo)
  (setq echo (getvar 'CMDECHO))
  (setvar 'CMDECHO 1)
  (command "_SELECT" "_ALL" "")
  (setvar 'CMDECHO echo)
  (princ)
)

 

if it works as expected, you must ensure CMDECHO is '1' when you call the 'select command.

 

Hope this helps,
Henrique

 

EESignature

0 Likes
Message 5 of 7

Anonymous
Not applicable

Hi All,

 

Thank you for your replies.  I found the problem; Redman was the closest to the answer.    The problem was in another command. 

 

What I was trying to accomplish was to blank the entire drawing.  So following the select all command was an erase command.   If you were using autocad in the command line the commands would have been

 

SELECT

ALL

ERASE

 

and of course in autocad that will select everything and erase them.    However evidently AutoLisp does not emulate autocad faithfully. 

 

I had

(command "_SELECT" "ALL" ""

   "ERASE"

)

 

It turns out that it was the ERASE that was causing the problem.   Evidently AutoLisp does not understand that the ERASE command is to operate on the selection set of the previous line.   ERASE was expecting its own selection.

 

I changed it to

(command "_SELECT" "ALL" ""

"ERASE" "ALL" ""

)

 

and that worked.   Of course that made the select command redudant, so I then changed it to

 

(command "ERASE" "ALL" "")

 

And all is happy. 

 

Thanks for your time!

0 Likes
Message 6 of 7

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

What I was trying to accomplish was to blank the entire drawing.  So following the select all command was an erase command.   If you were using autocad in the command line the commands would have been

 

SELECT

ALL

ERASE

 

and of course in autocad that will select everything and erase them.  ....

 

....   Evidently AutoLisp does not understand that the ERASE command is to operate on the selection set of the previous line.   ERASE was expecting its own selection.

....


SELECT does not leave everything selected/highlighted.  It only puts things into what becomes the Previous selection.  Your command-line usage example does not work for me.  If I type Erase immediately after typing All, it's still waiting for further selection, and the word "erase" is invalid for that.  If I complete the selection with another Enter after giving it the All option, it goes back to the Command: prompt, and a following Erase command has no relationship to the Select results unless given the Previous option.

 

If you select everything with a big window rather than using a Select command, and then [with everything highlighted] type Erase, it will do it [assuming you have the PICKFIRST System Variable set appropriately].

 

You are quite correct that "AutoLisp does not understand that the ERASE command is to operate on the selection set of the previous line," because your code did not tell it to, and that Erase expects its own selection.  The correct construction [I'm not suggesting you use it here, but if you find some other application in which using Select first is appropriate] would be:

 

(command

  "_SELECT" "ALL" ""

  "ERASE" "P" ""

)

Kent Cooper, AIA
0 Likes
Message 7 of 7

RedMan77
Collaborator
Collaborator

Glad I could help if only in a small way.  Most of my issues are syntax issues.  I am still learning. 

0 Likes