TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: cadman6735 on April 21, 2011, 02:30:15 PM

Title: ssget "_w" with filter
Post by: cadman6735 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))))
Title: Re: ssget "_w" with filter
Post by: ronjonp 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.

Title: Re: ssget "_w" with filter
Post by: Lee Mac 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  --
)
Title: Re: ssget "_w" with filter
Post by: CAB 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"))))
Title: Re: ssget "_w" with filter
Post by: ronjonp 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
Title: Re: ssget "_w" with filter
Post by: alanjt 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. (http://www.theswamp.org/lilly_pond/alanjt/nerd.gif)
Title: Re: ssget "_w" with filter
Post by: ronjonp on April 21, 2011, 03:54:29 PM
 :-)
Title: Re: ssget "_w" with filter
Post by: cadman6735 on April 21, 2011, 06:30:33 PM
Thanks all...

Title: Re: ssget "_w" with filter
Post by: cadman6735 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?
Title: Re: ssget "_w" with filter
Post by: ronjonp 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.
Title: Re: ssget "_w" with filter
Post by: cadman6735 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.
Title: Re: ssget "_w" with filter
Post by: ronjonp 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.
Title: Re: ssget "_w" with filter
Post by: cadman6735 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
Title: Re: ssget "_w" with filter
Post by: cadman6735 on April 21, 2011, 07:07:54 PM
This is so cool, it is like a new toy or something

Thanks again