Jump to content

Select polylines with the same thickness


thekiki

Recommended Posts

Hi all,

I'm looking for a lisp that when i click on the polyline, i can select all the polylines

   1/ having the same thickness, never mind the color or linetype (solution n°1)

   2/ having the same thickness and color, never mind the linetype (solution n°2).

Thanks for your help.

Link to comment
Share on other sites

I've not been concentrating on this forum for a couple of weeks, the boss wants me to work (which is odd), so not sure how you are with making up a LISP, if I give you some ideas will that help? (the boss still wants work done today, I need to have a word with the boss.....)

 

You can select a polyline with (entsel) or (ssget), ssget might be better here using the reference document from Lee Mac as a guide - filter the selection set for single object selection and for polyline, and then after (entget (ssname -selectionSet- 0) ) to get the entity selected.

 

From there you can get the thickness using (assoc ....) number 39

And colour using (assoc... ) again, with code 62

 

Finally do a new selection set for all items filtering it for (0 . "*POLYLINE")(39 . THICKENSS)(62 . COLOUR) - again using whatever reference online on how to make up the selection set. THICKNESS and COLOUR are what you found from the assoc lines

 

 

Hope that helps a bit.

 

Last question, I am assuming you mean thickness and not line width which is assoc code 40

 

 

The internet can help you put all of this together - but ask where you get stuck and even showing off when you get it to work

 

Link to comment
Share on other sites

Why not familiarize yourself with the FILTER command.
It would be simpler than to build a lisp, in addition once the use acquired, FILTER will allow you to make multiple filters which could be useful to you thereafter to build your selections quickly.

Link to comment
Share on other sites

Here's the basis.

The only thing is: it doesn't work for ByLayer.

 

Command SPST expects the source object to have a line thickness.

Command SPSTC expects the source object to have a line thickness and color.

 

;; 1/ having the same thickness, never mind the color or linetype
(defun c:spst ( / source thickness ss i pickset)
	;; user selects source
	(setq source (car (entsel "\nSelect Source object: ")))
	;; read line thickness
	(setq thickness (cdr (assoc 370 (entget source))))		;; line thickness
	
	;; select all ploylines with that thinkness
	(setq ss (ssget "_X" (list (cons 0 "*POLYLINE") (cons 370 thickness))))
	
	;; now grip these objects
	(setq pickset (ssadd))
	(setq i 0)
	(repeat (sslength ss)
		(ssadd (ssname ss i) pickset)
		(setq i (+ i 1))
	)
	;; this grips the objects
	(sssetfirst nil pickset)
)

;; 2/ having the same thickness and color, never mind the linetype (solution n°2).
(defun c:spstc ( / source thickness ss i pickset)
	(setq source (car (entsel "\nSelect Source object: ")))
	(setq thickness (cdr (assoc 370 (entget source))))		;; line thickness
	(setq color (cdr (assoc 62 (entget source))))		;; color
	
	(setq ss (ssget "_X" (list (cons 0 "*POLYLINE") (cons 370 thickness) (cons 62 color))))
	
	(setq pickset (ssadd))
	(setq i 0)
	(repeat (sslength ss)
		(ssadd (ssname ss i) pickset)
		(setq i (+ i 1))
	)
	(sssetfirst nil pickset)
)

 

Link to comment
Share on other sites

Thanks Emmanuel, but it doesn't work (on the screen we can see:  "Select Source object: ; erreur: valeur de liste SSGET incorrecte")

Link to comment
Share on other sites

Otherwise if you really need a lisp, I have this:
Run DYN_FILTER, move your cursor over a source entity; watch your status bar where the DXF codes of the entity should appear.
If these seem suitable to you, validate with a right-click.
From then on the command (ssget '_X') will appear on the command line with the corresponding options (only the most common DXF codes are used)
Here again you have the possibility of removing certain DXF codes to make the selection more general.
However, you must know the most common DXF codes to use it effectively...

 

