getting a prompt to select objects if there are not objects selected

getting a prompt to select objects if there are not objects selected

jagostinho74
Collaborator Collaborator
1,200 Views
6 Replies
Message 1 of 7

getting a prompt to select objects if there are not objects selected

jagostinho74
Collaborator
Collaborator

hello,

 

I have created a new command to delete all the 3DSolids from my drawing but I think that I am getting a prompt to select objects if there are no more 3DSolids to be deleted. How can I prevent this from happening?

 

My goal is to run the command to delete all 3D Solids and if no 3D Solids can be found just return to the command line.

 

this is my code

(if (= (getvar "cmdactive") 1) (ssget "x" '((0 . "*3DSOLIDS*"))) (sssetfirst nil (ssget "x" '((0 . "*3DSOLIDS*")))))(command "erase")

 

and this is what I get in the command line

command line.png

 

thank you

Assistant BIM/CAD Manager

Manchester, UK


0 Likes
Accepted solutions (1)
1,201 Views
6 Replies
Replies (6)
Message 2 of 7

pbejse
Mentor
Mentor
Accepted solution

@jagostinho74 wrote:

I have created a new command to delete all the 3DSolids from my drawing but I think that I am getting a prompt to select objects if there are no more 3DSolids to be deleted. How can I prevent this from happening?

 


Why not simply

(if (ssget "x" '((0 . "3DSOLID*")(410 . "Model")))
	   (command "Erase" "P" ""))

or

(if (ssget "x" (list '(0 . "3DSOLID*")(Cons 410 (getvar 'ctab))))
	   (command "Erase" "P" ""))

 or

(if (setq ss_solids (ssget "x" '((0 . "3DSOLID*"))))
  (foreach e (mapcar 'cadr (ssnamex ss_solids))
    (entdel e)
  )
)

HTH

 

Message 3 of 7

marko_ribar
Advisor
Advisor

Maybe, something like this :

 

(if (= (getvar 'cmdactive) 1)
  (ssget "_X" '((0 . "*3DSOLID*")))
  (if (ssget "_X" '((0 . "*3DSOLID*")))
    (vl-cmdf "_.ERASE" "_P" "")
  )
)
Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 4 of 7

john.uhden
Mentor
Mentor

@marko_ribar ,

Somehow I don't think you need the first ssget.

John F. Uhden

0 Likes
Message 5 of 7

Kent1Cooper
Consultant
Consultant

The (ssget) filter list entry for entity type is wrong.  No S at the end, and the wildcard asterisks are meaningless -- there aren't any entity types with more letters before or after.

... '((0 . "3DSOLID")) ...

 

I don't understand the  (if (= (getvar "cmdactive") 1)  part.  Breaking down:

 

(if (= (getvar "cmdactive") 1); test expression -- is a command [any command] active?

  (ssget "x" '((0 . "*3DSOLIDS*"))); then expression

    ;; looks for them only if another command is active, but does nothing with what it finds

  (sssetfirst nil (ssget "x" '((0 . "*3DSOLIDS*")))); else expression

    ;; selects/highlights/grips any it finds 

); if

(command "erase"); thoroughly outside (if) function, and whether or not it found any

 

That means the Erase command will be called whether or not this is called during another command, and whether or not there are any 3D Solids to find.  But if it's during another command, that won't be an appropriate answer to whatever the current prompt is.

 

I agree with @pbejse 's simpler suggestions, and offer another, which will remove them from all spaces [whereas the Erase command can "see" only those in the current space]:

 

(if (setq ss (ssget "_X" '((0 . "3DSOLID"))))
  (repeat (setq n (sslength ss))
    (vla-delete (vlax-ename->vla-object (ssname ss (setq n (1- n)))))
  ); repeat
); if

 

[I first tried using (entdel), but somehow that didn't remove them from all spaces the way (vla-delete) does.]

Kent Cooper, AIA
Message 6 of 7

jagostinho74
Collaborator
Collaborator

thank you @pbejse .

I'm using your first suggestion.

Assistant BIM/CAD Manager

Manchester, UK


0 Likes
Message 7 of 7

jagostinho74
Collaborator
Collaborator

thank you for such detailed explanation @Kent1Cooper .

It is very useful to understand better what the code is doing.

 

Assistant BIM/CAD Manager

Manchester, UK


0 Likes