i've been looking for a way to get QSELECT functionality in an automated form (like Actions) so i can select hatches with a particular pattern and flip them to a new pattern, but i'm having problems understanding the syntax of SSGET.
looking at the help page:
they give the syntax as:
(ssget [sel-method] [pt1 [pt2]] [pt-list] [filter-list])
but then the examples all suggest something more like (ssget "[sel-method]" '([pt1 [pt2]] [pt-list] [filter-list]))
what's the syntax for filter lists? i want to select all hatches with pattern DOTS (and then change to pattern SOLID). any help??
thanks in advance!
Solved! Go to Solution.
(ssget "x" '((0 . "hatch") (2 . "dots"))) will select all hatch patterns in the drawing with the pattern name dots.
To change all dots hatches to solids, something like this would work.
(defun c:test ( / ss e ei)
(repeat (sslength (setq ss (ssget "x" '((0 . "HATCH")(2 . "DOTS")))))
(setq e (ssname ss 0) ei (entget e))
(ssdel e ss)
(entmod (subst '( 2 . "SOLID") (assoc 2 ei) ei))
that's awesome, thank you so much!
so a few questions,
(ssget "x" '((0 . "HATCH")(2 . "DOTS")))
i understand issue the SSGET command and use the X method to search the entire db, but then the 0 and the 2 - are those codes that indicate entity type (hmm, maybe a property??) i assume so.
and is the . a delimiter that basically makes the statement say "take property 0 (maybe 0 is all entities??) and filter out anything that is "HATCH", then from that set, look at property 2 (pattern name) and filter it further for matches of "DOTS".
is this correct?
i realize i can prob get this online (and i just did download the LISP reference guide, but i figure i'll post this follow up in case it's helpful to anyone else)
started with this:
that lead me to this:
then to this:
(the 16th page or page 6)
If you want to find out what the codes mean, you might look at the dxf reference for autocad. In AutoCAD help search box, type "DXF" without the quotes. Then choose the entities section. Click on common codes to obtain those or insert to obtain the insert codes.
Association lists are the way AutoLISP entity access functions get and put those object properties. They are lists of key/value pairs. Each key/value pair is stored as a dotted list. (key . value). The period must have whitespace on both sides. The key is a DXF code. The value varies. Some properties are strings (surrounded by quotes). Others can be numeric or point data.
You can experiment with looking up data by using
Enter the above and select an object. View the resulting data.
entget, entmod, subst, and assoc are a few frequently used entity data functions. SSGET uses association list filters.
The references you cited are good places to start learning. Thanks for the kudo. Glad it worked for you.
I know its too late but
(defun c:test ( / ad ) (vl-load-com) (foreach space (list (vla-get-modelspace (setq ad (vla-get-ActiveDocument (vlax-get-acad-object)))) (vla-get-paperspace ad) ) (vlax-for i space (and (eq "AcDbHatch" (vla-get-objectname i)) (eq (strcase (vla-get-patternName i)) "DOTS") (vla-setpattern i acHatchPatternTypePreDefined "SOLID") ) ) ) )
Just showing an alternative. It might be faster...? I don't know. There are several ways to accomplish your goal. I posted it just for fun
It would be extremely unlikely that that code would be faster due to the efficiency of the selectionset mechanism. Having to parse every element at the top level to determine whether it was hatch or not would be generally slower than to use selection sets. In addition, your code would overlook any layout that was not the the current paperspace.
ActiveX would shine however if you needed to change hatch nested into blocks in addition to those in the main modelspace and layout blocks. Such as:
(vl-load-com) (defun c:test ( / doc) (vlax-for b (vla-get-blocks (setq doc (vla-get-activedocument (vlax-get-acad-object)))) (vlax-for o b (if (and (= "AcDbHatch" (vla-get-objectname o)) (= "DOTS" (strcase (vla-get-PatternName o)))) (vla-setpattern o acHatchPatternTypePreDefined "solid") )) ) (vla-regen doc acallviewports) (princ) )