Author Topic: ssget "_w" with filter  (Read 7040 times)

0 Members and 1 Guest are viewing this topic.

cadman6735

  • Guest
ssget "_w" with filter
« on: April 21, 2011, 02:30:15 PM »
I am practicing, this code is for nothing other than my education.

I am not sure what I am doing wrong.  I think my (setq sset (ssget...  Is not selecting anything. and gets stuck on (repeat (sslength sset)...

I have found two opions for the sset:
Code: [Select]
(setq sset (ssget "W" pt1 pt2 (list (cons 0 "TEXT") (cons 0 "MTEXT"))))
(setq sset (ssget "_W" pt1 pt2 '((0 . TEXT) (0 . MTEXT))))

The first line gets stuck on (repeat
The second line gets stuck on its own line "invalid list"

If someone can educate me this would be great
Thanks

Quote
(defun c:test ( / )

  (setq pt1 (getpoint "\nPick First Point"))
  (setq pt2 (getcorner pt1 "\nPick Second Point"))
  (setq sset (ssget "W" pt1 pt2 (list (cons 0 "TEXT") (cons 0 "MTEXT"))))
 

  (setq item 0)

  (repeat (sslength sset)

    (setq
      ent   (ssname sset item)
      entData   (entget ent)
      entString   (cdr (assoc 1 (entget ent)))
      entType   (cdr (assoc 0 (entget ent)))
      newString (strcase entString)
      entString (subst (cons 1 newString) (assoc 1 entData) entData)
    )

    (entmod entString)

    (setq item (1+ item))
  )

(princ)
)




;(setq sset (ssget "_W" pt1 pt2 '((0 . TEXT) (0 . MTEXT))))

ronjonp

  • Needs a day job
  • Posts: 7529
Re: ssget "_w" with filter
« Reply #1 on: April 21, 2011, 02:39:48 PM »
First off .. change your selection filter to this:

(setq sset (ssget "W" pt1 pt2 (list (cons 0 "*TEXT"))))

This will not work:
(setq sset (ssget "W" pt1 pt2 (list (cons 0 "TEXT") (cons 0 "MTEXT"))))

You should check that you have all the appropriate input before you try to repeat:
...and locali(z)(s)e your variables  :-)

Code: [Select]
(defun c:test (/ ent entdata entstring enttype item newstring pt1 pt2 sset)
  (if (and (setq pt1 (getpoint "\nPick First Point"))
  (setq pt2 (getcorner pt1 "\nPick Second Point"))
  (setq sset (ssget "W" pt1 pt2 (list (cons 0 "*TEXT"))))
  (setq item 0)
      )
    (repeat (sslength sset)
      (setq ent      (ssname sset item)
   entdata   (entget ent)
   entstring (cdr (assoc 1 (entget ent)))
   enttype   (cdr (assoc 0 (entget ent)))
   newstring (strcase entstring)
   entstring (subst (cons 1 newstring) (assoc 1 entdata) entdata)
      )
      (entmod entstring)
      (setq item (1+ item))
    )
  )
  (princ)
)

Try pasting this into the command line (sslength nil) ... you need to see what functions will chuck wobblies with invalid data.

« Last Edit: April 21, 2011, 02:44:34 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: ssget "_w" with filter
« Reply #2 on: April 21, 2011, 02:41:28 PM »
When you say, 'gets stuck' I'm assuming you mean it errors, as a repeat expression cannot enter an infinite loop by its definition.

The error would most likely be caused by a null SelectionSet since your filter list will filter out all entities.

By default, the filter list will match all entries using an AND operation, i.e. all conditions in the filter list must be met.

To filter for more than one object we require an OR operation, which can be achieved in one of two ways:

Using the wcmatch OR:
Code: [Select]
(ssget '((0 . "TEXT,MTEXT")))
Using the -4 filter OR:
Code: [Select]
(ssget '((-4 . "<OR") (0 . "TEXT") (0 . "MTEXT") (-4 . "OR>")))
I would use the first one.

Lee

EDIT: When working with SelectionSets, be sure to test for a valid SelectionSet before proceeding to use ssname/sslength/ssmemb/ssdel etc. As SelectionSet functions will error if passed nil for the SelectionSet argument.

i.e.
Code: [Select]
(if (setq ss (ssget ... ))
  -- Your Code Here  --
)
« Last Edit: April 21, 2011, 02:44:37 PM by Lee Mac »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ssget "_w" with filter
« Reply #3 on: April 21, 2011, 02:44:39 PM »
Careful with this as it will get Rtext too.
Code: [Select]
(setq sset (ssget "W" pt1 pt2 (list (cons 0 "*TEXT"))))
I prefer
Code: [Select]
(setq sset (ssget "W" pt1 pt2 (list (cons 0 "TEXT,MTEXT"))))
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.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: ssget "_w" with filter
« Reply #4 on: April 21, 2011, 02:49:03 PM »
Careful with this as it will get Rtext too.
Code: [Select]
(setq sset (ssget "W" pt1 pt2 (list (cons 0 "*TEXT"))))
I prefer
Code: [Select]
(setq sset (ssget "W" pt1 pt2 (list (cons 0 "TEXT,MTEXT"))))

I prefer:
(setq sset (ssget "_W" pt1 pt2 '((0 . "TEXT,MTEXT"))))
 :-P

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: ssget "_w" with filter
« Reply #5 on: April 21, 2011, 03:21:06 PM »
Careful with this as it will get Rtext too.
Code: [Select]
(setq sset (ssget "W" pt1 pt2 (list (cons 0 "*TEXT"))))
I prefer
Code: [Select]
(setq sset (ssget "W" pt1 pt2 (list (cons 0 "TEXT,MTEXT"))))

I prefer:
(setq sset (ssget "_W" pt1 pt2 '((0 . "TEXT,MTEXT"))))
 :-P
Well, I prefer
Code: [Select]
(setq sset (ssget "_W" pt1 pt2 '((0 . "MTEXT,TEXT")))) because I like to alphabetize.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7529
Re: ssget "_w" with filter
« Reply #6 on: April 21, 2011, 03:54:29 PM »
 :-)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

cadman6735

  • Guest
Re: ssget "_w" with filter
« Reply #7 on: April 21, 2011, 06:30:33 PM »
Thanks all...


cadman6735

  • Guest
Re: ssget "_w" with filter
« Reply #8 on: April 21, 2011, 06:46:13 PM »
Which sel-method allows me to pick individual elements or crossing window.  Same as in the move command or copy command.

or is this a routine all to itself?

ronjonp

  • Needs a day job
  • Posts: 7529
Re: ssget "_w" with filter
« Reply #9 on: April 21, 2011, 06:50:06 PM »
Which sel-method allows me to pick individual elements or crossing window.  Same as in the move command or copy command.

or is this a routine all to itself?

(SSGET) Gives you a window(s) selection. No need to supply points.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

cadman6735

  • Guest
Re: ssget "_w" with filter
« Reply #10 on: April 21, 2011, 06:55:15 PM »
um...  I would like to be able to select one item with a pick box, like you see when you first start the move command or select a window of items as if I click off to the side (not hitting an element) it jumps right into a window selection, for multiple items.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: ssget "_w" with filter
« Reply #11 on: April 21, 2011, 07:01:00 PM »
(ssget) has that exact behavior on my computer  :?  You may want to look into (entsel) for single selection.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

cadman6735

  • Guest
Re: ssget "_w" with filter
« Reply #12 on: April 21, 2011, 07:05:28 PM »
I'm sorry ronjonp

I didn't remove the getpoint function...

you even told me to do so too...  I must have a hearing problem or something... 

Thanks for your help

cadman6735

  • Guest
Re: ssget "_w" with filter
« Reply #13 on: April 21, 2011, 07:07:54 PM »
This is so cool, it is like a new toy or something

Thanks again