Can't call AI_SELALL command through Lisp

Can't call AI_SELALL command through Lisp

elias.kanellakis
Participant Participant
806 Views
12 Replies
Message 1 of 13

Can't call AI_SELALL command through Lisp

elias.kanellakis
Participant
Participant

Hi guys,

i can't call the AI_SELALL command via a Lisp.. I even wrote this simple code and still nothing:

 

(defun c:PRACTICE ()
(command "AI_SELALL")
(princ)
)

 

When i write AI_SELALL directly on the command line it works! But can't do it within a Lisp.. Does anyone know why?

0 Likes
Accepted solutions (3)
807 Views
12 Replies
Replies (12)
Message 2 of 13

pendean
Community Legend
Community Legend
0 Likes
Message 3 of 13

Kent1Cooper
Consultant
Consultant
Accepted solution

AutoLisp (command) functions can accept only native AutoCAD command names, and AI_SELALL is not one -- it's a custom AutoLisp command definition.  This is the way to invoke such a thing in AutoLisp:

 

(defun c:PRACTICE ()
  (C:AI_SELALL)
  (princ)
)

Kent Cooper, AIA
Message 4 of 13

paullimapa
Mentor
Mentor

Have you tried this 

(defun c:PRACTICE ()
(AI_SELALL)
)

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 13

elias.kanellakis
Participant
Participant
oh yes that works perfectly, thanks so much!
0 Likes
Message 6 of 13

Kent1Cooper
Consultant
Consultant

@paullimapa wrote:

Have you tried this 

.... (AI_SELALL) ....

; error: no function definition: AI_SELALL

 

It's definitely defined with the C: [i.e. as a command, not just a function], and needs to be invoked with that included [see Message 3].  You should be able to find the definition in the support files [in my Acad2020 here, it's part of acad2020doc.lsp, described as a new command, but it may be elsewhere in later versions in which it's no longer new].

Kent Cooper, AIA
0 Likes
Message 7 of 13

paullimapa
Mentor
Mentor

Yes I missed the c:  If memory serves me correctly all those ai_ functions used to be defined in a separate ai_utils.lsp file. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 8 of 13

paullimapa
Mentor
Mentor

 

 

Basically you can just use the actual lines of code like this:

 

(defun c:PRACTICE ()
(initcommandversion -1)
(command "_.SELECT" "_ALL" "")
(princ)
)

 

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 13

elias.kanellakis
Participant
Participant

Guys one more question..

 

After selecting everything with AI_SELALL i want to Explode the selection.. So i use Command Explode.. The problem is that it doesn't keep the previous selection and prompts the user to select again.. Why does this happen??

 

(defun c:PRACTICE ()

(C:AI_SELALL)
(COMMAND ''EXPLODE")
(princ)
)

 

Should i make the selection with the SSGET? Is it the only way?

 

To be more exact about what i m trying to do.. I want to create a Lisp that explodes everything in the drawing, in order to call it in a different Lisp using  the C: name

 

The other Lisp will be used as the Main and as it uses a selection from the user to do some stuff, i saw that i can't use the same selection to Explode also.. So i want to make the Explode in a different lisp file an call it in the Main Lisp..

 

 

0 Likes
Message 10 of 13

-didier-
Advisor
Advisor
Accepted solution

Bonjour @elias.kanellakis 

 

It is better to use ssget, create a variable with and either browse the selection set or run a command on the selection set, in your case:

 

Snag_35723d03.png

Amicalement

Éternel débutant.. my site for learning : Programmer dans AutoCAD

DA

EESignature

Message 11 of 13

Kent1Cooper
Consultant
Consultant

@elias.kanellakis wrote:

....

(COMMAND ''EXPLODE")

....


Just a little by way of further explanation:  Something no one thinks to wonder about at first, but that we all eventually run up against, is the fact that for some inexplicable reason, when called in an AutoLisp (command) function, the EXPLODE command can Explode only one object.  If you give it a multiple-object selection set, it will Explode only one thing in it.  [This also means that if you are Exploding only one object, you don't need to "complete the selection" with the typical Enter "" -- just give it the one object, and the command is completed.]  There are three ways I know of to get around that odd limitation, of which I think @-didier-'s suggestion, using a preceding (initcommandversion) function, is better than the other two.

Kent Cooper, AIA
0 Likes
Message 12 of 13

paullimapa
Mentor
Mentor
0 Likes
Message 13 of 13

paullimapa
Mentor
Mentor
Accepted solution

you can try this:

(defun c:PRACTICE ()
;; c:ai_selall - code from acad20xxdoc.lsp
(initcommandversion -1)
(command "_.SELECT" "_ALL" "")
;; initcommandversion - https://help.autodesk.com/view/ACD/2025/ENU/?guid=GUID-6176FC98-DC5D-433E-8D76-F481BE68D46A
(initcommandversion)
(COMMAND "_.EXPLODE")
(princ)
)

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos