Author Topic: [Newb Help] Selection set problem with (list) filtering  (Read 3420 times)

0 Members and 1 Guest are viewing this topic.

James Cannon

  • Guest
[Newb Help] Selection set problem with (list) filtering
« on: June 02, 2009, 11:12:46 AM »
Code: [Select]
     (setq SL (ssget "X" (list (cons 100 "AcDbMText")(cons 8 "PT"))))
That is selecting everything on layer "PT" with no regard to whether it's MText or not.

I was under the impression that placing multiple 'filters' in the (list ) would mean that the selection set would be filtered such that it selected only items that met ALL the requirements stated (such as where dxf100=AcDbMText and where dxf8=PT)

What am I doing wrong?
« Last Edit: June 02, 2009, 11:16:13 AM by James Cannon »

James Cannon

  • Guest
Re: [Newb Help] Selection set problem with (list) filtering
« Reply #1 on: June 02, 2009, 11:18:22 AM »
To explain what is in my head...

What I THING that is doing.. is:

setq SL (starting the definition of the variable "SL"...)
ssget "X" (...as a selection set of everything in the drawing...)
list (...filtered to only include...)
cons 100 "AcDbMText" (only MText objects...)
cons 8 "PT" (...that are on layer "PT")

...am I flawed?  OR rather... I know I am... but where am I flawed? lol..

T.Willey

  • Needs a day job
  • Posts: 5251
Re: [Newb Help] Selection set problem with (list) filtering
« Reply #2 on: June 02, 2009, 11:22:06 AM »
To select certain entities, then use dxf code 0 instead of 100.  So

(cons 0 "mtext")
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

James Cannon

  • Guest
Re: [Newb Help] Selection set problem with (list) filtering
« Reply #3 on: June 02, 2009, 11:24:14 AM »
To select certain entities, then use dxf code 0 instead of 100.  So

(cons 0 "mtext")

Thanks, I tried that too, and it did the same thing.

Code: [Select]
      (setq SL (ssget "X" (list (cons 0 "mtext")(cons 8 "PT")))
..still results in a sset that contains all objects on layer PT. :(

James Cannon

  • Guest
Re: [Newb Help] Selection set problem with (list) filtering
« Reply #4 on: June 02, 2009, 11:26:34 AM »
To clarify, I'm trying to incorporate part of Mark Thomas' Layer-Delete routine, found here; http://www.cadtutor.net/forum/showthread.php?t=2022 ,  into a routine of my own.

I just want to delete all MText objects on a certain layer.

Providing greater context, ref:

Code: [Select]
     (setq SL (ssget "X" (list (cons 0 "mtext")(cons 8 "PT")))
            ; set 'cntr' to number of items in selection set
            cntr (1- (sslength SL))
            amt (itoa cntr); make a string from an integer
)
            
 
      (if
        ; does the sel set have anything in it
        (> cntr 0); test
 
        (while
          ; as long as 'cntr' is greater than or equal to 0
          ; keep looping
          (>= cntr 0)
 
          ; extract the ename from the sel set
          (setq ssent (ssname SL cntr))
          (entdel ssent); delete that entity
          (setq cntr (1- cntr)); subtract 1 from cntr
          )
 
        )

It deletes everything on the layer "PT" and thus I -assume- the sset is including everything on layer "PT" which includes some polylines.  I don't think it SHOULD be including the plines in the sset, which is what I'm trying to figure out how to fix.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: [Newb Help] Selection set problem with (list) filtering
« Reply #5 on: June 02, 2009, 11:36:39 AM »
It works here as you have it.  I have two items in the drawing, both on layer PT.  One is a line, and one is an mtext entity.

Quote
Command: (setq SL (ssget "X" (list (cons 0 "mtext")(cons 8 "PT"))))
<Selection set: 12>

Command: (sslength sl)
1
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: [Newb Help] Selection set problem with (list) filtering
« Reply #6 on: June 02, 2009, 11:40:05 AM »
If you want to delete everything on a layer, no need to do as much testing as you do.  Just use

Code: [Select]
(if (setq Sl (ssget "x" '((0 . "mtext") (8 . "pt"))))
    (while (setq ent (ssname Sl 0))
        (entdel ent)
        (ssdel ent Sl)
    )
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

James Cannon

  • Guest
Re: [Newb Help] Selection set problem with (list) filtering
« Reply #7 on: June 02, 2009, 11:42:16 AM »
What's the significance of using the ' instead of the (list ) ?

I modified my code to suit the format you used, and it runs smoothly and nicely.

As for the extra testing, it's unnecessary, but whenever I add snippets of code from other places, I try to get it working before trimming out other things that may be unnecessary.  It's just kind of a precautionary thing because I'm not very comfortable/confident in what I'm doing, to go hacking stuff up right off the bat.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: [Newb Help] Selection set problem with (list) filtering
« Reply #8 on: June 02, 2009, 11:43:04 AM »
I just want to delete all MText objects on a certain layer.
Select Similar + DEL key = Mission Accomplished


But if you're trying to learn sumpin' new...
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

James Cannon

  • Guest
Re: [Newb Help] Selection set problem with (list) filtering
« Reply #9 on: June 02, 2009, 11:45:01 AM »
I just want to delete all MText objects on a certain layer.
Select Similar + DEL key = Mission Accomplished


But if you're trying to learn sumpin' new...

Trying to make a routine that's going to be used by the non-CAD-savvy in the office as well.  It needs to basically be an "easy button" that they have to do as little as possible.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: [Newb Help] Selection set problem with (list) filtering
« Reply #10 on: June 02, 2009, 11:47:43 AM »
What's the significance of using the ' instead of the (list ) ?

The single quote ( ' ) in the ssget filter list, just means to use what is next as it is written.  If you don't have any variables, then you can use the single quote, but if you have variables, then you need to use ' list ' with ' cons ' to make an association list.

'((0 . "mtext")) = (list (cons 0 "mtext")) = (setq str "mtext") (list (cons 0 str)) = (list '(0 . "mtext"))

Just something you get used to with experience.


I modified my code to suit the format you used, and it runs smoothly and nicely.

As for the extra testing, it's unnecessary, but whenever I add snippets of code from other places, I try to get it working before trimming out other things that may be unnecessary.  It's just kind of a precautionary thing because I'm not very comfortable/confident in what I'm doing, to go hacking stuff up right off the bat.

Not a problem.  Each person works differently, and if you learning that way, then there is no problem.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

James Cannon

  • Guest
Re: [Newb Help] Selection set problem with (list) filtering
« Reply #11 on: June 02, 2009, 11:57:01 AM »
Ok, that makes good sense to me now. (after reading through it a couple times, to wrap my head around it, heh)

Thanks for the thorough explanation!

T.Willey

  • Needs a day job
  • Posts: 5251
Re: [Newb Help] Selection set problem with (list) filtering
« Reply #12 on: June 02, 2009, 11:58:50 AM »
You're welcome.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: [Newb Help] Selection set problem with (list) filtering
« Reply #13 on: June 02, 2009, 01:03:50 PM »
entdel only works for Modelspace and the most recently active Layout, use this:

Code: [Select]
(mapcar '(lambda (x) (vla-delete (vlax-ename->vla-object x)))  (mapcar 'cadr (ssnamex ss)))   

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.