View Full Version : Selection Set Check
mpeterson79
2008-02-12, 03:53 PM
I'm having a little trouble with some code - I'm not very well versed in AutoLISP, so I'm hoping someone out there can lend me a hand.
I'm trying to program a little verification into one of my programs, to check two things:
That the user has only picked text entities, and
that the text entities are all on layer "Layer01" (as an example)
Here is the small bit of code I tried, but it's not working:
(if (not (= sset (ssget "P" '((0 . "TEXT") (8 . "Layer01")))))
(prompt "\nText is on incorrect layer-All text must be on Layer01 layer")
)
Any ideas why this might not be working?
I get an "Error: bad argument type: lselsetp nil" when I try to use it.
Lions60
2008-02-12, 04:31 PM
Give this a try.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; This program checks each text entity.;;;
;;; If the text is not on Layer01 then a ;;;
;;; message tells you this. If the text ;;;
;;; is on Layer01 then it returns true & ;;;
;;; goes to the next entity. ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun C:Check ()
(setq sset (ssget "X" '((0 . "TEXT"))))
(setq number (sslength sset))
(setq Count 0)
(setq name (ssname sset Count))
(repeat number
(setq ent (entget name))
(if (/= (assoc 8 ent) "(8 . \"Layer01\")")
(progn
(prompt "\nText is on incorrect layer-All text must be on Layer01 layer\n")
(setq number nil)
);; end of progn
(setq COUNT (1+ COUNT))
);; end of if
);; end of repeat
);; end of defun
(prompt "\nType Check at the command prompt to start program\n")
mpeterson79
2008-02-12, 04:38 PM
Hmmm, I don't understand how that one is supposed to operate, but I can't seem to get it to work.
Sorry, my LISP knowledge is very limited.
What is wrong with your code is that you are trying to make a selection set that includes all TEXT that is not on layer LAYER01. You need to move your NOT into a list and wrap the part of your selection set filter for the elements you do now want to include in your selection.
I have the same problem with trying to remember the code to do these type filters, so I wrote a snippet that would help me in the future. This takes a list, and wraps it with the appropriate code. Try it out.
(defun wrapFilter (filterList filterType /)
(if (or
(= (strcase filterType) "NOT")
(= (strcase filterType) "OR")
(= (strcase filterType) "AND")
(= (strcase filterType) "XOR")
)
(append (list (cons -4 (strcat "<" (strcase filterType))))
filterList
(list (cons -4 (strcat (strcase filterType) ">")))
)
nil
)
)
Usage:
(wrapFilter (list (cons 8 "Layer01")) "not")
And now your code
(if (setq sset (ssget "P"(append (list (cons 0 "TEXT"))(wrapFilter (list (cons 8 "Layer01")) "not"))))
(prompt "\nText is on incorrect layer-All text must be on Layer01 layer")
)
kennet.sjoberg
2008-02-12, 08:25 PM
This code check for all model and paperspace "TEXT", not on layer "Layer01"
(if (ssget "_X" '((-4 . "<AND")(0 . "TEXT") (-4 . "<NOT")(8 . "Layer01")(-4 . "NOT>")(-4 . "AND>")))
(princ "\nText found on other layer than Layer01" )
(princ)
)
: ) Happy Computing !
kennet
CAB2k
2008-02-13, 05:00 AM
I'm having a little trouble with some code - I'm not very well versed in AutoLISP, so I'm hoping someone out there can lend me a hand.
I'm trying to program a little verification into one of my programs, to check two things:
That the user has only picked text entities, and
that the text entities are all on layer "Layer01" (as an example)
Here is the small bit of code I tried, but it's not working:
(if (not (= sset (ssget "P" '((0 . "TEXT") (8 . "Layer01")))))
(prompt "\nText is on incorrect layer-All text must be on Layer01 layer")
)
Any ideas why this might not be working?
I get an "Error: bad argument type: lselsetp nil" when I try to use it.
You're on the right track but this filter will prevent the wrong layer from being selected.
So no message is ever necessary, it just won't happen. The only thing that will happen
is that nothing at all is selected and in that case the selection will return nil.
It can be written like this:
(prompt "\nSelect Text on layer Layer01.")
(while (not (setq ss (ssget "P" '((0 . "TEXT") (8 . "Layer01")))))
(prompt "\nError - Nothing selected, Try again.")
)
;; ss containg a selection set of text on layer01
ccowgill
2008-02-13, 01:21 PM
(prompt "\nSelect Text on layer Layer01.")
(while (not (setq ss (ssget "P" '((0 . "TEXT") (8 . "Layer01")))))
(prompt "\nError - Nothing selected, Try again.")
)
;; ss containg a selection set of text on layer01
yes, but with the "P" isnt it going to grab your previous selection set, whereas you are setting up a new selection set with the prompt, shouldnt it be this:
(prompt "\nSelect Text on layer Layer01.")
(while (not (setq ss (ssget '((0 . "TEXT") (8 . "Layer01")))))
(prompt "\nError - Nothing selected, Try again.")
)
;; ss containg a selection set of text on layer01
CAB2k
2008-02-13, 03:43 PM
Oh, what was I thinking. Must have been half asleep. That's my excuse. :)
I meant to remove it. That's what I get for not testing the code.
Thanks Chris.
ccowgill
2008-02-13, 09:30 PM
Oh, what was I thinking. Must have been half asleep. That's my excuse. :)
I meant to remove it. That's what I get for not testing the code.
Thanks Chris.
Well according to what I can see on your post, that's what happens when you post at 11:00 PM, I am usually in bed by 10 or 10:30
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.