(defun data2string (l_dxf / l_dxf lst_pair grp_el typ_el ch1 ch2 ch)
  (setq ch "")
  (while l_dxf
    (setq lst_pair (car l_dxf))
    (setq grp_el (car lst_pair) typ_el (cdr lst_pair))
    (cond
      ((eq (type grp_el) 'INT)
        (setq ch1 (itoa grp_el))
      )
      ((eq (type grp_el) 'REAL)
        (setq ch1 (rtos grp_el 2 4))
      )
      ((eq (type grp_el) 'STR)
        (setq ch1 (strcat "\"" grp_el "\""))
      )
      (T
        (setq ch1 "")
      )
    )
    (cond
      ((eq (type typ_el) 'INT)
        (setq ch2 (itoa typ_el))
      )
      ((eq (type typ_el) 'REAL)
        (setq ch2 (rtos typ_el 2 4))
      )
      ((eq (type typ_el) 'STR)
        (setq ch2 (strcat "\"" typ_el "\""))
      )
      ((eq (type typ_el) 'LIST)
        (setq ch2 (strcat (rtos (car typ_el) 2 4) " " (rtos (cadr typ_el) 2 4) (if (caddr typ_el) (strcat " " (rtos (caddr typ_el) 2 4)) "")))
      )
      (T
        (setq ch2 "")
      )
    )
    (if (eq (type typ_el) 'LIST)
      (setq ch (strcat ch "(" ch1 " " ch2 ") "))
      (setq ch (strcat ch "(" ch1 " . " ch2 ") "))
    )
    (setq l_dxf (cdr l_dxf) ch1 "" ch2 "")
  )
  (strcat "(" ch ")")
)
(defun c:dyn_filter ( / sv_shmnu oldim key pt_sel l_dxfcod m_filt ent dxf_ent typ_ent msg ss)
  (setq
    sv_shmnu (getvar "SHORTCUTMENU")
    oldim (getvar "dimzin")
  )
  (setvar "dimzin" 0)
  (setvar "SHORTCUTMENU" 11)
  (while (and (setq key (grread T 4 0)) (not (member key '((2 13) (2 32)))) (/= (car key) 25))
    (setq
      l_dxfcod nil m_filt nil
      pt_sel (osnap (list (caadr key) (cadadr key)) "_near")
    )
    (if pt_sel
      (progn
        (setq ss (ssget "_C" pt_sel pt_sel))
        (if ss (setq ent (ssname ss 0)))
      )
      (setq ent (car (nentselp (list (caadr key) (cadadr key)))))
    )
    (cond
      (ent
        (setq dxf_ent (entget ent))
        (setq l_dxfcod (append '(38 39 48 370 62 6 8 67 0) l_dxfcod))
        (if (member (cdr (assoc 0 dxf_ent)) '("HATCH" "INSERT" "MLINE" "SHAPE"))
          (if (assoc 2 dxf_ent) (setq l_dxfcod (cons 2 l_dxfcod)))
        )
        (foreach n l_dxfcod (if (assoc n dxf_ent) (setq m_filt (cons (assoc n dxf_ent) m_filt))))
        (grtext -2 (data2string m_filt))
      )
      (T (grtext -2 ""))
    )
  )
  (cond
    (dxf_ent
      (setq typ_ent (cdr (assoc 0 dxf_ent)) m_filt nil)
      (cond
        ((eq typ_ent "LWPOLYLINE")
          (setq l_dxfcod (cons 43 l_dxfcod))
        )
        ((or (eq typ_ent "POLYLINE") (eq typ_ent "MLINE") (eq typ_ent "SPLINE"))
          (setq l_dxfcod (cons 70 l_dxfcod))
        )
        ((or (eq typ_ent "DIMENSION") (eq typ_ent "LEADER"))
          (setq l_dxfcod (cons 3 l_dxfcod))
          (setq l_dxfcod (cons 70 l_dxfcod))
        )
        ((or (eq typ_ent "ARC") (eq typ_ent "CIRCLE") (eq typ_ent "ELLIPSE"))
          (setq l_dxfcod (cons 40 l_dxfcod))
        )
        ((or (eq typ_ent "TEXT") (eq typ_ent "MTEXT") (eq typ_ent "ATTDEF"))
          (setq l_dxfcod (cons 7 l_dxfcod))
          (setq l_dxfcod (cons 40 l_dxfcod))
        )
      )
      (foreach n l_dxfcod (if (assoc n dxf_ent) (setq m_filt (cons (assoc n dxf_ent) m_filt))))
      (princ (strcat "\n(ssget \"" "_X" "\" " (data2string m_filt) ")"))
      (setq msg "")
      (initget (foreach n m_filt (setq msg (strcat (itoa (car n)) " " msg))))
      (setq msg "")
      (setq msg (strcat "\nDXF code to delete? [" (foreach n m_filt (setq msg (strcat (itoa (car n)) "/" msg))) "]"))
      (while (setq what (getkword msg))
        (setq m_filt (vl-remove (assoc (atoi what) m_filt) m_filt))
        (princ (strcat "\n(ssget \"" "_X" "\"" (data2string m_filt) ")"))
        (setq msg "")
        (initget (foreach n m_filt (setq msg (strcat (itoa (car n)) " " msg))))
        (setq msg "")
        (setq msg (strcat "\nDXF code to delete? [" (foreach n m_filt (setq msg (strcat (itoa (car n)) "/" msg))) "]"))
      )
      (if (zerop (getvar "PICKFIRST")) (setvar "PICKFIRST" 1))
      (sssetfirst nil nil)
      (setq ss (ssget "_X" m_filt))
      (princ (strcat "\n" (itoa (sslength ss)) " selected similar objects."))
      (sssetfirst nil ss)
    )
    (T (princ "\nNo selection"))
  )
  (setvar "SHORTCUTMENU" sv_shmnu)
  (setvar "dimzin" oldim) 
  (prin1)
)

 

Link to comment
Share on other sites

1 hour ago, Emmanuel Delay said:

Oh, you got a French Autocad.  Yeah, that complicates things.

 

 

would this be the fix?

 

(setq ss (ssget "_X" '((0 . "*POLYLINE") (370 . thickness))))

 

 

Thinking language variation and taking out English words in the commands?

Link to comment
Share on other sites

@Emmanuel Delay

Your code is good even in French
It would only be necessary to agree on the term thickness (Height of the polyline: DXF 39 or Lineweight of the polyline: DXF 370)
Because indeed if the polyline entity has no Lineweight then your code fails (bad list for ssget)
If the polyline has Lineweight then it works

Link to comment
Share on other sites

Ah, I get it.

Your line thinkness is not line thickness, it's global width of the polyline.

 

I'll see what I can do tomorrow (unless someone is faster)

 

Link to comment
Share on other sites

33 minutes ago, Emmanuel Delay said:

I'll see what I can do tomorrow (unless someone is faster)

On  @Emmanuel Delay  permit

 

;; 1/ having the same thickness, never mind the color or linetype
(defun c:spst-43 ( / source thickness ss i pickset)
	;; user selects source
	(setq source (car (entsel "\nSelect Source object: ")))
	;; read line thickness
	(setq thickness (cdr (assoc 43 (entget source))))		;; line thickness
	
	;; select all ploylines with that thinkness
	(setq ss (ssget "_X" (list (cons 0 "*POLYLINE") (cons 43 thickness))))
	
	;; now grip these objects
	(setq pickset (ssadd))
	(setq i 0)
	(repeat (sslength ss)
		(ssadd (ssname ss i) pickset)
		(setq i (+ i 1))
	)
	;; this grips the objects
	(sssetfirst nil pickset)
)

;; 2/ having the same thickness and color, never mind the linetype (solution n°2).
(defun c:spstc-43-62 ( / source thickness ss i pickset)
	(setq source (car (entsel "\nSelect Source object: ")))
	(setq thickness (cdr (assoc 43 (entget source))))		;; line thickness
	(setq color (cdr (assoc 62 (entget source))))		;; color
	
	(setq ss (ssget "_X" (list (cons 0 "*POLYLINE") (cons 43 thickness) (cons 62 color))))
	
	(setq pickset (ssadd))
	(setq i 0)
	(repeat (sslength ss)
		(ssadd (ssname ss i) pickset)
		(setq i (+ i 1))
	)
	(sssetfirst nil pickset)
)

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...