TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Fabricio28 on February 16, 2017, 11:06:44 AM

Title: Select the similiar
Post by: Fabricio28 on February 16, 2017, 11:06:44 AM
Hi all,

I have 2 different MText in my drawing.
- Area
- Lot Number

But this MText is the same layer "-AREA-LOTES".
I'd like to select all MText to Lot Numbers and change to "-NRO-LOTE" layer.

Is it possible?

I was trying to use select the similiar. But I couldn't do that.

Thank in advance
Fabricio
Title: Re: Select the similiar
Post by: ronjonp on February 16, 2017, 11:19:25 AM
Code - Auto/Visual Lisp: [Select]
  1. (sssetfirst nil (ssget "_x" '((0 . "mtext") (1 . "#,##"))))
Title: Re: Select the similiar
Post by: Andrea on February 16, 2017, 11:23:01 AM
Code: [Select]
(defun c:SSIM (/ circles #count centerp item Mtexts MtextObject vlaitem)
  (setq circles (ssget "_X"
       '((0 . "CIRCLE")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "-NRO-LOTE")
(100 . "AcDbCircle")
)
)
  )
  (repeat (setq #count (sslength circles))
    (setq item (ssname circles (setq #count (1- #count))))
    (setq centerp (assoc 10 (entget item)))
    (if (setq Mtexts (ssget "_X"
    (list
      '(0 . "MTEXT")
      centerp
    )
     )
)
      (progn
(setq MtextObject (ssname Mtexts 0))
(setq vlaitem (vlax-ename->vla-object MTextobject))
(vla-put-layer vlaitem "-NRO-LOTE")
      )
    )

  )
  (princ)
)
Title: Re: Select the similiar
Post by: Fabricio28 on February 16, 2017, 11:23:48 AM
Code - Auto/Visual Lisp: [Select]
  1. (sssetfirst nil (ssget "_x" '((0 . "mtext") (1 . "#,##"))))

very nice solution my old friend Ron,

Worked like a charm.

Thanks :)
Title: Re: Select the similiar
Post by: Andrea on February 16, 2017, 11:24:47 AM
Code - Auto/Visual Lisp: [Select]
  1. (sssetfirst nil (ssget "_x" '((0 . "mtext") (1 . "#,##"))))

+Kudo
Title: Re: Select the similiar
Post by: ronjonp on February 16, 2017, 11:27:48 AM
Thanks guys :)
Title: Re: Select the similiar
Post by: Fabricio28 on February 16, 2017, 11:29:04 AM
Code: [Select]
(defun c:SSIM (/ circles #count centerp item Mtexts MtextObject vlaitem)
  (setq circles (ssget "_X"
       '((0 . "CIRCLE")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "-NRO-LOTE")
(100 . "AcDbCircle")
)
)
  )
  (repeat (setq #count (sslength circles))
    (setq item (ssname circles (setq #count (1- #count))))
    (setq centerp (assoc 10 (entget item)))
    (if (setq Mtexts (ssget "_X"
    (list
      '(0 . "MTEXT")
      centerp
    )
     )
)
      (progn
(setq MtextObject (ssname Mtexts 0))
(setq vlaitem (vlax-ename->vla-object MTextobject))
(vla-put-layer vlaitem "-NRO-LOTE")
      )
    )

  )
  (princ)
)

Wow :)
Very Nice too Andrea!!

Thank you very much.
Fabricio
Title: Re: Select the similiar
Post by: Fabricio28 on February 16, 2017, 11:34:40 AM
Code: [Select]
(defun c:SSIM (/ circles #count centerp item Mtexts MtextObject vlaitem)
  (setq circles (ssget "_X"
       '((0 . "CIRCLE")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "-NRO-LOTE")
(100 . "AcDbCircle")
)
)
  )
  (repeat (setq #count (sslength circles))
    (setq item (ssname circles (setq #count (1- #count))))
    (setq centerp (assoc 10 (entget item)))
    (if (setq Mtexts (ssget "_X"
    (list
      '(0 . "MTEXT")
      centerp
    )
     )
)
      (progn
(setq MtextObject (ssname Mtexts 0))
(setq vlaitem (vlax-ename->vla-object MTextobject))
(vla-put-layer vlaitem "-NRO-LOTE")
      )
    )

  )
  (princ)
)

If the circle were in the " -AREA-LOTE" the code isn't working.

My first step is change the circle and the number to "-NRO-LOTE".
But I can select the similar all circle and change the layer as I want to. But couldn't do that to the number.

Will be good if I able to change boths (circle and Number) to "-NRO-LOTE" layer.

Thanks
Title: Re: Select the similiar
Post by: ronjonp on February 16, 2017, 11:38:17 AM
Why don't you make a block with an attribute?
Title: Re: Select the similiar
Post by: Fabricio28 on February 16, 2017, 11:43:22 AM
Why don't you make a block with an attribute?

Because I've exploded that elements from autocad civil 3D.  :-D

Title: Re: Select the similiar
Post by: Andrea on February 16, 2017, 11:48:05 AM
Code: [Select]
(defun c:SSIM (/ circles #count centerp item Mtexts MtextObject vlaitem)
  (setq circles (ssget "_X"
       '((0 . "CIRCLE")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "-NRO-LOTE")
(100 . "AcDbCircle")
)
)
  )
  (repeat (setq #count (sslength circles))
    (setq item (ssname circles (setq #count (1- #count))))
    (setq centerp (assoc 10 (entget item)))
    (if (setq Mtexts (ssget "_X"
    (list
      '(0 . "MTEXT")
      centerp
    )
     )
)
      (progn
(setq MtextObject (ssname Mtexts 0))
(setq vlaitem (vlax-ename->vla-object MTextobject))
(vla-put-layer vlaitem "-NRO-LOTE")
      )
    )

  )
  (princ)
)

If the circle were in the " -AREA-LOTE" the code isn't working.

My first step is change the circle and the number to "-NRO-LOTE".
But I can select the similar all circle and change the layer as I want to. But couldn't do that to the number.

Will be good if I able to change boths (circle and Number) to "-NRO-LOTE" layer.

Thanks

why do not mix both code ?
my filtering object is to detext all circle and compare centerpoints to MTEXT who have same centerpoints..

but you can use Ron filtering selection.. :)
or,..
remove the layer filtering..
Code: [Select]
(setq circles (ssget "_X"
       '((0 . "CIRCLE")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
; (8 . "-NRO-LOTE")
(100 . "AcDbCircle")
)
)
  )
Title: Re: Select the similiar
Post by: ronjonp on February 16, 2017, 11:51:03 AM
Why don't you make a block with an attribute?

Because I've exploded that elements from autocad civil 3D.  ;D
>:D  .. this is how I'd do it.
Title: Re: Select the similiar
Post by: Fabricio28 on February 16, 2017, 12:00:17 PM
Why don't you make a block with an attribute?

Because I've exploded that elements from autocad civil 3D.  ;D
>:D  .. this is how I'd do it.

Wow!

Do you make a block with the circles and numbers. How could you do that?

Amazing
Title: Re: Select the similiar
Post by: ronjonp on February 16, 2017, 12:07:37 PM
Why don't you make a block with an attribute?

Because I've exploded that elements from autocad civil 3D.  ;D
>:D  .. this is how I'd do it.

Wow!

Do you make a block with the circles and numbers. How could you do that?

Amazing
Code  ;)
Title: Re: Select the similiar
Post by: Fabricio28 on February 16, 2017, 12:23:32 PM
Why don't you make a block with an attribute?

Because I've exploded that elements from autocad civil 3D.  ;D
>:D  .. this is how I'd do it.

Wow!

Do you make a block with the circles and numbers. How could you do that?

Amazing
Code  ;)

I see...
Very impressive  :-)
Title: Re: Select the similiar
Post by: ronjonp on February 16, 2017, 03:13:49 PM
Here's something to layer the circle & text objects based on your example drawing:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ ss)
  2.   (if (setq ss (ssget "_x"
  3.                       '((-4 . "<OR")
  4.                         (-4 . "<AND")
  5.                         (0 . "mtext")
  6.                         (1 . "#,##")
  7.                         (-4 . "AND>")
  8.                         (-4 . "<AND")
  9.                         (0 . "circle")
  10.                         (-4 . "<=")
  11.                         (40 . 1.5)
  12.                         (-4 . "AND>")
  13.                         (-4 . "OR>")
  14.                        )
  15.                )
  16.       )
  17.     (foreach x (mapcar 'cadr (ssnamex ss))
  18.       (entmod (subst '(8 . "-NRO-LOTE") (assoc 8 (entget x)) (entget x)))
  19.     )
  20.   )
  21.   (princ)
  22. )
Title: Re: Select the similiar
Post by: Fabricio28 on February 17, 2017, 05:28:54 AM
Here's something to layer the circle & text objects based on your example drawing:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ ss)
  2.   (if (setq ss (ssget "_x"
  3.                       '((-4 . "<OR")
  4.                         (-4 . "<AND")
  5.                         (0 . "mtext")
  6.                         (1 . "#,##")
  7.                         (-4 . "AND>")
  8.                         (-4 . "<AND")
  9.                         (0 . "circle")
  10.                         (-4 . "<=")
  11.                         (40 . 1.5)
  12.                         (-4 . "AND>")
  13.                         (-4 . "OR>")
  14.                        )
  15.                )
  16.       )
  17.     (foreach x (mapcar 'cadr (ssnamex ss))
  18.       (entmod (subst '(8 . "-NRO-LOTE") (assoc 8 (entget x)) (entget x)))
  19.     )
  20.   )
  21.   (princ)
  22. )

Ron,

Fantastic!!!

Worked like a charm.

Thank you very much for the help. :)

Fabricio
Title: Re: Select the similiar
Post by: ronjonp on February 17, 2017, 11:33:20 AM
 :)