Jump to content

Recommended Posts

Posted

Attempting to learn more about how do do things in VLA

 

Given:

(setq A3 (ssget "_X" '((2 . "SW_CEN*")))) 

 

I am looking for actually the simplest option for deleting A3.

I was hoping there was a method similar to

 

(vla-delete

 

that worked on selection sets vs individual objects.

 

These two methods work by I suspect my methodology is less than perfect.

 

(setq A3 (ssget "_X" '((2 . "SW_CEN*"))) i 0) 
(repeat (setq i (sslength A3))
(entdel (ssname A3 (setq i (1- i))))
)

 

and

 

(setq A3 (ssget "_X" '((2 . "SW_CEN*")))) 
(mapcar '(lambda (ent) (vla-Delete (vlax-ename->vla-object Ent)))
(vl-remove-if-not '(lambda (x) (= (type x) 'ename)) (mapcar 'cadr (ssnamex A3))))

 

the last one works but returns a long string of "nil" afterwards.

 

Is there a simpler way of simply deleting the A3 selection set?

 

 

Posted (edited)
(setq A3 nil) 

 

Edited by confutatis
  • Like 1
Posted

I meant is there a simpler method than this?

 

(setq A3 (ssget "_X" '((2 . "SW_CEN*"))) i 0) 
(repeat (setq i (sslength A3))
(entdel (ssname A3 (setq i (1- i))))
)

 

it seems "cleaner"

 

I just posted that last snippet as examples of what I have tried...

 

Is there a similar function to this

 

(vla-delete

 

specific to selection sets?

 

Posted

I guess I can't get simpler than this:

 

(setq A3 (ssget "_X" '((2 . "SW_CEN*")))) (command "_.erase" A3 "")

 

But I am attempting to learn VLA

Posted

It's not clear to me what you want to do.

The simplest solution to delete a selection set is the one given by confutatis.

On the other hand, you want to learn VLA(?).

A start could be the snippet below.

(ssget "_X" YOUR_FILTER_HERE)
(setq SEL (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
(if (> (vla-get-count SEL) 0)
 (vlax-for Obj SEL
   DO WHAT YOU WANT WITH Obj HERE
 )
)
(setq SEL nil)

 

  • Agree 1
Posted (edited)

Are you talking about this?

 

(setq A3 nil) 

 

That doesn't delete the entities that comprise the selection set does it?

 

This accomplishes what I am trying to do

 

(setq A3 (ssget "_X" '((2 . "SW_CEN*")))) (command "_.erase" A3 "")

 

I was just asking how to do that with VLA commands.. (this simplest way possible)

I am "novice-level" day 2..

 

Sorry for any confusion...

Edited by ILoveMadoka
Posted
19 hours ago, confutatis said:

(setq A3 nil) 

 

Doesn't that just clears the selection set and not delete any entity's?

Posted (edited)
22 hours ago, ILoveMadoka said:

I meant is there a simpler method than this?

 





(setq A3 (ssget "_X" '((2 . "SW_CEN*"))) i 0) 
(repeat (setq i (sslength A3))
(entdel (ssname A3 (setq i (1- i))))
)

 

Just another way of doing it without the i variable.

 

(if (setq A3 (ssget "_X" '((2 . "SW_CEN*")))) 
  (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex A3)))
    (entdel e)
  )
)

 

set up a function like this.

 

 

Edited by mhupp
  • Like 2
Posted
2 hours ago, mhupp said:

Just another way of doing it without the i variable.

 


(setq A3 (ssget "_X" '((2 . "SW_CEN*"))) i 0) 
(foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex A3)))
  (entdel e)
)

 

set up a function like this.

 

 

@mhupp FWIW when using "_X" with ssget you don't need vl-remove and you need to check that the selection is valid:

(if (setq a3 (ssget "_X" '((2 . "SW_CEN*"))))
  (foreach e (mapcar 'cadr (ssnamex a3)) (entdel e))
)

 

  • Thanks 1
Posted

Lots of good solutions you guys.. <Thank you>

 

I need to learn to search better, that's for sure.

I had not come across that entry or LeeMac's page on SS processing.

 

If I wanted to use

 

(vla-delete 

 

I would have to create some sort of counter to process the selection set?

 

looking at lido's code

 

(ssget "_X" YOUR_FILTER_HERE)
(setq SEL (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
(if (> (vla-get-count SEL) 0)
 (vlax-for Obj SEL
   DO WHAT YOU WANT WITH Obj HERE
 )
)
(setq SEL nil)

 

and adding/incorporating my

 

(ssget "_X" '((2 . "SW_CEN*")))

 

how would I marry that with the

 

(vla-delete 

 

since that was where I had started in the first place..

 

(ssget "_X" '((2 . "SW_CEN*")))
(setq SEL (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
(if (> (vla-get-count SEL) 0)
 (vlax-for Obj SEL
   (vla-delete SEL) ;No idea here
 )
)
(setq SEL nil)

 

I saw this on Lee's page: Here

 

(defun c:test5 ( / s )
    (if (ssget)
        (progn
            (vlax-for o (setq s (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
                (print (vla-get-objectname o))
            )
            (vla-delete s)
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

but do not understand what is going on enough to put it together with what I was attempting to do.

 

I know I already have several workable solutions in here but, asking these questions helps me to understand.

(apologies if that is frustrating to those I am looking to here.)

Posted
19 minutes ago, ILoveMadoka said:

i need to learn to search better, that's for sure.

 

 

I don't use the fourms search feature rather go to google and type

site:cadtutor.net delete selection set     This will return only results for this site.

Posted
58 minutes ago, ronjonp said:

@mhupp FWIW when using "_X" with ssget you don't need vl-remove and you need to check that the selection is valid

 

Very nice! so vl-remove is only needed when you select something with the mouse?

 

;;----------------------------------------------------------------------------;;
;; Fillet Multiple Polylines
(defun C:FMP (/ r SS)
  (if (setq r (getdist (strcat"\nSet Radius <" (rtos (getvar 'filletrad) 2) ">: ")))
    (setvar 'filletrad r)
  )
  (if (setq SS (ssget "_:L" '((0 . "LWPOLYLINE"))))
    (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (vl-cmdf "_Fillet" "P" x)
    )
  )
  (princ)
)

 

the (mapcar 'cadr (ssnamex SS)) returns the following when selecting 3 polylines.

(<Entity name: 2bd585d0> <Entity name: 2bd58610> <Entity name: 2bd57950> (0 (126.501215693286 -25.2529608935387 0.0)))

is that the point i clicked or something?

 

if ssget "X"

(<Entity name: 2bd585d0> <Entity name: 2bd58610> <Entity name: 2bd57950>)

 

Posted
1 hour ago, mhupp said:

 

Very nice! so vl-remove is only needed when you select something with the mouse?

 


;;----------------------------------------------------------------------------;;
;; Fillet Multiple Polylines
(defun C:FMP (/ r SS)
  (if (setq r (getdist (strcat"\nSet Radius <" (rtos (getvar 'filletrad) 2) ">: ")))
    (setvar 'filletrad r)
  )
  (if (setq SS (ssget "_:L" '((0 . "LWPOLYLINE"))))
    (foreach x (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (vl-cmdf "_Fillet" "P" x)
    )
  )
  (princ)
)

 

the (mapcar 'cadr (ssnamex SS)) returns the following when selecting 3 polylines.

(<Entity name: 2bd585d0> <Entity name: 2bd58610> <Entity name: 2bd57950> (0 (126.501215693286 -25.2529608935387 0.0)))

is that the point i clicked or something?

 

if ssget "X"

(<Entity name: 2bd585d0> <Entity name: 2bd58610> <Entity name: 2bd57950>)

 

Read about SSNAMEX HERE

Quote

The data returned by ssnamex is a list made up of sublists that contain information about an entity and the selection method used to select it, or a polygon used to select one or more entities. Each sublist that describes the selection of a particular entity comprises of three parts: selection method ID (an integer >= 0), entity name of the selected entity, and selection method specific data that describes how the entity was selected.

((sel_id1 ename1 (data))(sel_id2 ename2 (data)) ... )

The following table lists the selection method IDs:

Selection method IDs

ID

Description

0 Nonspecific (i.e., Last All)

1 Pick

2 Window or WPolygon

3 Crossing or CPolygon

4 Fence

 

Posted

@ILoveMadoka

In your first post you asked for the easiest way to delete the selection set A3. I repeat, to do this, confutatis's answer is correct.

If you want to delete the entities (objects) one by one from the selection set with the vla-delete function, then in your last post replace (vla-delete SEL) with (vla-delete Obj).

On the other hand, you have to do SEL nil because an AutoLISP application cannot have more than 128 selection sets open at once.

 

  • Like 1
Posted

You are arguing semantics.

When I said delete I meant delete the entities within a drawing not nul the selection set. The latter is what you reference.

 

I keep mentioning the [ (vla-delete ] method but I still don't know how to do it (novice) and nobody has helped me in that regard.

I posted some code from LeeMacs page that I believe is really close but I don't know how to marry his code and mine.

It's not a pi$$ing contest, I'm honesty try to learn something.

 

 

I thought that is one of the purposes for this forum.

 

 

I didn't want to get ripped by asking "please write a program for me."

I'm showing that I'm trying and requesting help with what I have figured out.

(Note: Thank you again to all who have replied and helped..)

 

I found the easiest way (ie: min code required)

 

(setq A3 (ssget "_X" '((2 . "SW_CEN*")))) (command "_.erase" A3 "")

 

What is the equivalent in VLA? (ie:minimal code required)

 

I have so many questions about how to do X in VLA.

I don't know jack and want to learn.

Posted (edited)
On 8/5/2021 at 12:30 AM, lido said:


(ssget "_X" YOUR_FILTER_HERE)
(setq SEL (vla-get-activeselectionset (vla-get-activedocument (vlax-get-acad-object))))
(if (> (vla-get-count SEL) 0)
 (vlax-for Obj SEL
   DO WHAT YOU WANT WITH Obj HERE
 )
)
(setq SEL nil)

 

 

@ILoveMadoka:

To answer your question definitively, i.e. using the VLA equivalent, lido's solution is the one you are looking for.

Beware, however, that the use of vla, vlax functions is not always the best. Often the entmake function is much more powerful and flexible than the vla-add function, the hatches created with vla functions are extremely cumbersome.

 

(setq A3 (ssget "_X" '((2 . "SW_CEN*")))) (command "_.erase" A3 "")

 

This is the quickest solution, in my opinion, and it is the one you wrote down. I often use it out of laziness and my friend mhupp will agree with me!

 

Edited by confutatis
  • Funny 1
Posted

I wish I knew enough to have options about which way was better!

 

Thank you

Posted
33 minutes ago, ILoveMadoka said:

I wish I knew enough to have options about which way was better!

 

In AutoCAD there has always been multiple ways to do one thing. Just go with the one your most comfortable with. In the end you are the one using the lisp dont over think it right now. once you start to understand the process better you could always change it if you want to.  I was looking over old code of mine recently and was like "LOL what was i thinking"

  • Like 1
Posted

 

I too look at my old programs from time to time, which were chock full of (command "change") and (command "chprop"). Back then it wasn't laziness, but ignorance, heresy to lisp purists.

Posted

One more: 

(sssetfirst nil (ssget "_X" '((2 . "SW_CEN*")))))(command "_.erase")

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...