Select all Polilines in Entire Drawing - but QSELECT is in DialogBox

Select all Polilines in Entire Drawing - but QSELECT is in DialogBox

Anonymous
Not applicable
6,722 Views
18 Replies
Message 1 of 19

Select all Polilines in Entire Drawing - but QSELECT is in DialogBox

Anonymous
Not applicable

Hello,
I wonder if it is possible to write a lisp "Select all Polilines in Entire Drawing" (there is second option: not "in Entire Drawing", but "In current Selection").
I tried, but QSELECT command is displayed only in the DialogBox. And there is no "-QSELECT" command (commands with "-" on the beginning are opened in an Interactive Menu, even if in lisp code before them is (INITDIA).)
Could you tell me: Is that possible to do this lisp?

0 Likes
6,723 Views
18 Replies
Replies (18)
Message 2 of 19

Kent1Cooper
Consultant
Consultant

Here's a way to select all of them in the drawing:

 

(sssetfirst nil (ssget "_X" '((0 . "*POLYLINE"))))

 

And to select all of them from among the current selection:

 

(sssetfirst nil (ssget "_I" '((0 . "*POLYLINE"))))

Kent Cooper, AIA
Message 3 of 19

Anonymous
Not applicable

Thank you.

Could you please explain me what are these letters meaning?

 

sssetfirst - Sets which objects are selected and gripped

 

nil - means "nothing"

 

(sssetfirst gripset [pickset])

 

gripset

Type: nil

AutoCAD no longer supports grips on unselected objects, so this argument is ignored. However, if gripset is nil and no pickset is specified, sssetfirst turns off the grip handles and selections it previously turned on.

pickset

 

But what mean "_X", "_I", etc.?

 

0 Likes
Message 4 of 19

Anonymous
Not applicable
Message 5 of 19

Anonymous
Not applicable

Finally I write good lisp, using your advice.

(defun c:SCTQ (/)
 (princ "\nFor this while you can select only Polylines: ")
 (sssetfirst nil (ssget '((0 . "*POLYLINE"))))
)

(defun c:SCTAQ (/)
 (princ "\nAll Polylines are selected.")
 (sssetfirst nil (ssget "_X" '((0 . "*POLYLINE"))))
)

 

I have a few questions:

1. what to type for what kind of AutoCad Objects?

I know, hat I can write "CIRCLE", "LINE", but what to type for Rotated dimension, Aligned Dimension (they are available to choose in DialogBox of QSELECT command)

2. I want also to write third type of lisp: "Select all kind of Objects apart from Polylines: ". 

How to write it? What expressions to use?

3.  Why these lisps written by me don't work?

(defun c:SCTQ1 (/)
 (princ "\nFor this while you can select only Lines:")
 (setq SelectLines
  (ssget
   '((0 . "LINE"))
  )
 )
)

(defun c:SCTAQ1 (/)
 (princ "\nAll Lines are selected.")
 (setq AllLines 
  (ssget "X" 
   '((0 . "LINE"))
  )
 )
)

 

I think I used right expressions. But there are errors. Here are prompts from CommandLine:

Command: SCTAQ1
; error: too few arguments

Command: SCTQ1

For this while you can select only Lines:
Select objects: 0 found

Select objects: 0 found, 0 total

Select objects: 0 found, 0 total

Select objects: 0 found, 0 total

Select objects: 0 found, 0 total

 When using SCTQ1, I click but I can't select nothing. Why?

 

 

 

 

 

0 Likes
Message 6 of 19

Lee_Mac
Advisor
Advisor

I'm pleased to see that you found my ssget function reference useful!

 

damian.wrobel wrote:

1. what to type for what kind of AutoCad Objects?

I know, hat I can write "CIRCLE", "LINE", but what to type for Rotated dimension, Aligned Dimension (they are available to choose in DialogBox of QSELECT command)

 

The filter list supplied to the ssget function determines the entities which are included in the selection by matching the DXF groups/logical operators found in the filter list against the corresponding DXF data held by each entity in a graphical selection or in the drawing database of the active drawing.

 

A reference for this DXF data can be found here.

 

damian.wrobel wrote:

2. I want also to write third type of lisp: "Select all kind of Objects apart from Polylines: ". 

How to write it? What expressions to use?

 

Since string-valued DXF groups found in the ssget filter list are matched using the same criteria as the wcmatch function, you can include wildcard operators, such as the "~" (tilde) operator to match everything except the given pattern:

 

(ssget "_X" '((0 . "~*POLYLINE")))

 

Alternatively, you can use the NOT logical operator, e.g.:

 

(ssget "_X" '((-4 . "<NOT") (0 . "*POLYLINE") (-4 . "NOT>")))

 

damian.wrobel wrote:

3.  Why these lisps written by me don't work?

 

Your code looks correct to me - perhaps you have a different definition of the function loaded?

0 Likes
Message 7 of 19

Anonymous
Not applicable

I don't kno what's going on...

Here we have the lisps, I described them.

What is the most wrong thing: These lisps should have effect only on Lines.

So is for only one of these lisps. The others either are broken (they have errors)

or have effect for both Lines and Polylines.

If you don't believe, try it for yourself.

 

; on ground of idea of Lee_Mac

;Selects not only Lines, but Lines and Polylines.
(defun c:SCTAQ (/)
 (princ "\nAll Lines are selected.")
 (sssetfirst nil
  (ssget "_X"
  '((0 . "*LINE"))
  )
 )
)

; Doesn't select not only Lines, but Lines and Polylines.
; SCTA`Qa = SeleCT All Non-Lines (method 'a')
(defun c:SCTA`Qa (/)
 (princ "\nAll Non-Lines (Objects which are not Lines) are selected.")
 (sssetfirst nil
  (ssget "_X"
  '((0 . "~*LINE"))
  )
 )
)

; Doesn't select not only Lines, but Lines and Polylines.
(defun c:SCTA`Qb (/)
 (princ "\nAll Non-Lines (Objects which are not Lines) are selected.")
 (sssetfirst nil
  (ssget "_X"
  '((-4 . "<NOT") (0 . "*LINE") (-4 . "NOT>"))
  )
 )
)

;Selects not only Lines, but Lines and Polylines.
(defun c:SCTTQ (/)
 (princ "\nFor this while you can select only Lines: ")
 (sssetfirst nil
  (ssget 
  '((0 . "*LINE"))
  )
 )
)

; Doesn't select not only Lines, but Lines and Polylines.
(defun c:SCTT`Qa (/)
 (princ "\nFor this while you can select All apart from Lines: ")
 (sssetfirst nil
  (ssget
  '((0 . "~*LINE"))
  )
 )
)

;---

(defun c:SCTT`Qb (/)
 (princ "\nFor this while you can select All apart from Lines: ")
 (sssetfirst nil
 '((-4 . "<NOT")
   (0 . "*POLYLINE")
   (-4 . "NOT>")
  )
 )
)

; You can select as well Lines as Non-Lines.
;Command:  SCTTA`QB
;For this while you can select All apart from Lines: ; error: bad argument type: 
;lselsetp ((-4 . "<NOT") (0 . "*POLYLINE") (-4 . "NOT>"))

;---

; idea of DW

; Is loaded, but doesn't give the effect
;Selects nothing
(defun c:SCTAQ1 (/ AllLinesSelected)
 (princ "\nAll Lines are selected.")
 (setq AllLinesSelected
  (ssget "X"
   '((0 . "LINE"))
  )
 )
)

; Doesn't select not only Lines, but Lines and Polylines.
(defun c:SCTA`Q1a (/ AllNon-LinesSelected)
 (princ "\nAll Non-Lines (Objects which are not Lines) are selected.")
 (setq AllNon-LinesSelected
  (ssget "X" 
   '((0 . "~LINE"))
  )
 )
)


; Doesn't select not only Lines, but Lines and Polylines.
(defun c:SCTA`Q1b (/ AllNon-LinesSelected)
 (princ "\nAll Non-Lines (Objects which are not Lines) are selected.")
 (setq AllNon-LinesSelected 
  (ssget "X" 
   '((-4 . "<NOT") (0 . "*POLYLINE") (-4 . "NOT>"))
  )
 )
)

; works very good
; Selects Lines, but not Polylines, Arcs
(defun c:SCTTQ1
 (/ SelectOnlyLines)
 (princ "\nFor this while you can select only Lines: ")
 (setq SelectOnlyLines
  (ssget
   '((0 . "LINE"))
  )
 )
)

; works very good
; Selects Polylines, Arcs, but not Lines
(defun c:SCTT`Q1a
 (/ SelectApartFromLines)
 (princ "\nFor this while you can select only Lines: ")
 (setq SelectApartFromLines
  (ssget 
   '((0 . "~LINE"))
  )
 )
)


; Doesn't select not only Lines, but Lines and Polylines.
(defun c:SCTT`Q1b
 (/ SelectApartFromLines)
 (princ "\nFor this while you can select All apart from Lines: ")
 (setq SelectApartFromLines 
  (ssget
   '((-4 . "<NOT") (0 . "*LINE") (-4 . "NOT>"))
  )
 )
)

 

0 Likes
Message 8 of 19

Lee_Mac
Advisor
Advisor

Try the following variations -

in my experience it is sometimes necessary to clear any active selection (as noted in the code):

 

; Includes Lines/Polylines/XLines/Splines
(defun c:SCTAQ ( )
    (sssetfirst nil nil) ;; clear any active selection
    (princ "\nAll Lines are selected.")
    (sssetfirst nil (ssget "_X" '((0 . "*LINE"))))
)

; Excludes Lines/Polylines/XLines/Splines
; SCTA`Qa = SeleCT All Non-Lines (method 'a')
(defun c:SCTA`Qa ( )
    (sssetfirst nil nil) ;; clear any active selection
    (princ "\nAll Non-Lines (Objects which are not Lines) are selected.")
    (sssetfirst nil (ssget "_X" '((0 . "~*LINE"))))
)

; Excludes Lines/Polylines/XLines/Splines
(defun c:SCTA`Qb ( )
    (sssetfirst nil nil) ;; clear any active selection
    (princ "\nAll Non-Lines (Objects which are not Lines) are selected.")
    (sssetfirst nil (ssget "_X" '((-4 . ""))))
)

; Includes Lines/Polylines/XLines/Splines (MANUAL SELECTION)
(defun c:SCTTQ ( )
    (sssetfirst nil nil) ;; clear any active selection
    (princ "\nFor this while you can select only Lines: ")
    (sssetfirst nil (ssget '((0 . "*LINE"))))
)

; Excludes Lines/Polylines/XLines/Splines (MANUAL SELECTION)
(defun c:SCTT`Qa ( )
    (sssetfirst nil nil) ;; clear any active selection
    (princ "\nFor this while you can select All apart from Lines: ")
    (sssetfirst nil (ssget '((0 . "~*LINE"))))
)

; Excludes Lines/Polylines/XLines/Splines (MANUAL SELECTION)
(defun c:SCTT`Qb ( )
    (sssetfirst nil nil) ;; clear any active selection
    (princ "\nFor this while you can select All apart from Lines: ")
    (sssetfirst nil (ssget '((-4 . ""))))
)

 

What program/editor are you using to write your code?

0 Likes
Message 9 of 19

Anonymous
Not applicable

I use standard Notepad from Windows.

0 Likes
Message 10 of 19

Lee_Mac
Advisor
Advisor
damian.wrobel wrote:

I use standard Notepad from Windows.

 

I thought so - using standard Notepad makes it incredibly difficult to spot obvious errors such as missed parentheses or typos.

 

I would strongly recommend writing your code using either the Visual LISP IDE (VLIDE) provided with AutoCAD, or a similar code editor (such as Notepad++).

 

Where the VLIDE is concerned, here are a few tutorials to get you started:

 

The Visual LISP Editor - Part 1

The Visual LISP Editor - Part 2

An Introduction to the Visual LISP IDE

Retrieving Information About a Function

A Shortcut to Localising Variables

Debugging Code with the Visual LISP IDE

0 Likes
Message 11 of 19

Kent1Cooper
Consultant
Consultant

I didn't dig too deep, but I did notice one thing you should be careful of:

 

;Selects not only Lines, but Lines and Polylines.
(defun c:SCTAQ (/)
  (princ "\nAll Lines are selected.")
  (sssetfirst nil
    (ssget "_X"
      '((0 . "*LINE"))
    )
  )
)

 

Be aware that the above will find not only Lines and Polylines, but also SPLINEs and XLINEs and MULTILINEs.  If you want only Lines and Polylines, try:

 

      '((0 . "LINE,*POLYLINE"))

 

The same kind of potential overlap may apply to certain other entity types, too.

Kent Cooper, AIA
0 Likes
Message 12 of 19

Anonymous
Not applicable

Now I undarstand the difference between "LINE" and "*LINE".

"LINE" is simply set of Lines. ANd the '*' symbol before 'LINE' represents 'anything from alphabet staying before 'Line'', so we get *=Multi (or simply M), *=Poly, *=X. Thank you for this great notice.

0 Likes
Message 13 of 19

Anonymous
Not applicable
Spoiler
My friend uses Notepad ++ and he recommended me it one year ago. I thought about it at this time one year ago, but I haven't used it so far. And I think I will finally download and use it. Thank you for good advice.
0 Likes
Message 14 of 19

Lee_Mac
Advisor
Advisor
damian.wrobel wrote:

Now I undarstand the difference between "LINE" and "*LINE".

"LINE" is simply set of Lines. ANd the '*' symbol before 'LINE' represents 'anything from alphabet staying before 'Line'', so we get *=Multi (or simply M), *=Poly, *=X. Thank you for this great notice.

 

Since strings within the ssget filter list may be matched using the same operators as the wcmatch function, you may find it useful to read the documentation for this function.

 

0 Likes
Message 15 of 19

Lee_Mac
Advisor
Advisor
damian.wrobel wrote:
My friend uses Notepad ++ and he recommended me it one year ago. I thought about it at this time one year ago, but I haven't used it so far. And I think I will finally download and use it. Thank you for good advice.

 

Notepad++ is indeed a fantastic general code editor - I use it for everything except AutoLISP & DCL as in my opinion, the VLIDE is the most suitable editor for writing AutoLISP, since, although quite dated, the IDE provides an AutoLISP debugger (among other utilities) which can be invaluable for finding problems with your code, as I describe in the tutorial linked earlier.

 

Lee

0 Likes
Message 16 of 19

Anonymous
Not applicable

Lee,

I have this lisps written in two ways:

1st - that is your way, with 'sssetfirst'

2nd - it is my idea. I use local Variables and 'setq'

 

Here we go:

 

; 1st way
; on ground of idea of Lee_Mac

;OK
(defun c:SCTAL (/)
 (princ "\nAll *Lines are selected.")
 (sssetfirst nil
  (ssget "_X"
  '((0 . "*LINE"))
  )
 )
)

; OK
; SCTA`La = SeleCT All Non-_Lines (method 'a')
(defun c:SCTA`La (/)
 (princ "\nAll Non-*Lines (Objects which are not *Lines) are selected.")
 (sssetfirst nil
  (ssget "_X"
  '((0 . "~*LINE"))
  )
 )
)

; OK
(defun c:SCTA`Lb (/)
 (princ "\nAll Non-Lines (Objects which are not *Lines) are selected.")
 (sssetfirst nil
  (ssget "_X"
  '((-4 . "<NOT") (0 . "*LINE") (-4 . "NOT>"))
  )
 )
)

;OK
(defun c:SCTTL (/)
 (princ "\nFor this while you can select only *Lines: ")
 (sssetfirst nil
  (ssget 
  '((0 . "*LINE"))
  )
 )
)

; OK
(defun c:SCTT`La (/)
 (princ "\nFor this while you can select All apart from *Lines: ")
 (sssetfirst nil
  (ssget
  '((0 . "~*LINE"))
  )
 )
)

;---

; OK
(defun c:SCTT`Lb (/)
 (princ "\nFor this while you can select All apart from *Lines: ")
 (sssetfirst nil
  (ssget
  '((-4 . "<NOT") (0 . "*LINE") (-4 . "NOT>"))
  )
 )
)

;---

;2nd way
; idea of DW

; Is loaded, but doesn't give the effect
;Selects nothing

;From CommandLine:
;Command: SCTAL1
;All *Lines are selected.<Selection set: 8f4>

(defun c:SCTAL1 (/ All_LinesSelected)
 (princ "\nAll *Lines are selected.")
 (setq All_LinesSelected
  (ssget "_X"
  '((0 . "*LINE"))
  )
 )
)

;-----

; Is loaded, but doesn't give the effect
;Selects nothing

;From CommandLine:
;Command: SCTA`L1A
;All Non-*Lines (Objects which are not *Lines) are selected.<Selection set: 89e>

(defun c:SCTA`L1a (/ AllNon-_LinesSelected)
 (princ "\nAll Non-*Lines (Objects which are not *Lines) are selected.")
 (setq AllNon-_LinesSelected
  (ssget "_X"
  '((0 . "~*LINE"))
  )
 )
)

;----

; Is loaded, but doesn't give the effect
;Selects nothing

;From CommandLine:
;Command: SCTA`L1B
;All Non-*Lines (Objects which are not *Lines) are selected.<Selection set: 923>

(defun c:SCTA`L1b (/ AllNon-_LinesSelected)
 (princ "\nAll Non-*Lines (Objects which are not *Lines) are selected.")
 (setq AllNon-_LinesSelected 
  (ssget "_X" 
   '((-4 . "<NOT") (0 . "*LINE") (-4 . "NOT>"))
  )
 )
)

; OK
(defun c:SCTTL1
 (/ SelectOnly_Lines)
 (princ "\nFor this while you can select only *Lines: ")
 (setq SelectOnly_Lines
  (ssget
   '((0 . "*LINE"))
  )
 )
)

; OK
(defun c:SCTT`L1a
 (/ SelectApartFrom_Lines)
 (princ "\nFor this while you can select All apart from *Lines: ")
 (setq SelectApartFrom_Lines
  (ssget 
   '((0 . "~*LINE"))
  )
 )
)


; OK
(defun c:SCTT`L1b
 (/ SelectApartFrom_Lines)
 (princ "\nFor this while you can select All apart from *Lines: ")
 (setq SelectApartFrom_Lines 
  (ssget
   '((-4 . "<NOT") (0 . "*LINE") (-4 . "NOT>"))
  )
 )
)

 

All of lisps written using 1st method work properly.

But three of lisps written by the 2nd method are loaded without error, but they don't give any effect.

 

Could you please explain me why these three lisps don't work properly?

0 Likes
Message 17 of 19

Anonymous
Not applicable

"The Visual LISP Editor - Part 1

The Visual LISP Editor - Part 2"

 

Afralisp... It is a great site for people who just begin with lisp.

0 Likes
Message 18 of 19

Lee_Mac
Advisor
Advisor
damian.wrobel wrote:

I have this lisps written in two ways:

1st - that is your way, with 'sssetfirst'

2nd - it is my idea. I use local Variables and 'setq'

 

All of lisps written using 1st method work properly.

But three of lisps written by the 2nd method are loaded without error, but they don't give any effect.

 

Could you please explain me why these three lisps don't work properly?

 

The ssget function will attempt to retrieve a selection set using a method determined by the supplied arguments, and if successful, will return this selection set (which your code then assigns to a local variable) - the ssget function does not highlight or grip the selection returned.

 

The sssetfirst function accepts one or two selection sets as arguments and will hightlight and/or grip all objects in the supplied selection sets.

 

I would suggest reading the documentation for each of these functions so that you become familiar with the arguments, returns & behaviour of each function.

 

Lee

0 Likes
Message 19 of 19

hencoop
Advisor
Advisor

Damian,

 

Another good reason to use VLIDE is that you can highlight a function, right-click on it and open the apropos widow which provides a direct link to help on the function (as well as other functions containing the highlighted string).

 

apropos.jpg

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes