PDA

View Full Version : Exclude objects from selection set


ccowgill
2006-02-14, 05:12 PM
When I ran a search for the above title, the forum returned that all the words except "set" are too common, so I have no other choice but to post my question.

Situation:
I would like to run a spell check on all objects in the current space except for our map blocks.

Our map blocks are all called M# where the # is a number 1-24 presently.

I created a lisp routine that would run spell check and then plot the drawing, basically a way to force the use of spell check on our drawings. However on the cover page when spell check runs it selects all the objects and that includes the location maps, which have many street names that are not common words, thus taking a long time to check the spelling. spell check can be canceled and the drawing will still plot.

this is what I am currently using to run spell check:

(command "spell" "all" "")


Any help would be greatly appreciated.

rkmcswain
2006-02-14, 07:05 PM
I don't know of any way to "exclude" by filtering, but you can build a selection set containing everything, then remove the "excluded" ones


(setq sset (ssget "X") sset2 (ssget "X" '((0 . "INSERT")(2 . "M*"))) i 0)
(repeat (sslength sset2)
(ssdel (ssname sset2 i) sset)
(setq i (1+ i))
)

Opie
2006-02-14, 07:16 PM
I don't know of any way to "exclude" by filtering, but you can build a selection set containing everything, then remove the "excluded" ones


(setq sset (ssget "X") sset2 (ssget "X" '((0 . "INSERT")(2 . "M*"))) i 0)
(repeat (sslength sset2)
(ssdel (ssname sset2 i) sset)
(setq i (1+ i))
)

You could use the not association list to exclude items from a selection set.

(setq sset (ssget "X" '((-4 . "<NOT")(2 . "M*")(-4 . "NOT>")(0 . "INSERT"))))

T.Willey
2006-02-14, 07:21 PM
This will select all but text objects.

(setq ss (ssget '((0 . "~TEXT"))))

I'm assuming you can do this for what you want, but I haven't tried it yet.

ccowgill
2006-02-14, 07:43 PM
This is what I ended up using, it seems to work well enough for what I need



(setq sset (ssget "X") sset2 (ssget "X" '((0 . "INSERT")(2 . "M*"))) i 0)
(repeat (sslength sset2)
(ssdel (ssname sset2 i) sset)
(setq i (1+ i))
)
(command "SPELL" sset "")


thanks again.

rkmcswain
2006-02-14, 08:09 PM
You could use the not association list to exclude items from a selection set.

(setq sset (ssget "X" '((-4 . "<NOT")(2 . "M*")(-4 . "NOT>")(0 . "INSERT"))))


You are right, but your code has a flaw. It only selects INSERT objects that are not named "M*"

The following selects all drawing entities except INSERT's named "M*"


(ssget "X" '((-4 . "<NOT")(-4 . "<AND")(0 . "INSERT")(2 . "M*")(-4 . "AND>")(-4 . "NOT>")))


ccowgill, Opie is right, use (ssget), it should be faster. My first post was wrong.

Thanks for the reminder Opie.

Opie
2006-02-14, 08:12 PM
You are right, but your code has a flaw. It only selects INSERT objects that are not named "M*"

The following selects all drawing entities except INSERT's named "M*"


(ssget "X" '((-4 . "<NOT")(-4 . "<AND")(0 . "INSERT")(2 . "M*")(-4 . "AND>")(-4 . "NOT>")))


ccowgill, Opie is right, use (ssget), it should be faster. My first post was wrong.

Thanks for the reminder Opie.
I realized that after I logged off. The code I posted was the example I was working with on my machine. I wasn't even working with the OP's request for the spell checker.

Thanks for clarifing it for me. ;)

ccowgill
2006-02-14, 08:20 PM
Thanks, I switched out the code and it works great, no more plotting out drawings that have typo's, every time I plot, spell check now automatically runs and I can still cancel the spell check if I wish.

Thanks again,

ccowgill
2006-02-27, 12:32 PM
As I was running spell check I noticed that it was checking spelling of frozen objects. How do I exclude objects that are frozen from the selection set

rkmcswain
2006-02-27, 01:52 PM
As I was running spell check I noticed that it was checking spelling of frozen objects. How do I exclude objects that are frozen from the selection set

Try this:


(ssget "all" '(
(-4 . "<NOT")
(-4 . "<AND")
(0 . "INSERT")
(2 . "M*")
(-4 . "AND>")
(-4 . "NOT>")
)
)


The "all" keyword is undocumented (as far as I can tell), but it works a little different than "x", in that it filters out frozen layers

Another option: http://tinyurl.com/npbjz

ccowgill
2006-02-27, 06:45 PM
so I can make sure I understand how ssget works if I use:



(ssget "all" '(
(-4 . "<NOT")
(-4 . "<AND")
(0 . "INSERT")
(-4 . "<OR")
(2 . "M*")
(2 . "P*")
(-4 . "OR>")
(-4 . "AND>")
(-4 . "NOT>")
)
)



it will select everything that is thawed except blocks that begin with the letter m, or letter p?

rkmcswain
2006-02-27, 08:39 PM
I'd like to think I could answer that just by looking at the code, but I usually test it out to make sure. It's fairly easy using VLIDE.

To answer your question, yes. But you can shorten it up some.


(ssget "all"
'(
(-4 . "<NOT")
(-4 . "<AND")
(0 . "INSERT")
(2 . "M*,P*")
(-4 . "AND>")
(-4 . "NOT>")
)
)


Good luck.

ccowgill
2006-02-28, 01:44 PM
I dont understand why I cant get this to work. When I separate the code so the selection set and erase command are separate they work fine, but it does not work in the form I am using:


(defun c:sup ()
(setq bss (ssget "X" '((-4 . "<AND")(0 . "insert")(2 . "$rma$,PROJ_NAM")(-4 . "AND>"))))
(command "erase" bss "")
(command "-purge" "r" "" "n")
(command "-purge" "a" "" "n")
(command "-purge" "a" "" "n")
(command "audit" "Y")
(command "-purge" "a" "" "n")

rkmcswain
2006-02-28, 02:17 PM
I dont understand why I cant get this to work. When I separate the code so the selection set and erase command are separate they work fine, but it does not work in the form I am using

Is that ALL your code? Because you are missing a parenthesis to close the defun.
Other than that, it works here just fine.

BTW - The "AND" is implied, and not needed unless you are separating it from other filters.

ccowgill
2006-02-28, 10:59 PM
This is what shows up on the command line when I run the code (the end parenthesis is in the code) and the two blocks I want to erase dont get erased.

If I run the erase part by itself in a separate code, it works fine.


Command: SUP
Initializing...erase
Select objects:
Command: SUP Unknown command "SUP". Press F1 for help.

Command: -purge
Enter type of unused objects to purge
[Blocks/Dimstyles/LAyers/LTypes/Plotstyles/SHapes/textSTyles/Mlinestyles/Tablest
yles/Regapps/All]: r Enter name(s) to purge <*>: Verify each name to be purged?
[Yes/No] <Y>: n Deleting registered application "EGPT_END".
Deleting registered application "EGPT_LCAD".
Deleting registered application "EGPT_LCAD_AI_BACKFLOW_SYMBOL".
Deleting registered application "EGPT_LCAD_AI_CONTROL_SYMBOL".
Deleting registered application "EGPT_LCAD_AI_DRIP_LEG".
Deleting registered application "EGPT_LCAD_AI_EMITTER_SYMBOL".
Deleting registered application "EGPT_LCAD_AI_EQUIPMENT_SYMBOL".
Deleting registered application "EGPT_LCAD_AI_EVAL_SYMBOL".
Deleting registered application "EGPT_LCAD_AI_FITTING_SYMBOL".
Deleting registered application "EGPT_LCAD_AI_HEAD_SYMBOL".
Deleting registered application "EGPT_LCAD_AI_PIPE_LEG".
Deleting registered application "EGPT_LCAD_AI_POC_SYMBOL".
Deleting registered application "EGPT_LCAD_AI_PUMP_SYMBOL".
Deleting registered application "EGPT_LCAD_AI_VALVE_SYMBOL".
Deleting registered application "EGPT_LCAD_AI_WATER_METER_SYMBOL".
Deleting registered application "EGPT_LCAD_AI_WIRE_LEG".
Deleting registered application "EGPT_LCAD_LC_PLANT_SYMBOL".
Deleting registered application "EGPT_LCAD_LD_PLANT_SYMBOL".
Deleting registered application "EGPT_LOT".
Deleting registered application "EGPT_LOT_ANNOTATION".
Deleting registered application "EGPT_LOT_TABLE_ANNOT".
Deleting registered application "EGPT_NODE_LEADER".
Deleting registered application "EPADCMMD".
Deleting registered application "EPADMIRROR".
24 registered applications deleted.

Command: -purge
Enter type of unused objects to purge
[Blocks/Dimstyles/LAyers/LTypes/Plotstyles/SHapes/textSTyles/Mlinestyles/Tablest
yles/Regapps/All]: a Enter name(s) to purge <*>: Verify each name to be purged?
[Yes/No] <Y>: n Deleting block "*D76".
Deleting block "A$C612309B5".
2 blocks deleted.
Deleting layer "DEFPOINTS".
Deleting layer "Dim".
Deleting layer "Exist Building".
Deleting layer "Exist Concrete".
Deleting layer "Exist Fence".
Deleting layer "Exist Guardrail".
Deleting layer "Exist Parking Lot".
Deleting layer "Exist Railroad".
Deleting layer "Exist Road".
Deleting layer "Exist Road Hatch".
Deleting layer "Exist Trees".
Deleting layer "Grading Limits".
Deleting layer "Grading Permits".
Deleting layer "Offset Notes".
Deleting layer "Points Freeze".
Deleting layer "Prop Contours".
Deleting layer "Prop Drive".
Deleting layer "Prop Fence".
Deleting layer "Prop Guardrail".
Deleting layer "Prop Sanitary".
Deleting layer "Prop Sidewalk".
Deleting layer "Prop Storm".
Deleting layer "Survey".
Deleting layer "tblk".
Deleting layer "Title Block".
25 layers deleted.
Deleting linetype "BORDER".
Deleting linetype "BORDER2".
Deleting linetype "BORDERX2".
Deleting linetype "CENTER".
Deleting linetype "CENTERX2".
Deleting linetype "DASHDOT".
Deleting linetype "DASHDOT2".
Deleting linetype "DASHDOTX2".
Deleting linetype "DASHED".
Deleting linetype "DASHED2".
Deleting linetype "DASHEDX2".
Deleting linetype "DIVIDE".
Deleting linetype "DIVIDE2".
Deleting linetype "DIVIDEX2".
Deleting linetype "DOT".
Deleting linetype "DOT2".
Deleting linetype "DOTX2".
Deleting linetype "FM".
Deleting linetype "GAS".
Deleting linetype "HIDDEN2".
Deleting linetype "HIDDENX2".
Deleting linetype "PHANTOM".
Deleting linetype "PHANTOMX2".
Deleting linetype "W-DITCHLINE".
Deleting linetype "W-OVERHEAD CABLE".
Deleting linetype "W-OVERHEAD ELECTRIC".
26 linetypes deleted.
Deleting text style "DELTASYMBOL".
1 text style deleted.
Deleting shape file "DRAWING1".
1 shape file deleted.
Deleting dimension style "ENGLISH2".
Deleting dimension style "Standard".
2 dimension styles deleted.

No unreferenced mlinestyles found.

No unreferenced plotstyles found.

No unreferenced table styles found.

Command: -purge
Enter type of unused objects to purge
[Blocks/Dimstyles/LAyers/LTypes/Plotstyles/SHapes/textSTyles/Mlinestyles/Tablest
yles/Regapps/All]: a Enter name(s) to purge <*>: Verify each name to be purged?
[Yes/No] <Y>: n
No unreferenced blocks found.

No unreferenced layers found.

No unreferenced linetypes found.

No unreferenced text styles found.

No unreferenced shape files found.

No unreferenced dimension styles found.

No unreferenced mlinestyles found.

No unreferenced plotstyles found.

No unreferenced table styles found.

Command: audit
Fix any errors detected? [Yes/No] <N>: Y
Auditing Header


DXF Name Current Value Validation Default
AcDbSortentsTable(71D13)
Error for Entry (9B597,9B5B0) eDuplicateKey fixed
AcDbSortentsTable(71D13)
Error for Entry (9B5D3,9B5D0) eDuplicateKey fixed

75 Blocks audited
Pass 1 119770 objects audited
Pass 2 119770 objects audited
Pass 3 120800 objects audited
Total errors found 2 fixed 2


Command: -purge
Enter type of unused objects to purge
[Blocks/Dimstyles/LAyers/LTypes/Plotstyles/SHapes/textSTyles/Mlinestyles/Tablest
yles/Regapps/All]: a Enter name(s) to purge <*>: Verify each name to be purged?
[Yes/No] <Y>: n
No unreferenced blocks found.

No unreferenced layers found.

No unreferenced linetypes found.

No unreferenced text styles found.

No unreferenced shape files found.

No unreferenced dimension styles found.

No unreferenced mlinestyles found.

No unreferenced plotstyles found.

No unreferenced table styles found.

Command: nil

rkmcswain
2006-03-01, 03:05 AM
The key to that is right here:


Command: SUP
Initializing...erase
Select objects:
Command: SUP Unknown command "SUP". Press F1 for help.


If "bss" is nil then the erase command will fail, causing the "Unknown Command" feedback.

Here is how to fix that:

(if
(setq bss (ssget "X" '((-4 . "<AND")(0 . "insert")(2 . "$rma$,PROJ_NAM")(-4 . "AND>"))))
(command "erase" bss "")
)


Now as to why "bss" is coming back NIL, you will have to figure that out. I created some blocks named "$rma$" and "PROJ_NAM", and the (ssget) line above definitely works, and selects the blocks.

ccowgill
2006-03-01, 04:16 PM
that was it, it works great now, thanks

rkmcswain
2006-03-02, 12:43 AM
Glad it's working now. Have a good one.

ccowgill
2006-05-22, 05:30 PM
I also need to exclude objects that are not on the current layout tab, I tried using this and it gives an error

Error: bad SSGET list value; reset after error


(setq CULAYOUT (getvar "ctab"))
(setq ss (ssget "all"
'((-4 . "<AND")
(0 . "LAYOUT")
(2 . CULAYOUT)
(-4 . "<NOT")
(-4 . "<AND")
(0 . "INSERT")
(2 . "M*")
(-4 . "AND>")
(-4 . "NOT>")
(-4 . "AND>")
)
)
)



any suggestions?

T.Willey
2006-05-22, 05:55 PM
To select objects that are in the current tab only, use

(ssget "x" (list (cons 410 (getvar "ctab"))))

ccowgill
2006-05-23, 03:52 PM
To select objects that are in the current tab only, use

(ssget "x" (list (cons 410 (getvar "ctab"))))
how do I combine what I have in my post with your line, I keep getting this error:

Error: bad SSGET list value

I need it to select all objects in the current layout tab that are visible and are not a block that begins with M (our location maps)

Opie
2006-05-23, 05:23 PM
how do I combine what I have in my post with your line, I keep getting this error:

Error: bad SSGET list value

I need it to select all objects in the current layout tab that are visible and are not a block that begins with M (our location maps)
The filter for the ssget function is a list of dotted pairs. For the dotted pairs that you are trying to place variable information into, you will need to construct the dotted pair with the group code and the value.
Your code might look like this:
(SETQ FILTER (LIST (CONS -4 "<AND")
(CONS 410 (GETVAR "ctab"))
(CONS -4 "<NOT")
(CONS -4 "<AND")
(CONS 0 "INSERT")
(CONS 2 "M*")
(CONS -4 "AND>")
(CONS -4 "NOT>")
(CONS -4 "AND>")
)
)
(SETQ SELECTIONSET (SSGET "X" FILTER))

ccowgill
2006-05-23, 05:58 PM
is there a way to do it using a dotted pair without constructing it?


(setq ss (ssget "all"
'((-4 . "<NOT")
(-4 . "<OR")
(-4 . "<AND")
(0 . "INSERT")
(2 . "M*")
(-4 . "AND>")
(67 . 0)
(-4 . "OR>")
(-4 . "NOT>")
)
)
)


what I have here works fine, it just still checks other layout tabs if there are more than one, I only want the current one checked.

kennet.sjoberg
2006-05-23, 06:19 PM
(command "._erase" (ssget "_X" (list '(0 . "INSERT") '(2 . "M*") (cons 410 (getvar "CTAB" ))) ) "" )

: ) Happy Computing !

kennet

Opie
2006-05-23, 06:20 PM
What is wrong with the way I mentioned? :confused:

ccowgill
2006-05-23, 06:24 PM
What is wrong with the way I mentioned?
this is part of a larger command, it redefines plot so it will check spelling before it plots. when I use what you had, it displays the message, command unknown and then goes directly to the plot dialog, skipping spell check all together.

here is the whole code, or at least what currently works.

(if (not c:engineering)
()
(progn
(command "undefine" "plot")
(defun C:PLOT (/ ss App Doc Dwgprops dname name file)
(vl-load-com)
;;===============================================
;; L o c a l F u n c t i o n s
;;===============================================
;; error function & Routine Exit
(defun *error* (msg)
(if
(not
(member
msg
'("console break"
"Function cancelled"
"quit / exit abort"
""
)
)
)
(princ (strcat "nError: " msg))
) ; endif
(restore_sys_vars) ; reset vars
) ;end defun
;; Function to save system variables in global variable
;; call to function
;; (save_sys_vars '("CMDECHO" "FILEDIA"))
(defun save_sys_vars (lst)
(setq *sysvarlist* '())
(repeat (length lst)
(setq *sysvarlist*
(append *sysvarlist*
(list (list (car lst) (getvar (car lst))))
)
)
(setq lst (cdr lst))
) ;end repeat
) ;end defun
;; Function to reset system variables
(defun restore_sys_vars ()
(repeat (length *sysvarlist*)
(setvar (caar *sysvarlist*) (cadar *sysvarlist*))
(setq *sysvarlist* (cdr *sysvarlist*))
) ;end repeat
) ;end defun
(save_sys_vars '("CMDECHO" "FILEDIA"))
(setvar "cmdecho" 0)
(setvar "filedia" 0)
(setq ss (ssget "all"
'((-4 . "<NOT")
(-4 . "<OR")
(-4 . "<AND")
(0 . "INSERT")
(2 . "M*")
(-4 . "AND>")
(67 . 0)
(-4 . "OR>")
(-4 . "NOT>")
)
)
) ;end setq
(command "SPELL" ss "")
;(command "QSAVE")
(setq App (vlax-Get-Acad-Object)
Doc (vla-Get-ActiveDocument App)
DwgProps (vla-Get-SummaryInfo Doc)
) ;end setq
(setq dname (getvar "DWGPREFIX"))
(setq dir (strcat dname "PLOTS/"))
(vl-mkdir dir)
(setq extA (getvar "ctab"))
(if (wcmatch extA "SH*")
(progn
(setq file (strcat dir extA ".PLT"))
(setq
outdev
(strcase
(vla-get-ConfigName
(vla-get-activelayout
(vla-get-activedocument (vlax-get-acad-object))
)
)
);end strcase
) ;end setq
(if (/= outdev "ALL SIZES KIP PLOTTER.PC3")
(progn
(command "-PLOT" "N" ;Detailed plot configuration? [Yes/No] <No>: N
"" ;Enter a layout name or [?] <Layout1>:
"" ;Enter a page setup name <>:
"" ;Enter an output device name or [?] <current>:
"n" ;Write the plot to a file [Yes/No] <N>: y
;file ;Enter file name <maverickengineeringx5405RCp01001-Layout1.PLT (file://maverickengineeringx5405RCp01001-Layout1.PLT/)>:
"N" ;Save changes to page setup [Yes/No]? <N> n
"y" ;Proceed with plot [Yes/No] <Y>:
) ;end command
) ;end progn
(progn
(command "-PLOT" "N" ;Detailed plot configuration? [Yes/No] <No>: N
"" ;Enter a layout name or [?] <Layout1>:
"" ;Enter a page setup name <>:
"" ;Enter an output device name or [?] <current>:
"y" ;Write the plot to a file [Yes/No] <N>: y
file ;Enter file name <maverickengineeringx5405RCp01001-Layout1.PLT (file://maverickengineeringx5405RCp01001-Layout1.PLT/)>:
"N" ;Save changes to page setup [Yes/No]? <N> n
"y" ;Proceed with plot [Yes/No] <Y>:
) ;end command
) ;end progn
) ;end if
) ;end progn
(progn
(initdia)
(command "_.PLOT")
) ;end progn
) ;end if
(*error* "") ; reset sysvars
) ;end defun
) ;end progn
) ;end if

kennet.sjoberg
2006-05-23, 06:32 PM
The way to make the list


(command "._erase"
(ssget "_X"
(list
'(-4 . "<and")
(cons 410 (getvar "CTAB" ) )
'(0 . "INSERT")
'(-4 . "<or")
'(2 . "MyBlock1")
'(2 . "MyBlock2")
'(-4 . "or>")
'(-4 . "and>")
)
)
""
)

: ) Happy Computing !

kennet

Opie
2006-05-23, 06:33 PM
(SETQ SS (SSGET "all"
(LIST '(-4 . "<AND")
(CONS 410 (GETVAR "ctab"))
'(-4 . "<NOT")
'(-4 . "<AND")
'(0 . "INSERT")
'(2 . "M*")
'(-4 . "AND>")
'(-4 . "NOT>")
'(-4 . "AND>")
) ;_ end of LIST
) ;_ end of ssget
) ;end setq
(COMMAND "SPELL" SS "")

Replace your highlighted code with this to see if it works.

Good Luck.

ccowgill
2006-05-23, 06:38 PM
Works perfectly, thanks