Author Topic: MLeader Attribute Text filtering  (Read 3663 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
MLeader Attribute Text filtering
« on: October 26, 2016, 09:24:57 AM »
Anyone have an idea how to get the value or an attribute that is within a mleader, and move it to a layer? Or even filter out a selection set by the attributes value?

Basically, messing around with mleader for a rev-triangle. Want to take the value and place it on the same layer as the revision cloud.

Thanks for the help again!
Civil3D 2020

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: MLeader Attribute Text filtering
« Reply #1 on: October 26, 2016, 10:52:39 AM »
I found some code that will filter out the mleader style and block based upon the tag values of the attribute. However looking for away to translate what it found to a layer name is the next task.

Code: [Select]
(defun c:SLCT-MLDR (/ _MLAttValue BlockColl ss i e f)
(vl-load-com)
;http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/search-for-existing-mleader-wtih-attribute-value/td-p/3930707
;;; pBe 22May2013 ;;;
;; Demo for Mtext Block Attribute ;;;
(defun _MLAttValue (en et tag coll / n i attag)
(setq n -1
i (1- (vla-get-count et))
)
(while (and (null attag) (< n i))
(if (And (eq "AcDbAttributeDefinition"
(vla-get-ObjectName (setq x (vla-item et (setq n (1+ n)))))
)
(eq tag (vla-get-TagString x))
)
(setq attag (vla-getBlockAttributeValue en (vla-get-ObjectID x)))
)
)
)
(setq BlockColl
(vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object)))
)
(if (setq ss (ssget "_:L" '((0 . "MULTILEADER"))))
(repeat (setq i (sslength ss))
(setq e (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
(if (And
;(Eq (vla-get-ContentBlockName e) "_TagBox")
(Eq (vla-get-ContentBlockName e) "_TagTriangle")
(setq f (_mlattvalue
e
;(vla-item BlockColl "_TagBox")
(vla-item BlockColl "_TagTriangle")
 "TAGNUMBER"
BlockColl
)
)
)
(princ (Strcat "\nDo your thing here with the value: \"" f "\""))
(princ "\nTag not Found:")
)
)
)(princ)
)
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7527
Re: MLeader Attribute Text filtering
« Reply #2 on: October 26, 2016, 11:28:03 AM »
Why not just put the mleader on the rev cloud layer & make sure the attribute in the block definition is on layer 0 ?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: MLeader Attribute Text filtering
« Reply #3 on: October 26, 2016, 11:32:34 AM »
Well. That's currently what I am doing. However, there are a crap load of drawings where those mleaders are on one layer and I need to move them over to the correct layer. Gotta love it!
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7527
Re: MLeader Attribute Text filtering
« Reply #4 on: October 26, 2016, 11:37:53 AM »
If they are all sharing a common style, you could filter by that name then put them on the appropriate layer.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: MLeader Attribute Text filtering
« Reply #5 on: October 26, 2016, 11:45:39 AM »
Ron,
This is what I am looking at. I hope this might shed some light. lol.
Civil3D 2020

ChrisCarlson

  • Guest
Re: MLeader Attribute Text filtering
« Reply #6 on: October 26, 2016, 12:01:31 PM »
Oh, look at the following

Code - Auto/Visual Lisp: [Select]
  1. (setq revval (vla-get-TextString (vlax-ename->vla-object attrib)))

Code - Auto/Visual Lisp: [Select]
  1. (vla-put-Layer attrib (strcat "rev" revval))

ronjonp

  • Needs a day job
  • Posts: 7527
Re: MLeader Attribute Text filtering
« Reply #7 on: October 26, 2016, 12:25:47 PM »

Here's a quick one .. could also be done by reading the att value & using (strcat "REV" attvalue) .. think you can figure it out? :)

Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ cld el p ss ss2 x)
  2.   (if (and (setq ss (ssget "x" '((0 . "multileader") (8 . "revs"))))
  3.       (setq ss2 (ssget "x" '((0 . "lwpolyline") (8 . "rev*"))))
  4.       )
  5.     (progn (setq ss (mapcar 'cadr (ssnamex ss)))
  6.       (setq ss2 (mapcar 'cadr (ssnamex ss2)))
  7.       (foreach x ss
  8.         (setq p (cdr (assoc 10 (setq el (entget x)))))
  9.         (setq cld
  10.           (cdar (vl-sort
  11.              (mapcar '(lambda (x) (cons (distance p (vlax-curve-getclosestpointto x p)) x))
  12.                 ss2
  13.              )
  14.              '(lambda (a b) (< (car a) (car b)))
  15.            )
  16.           )
  17.         )
  18.         (entmod (subst (assoc 8 (entget cld)) (assoc 8 el) el))
  19.       )
  20.     )
  21.   )
  22.   (princ)
  23. )
« Last Edit: October 26, 2016, 05:11:47 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: MLeader Attribute Text filtering
« Reply #8 on: October 26, 2016, 12:50:41 PM »
Minor nitpick:
Code - Auto/Visual Lisp: [Select]
  1. (entmod (subst (cons 8 (cdr (assoc 8 (entget cld)))) (cons 8 (cdr (assoc 8 el))) el))

Is the same as:
Code - Auto/Visual Lisp: [Select]
  1. (entmod (subst (assoc 8 (entget cld)) (assoc 8 el) el))

:wink:

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: MLeader Attribute Text filtering
« Reply #9 on: October 26, 2016, 12:53:55 PM »
Woohoo! you just saved my fingers .. or mouse clicker for that matter... Thank you very much!

Just curious here... How are you pasting the code with the numbers labeling each line? Im just using notepad.
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7527
Re: MLeader Attribute Text filtering
« Reply #10 on: October 26, 2016, 12:56:30 PM »
Minor nitpick:
Code - Auto/Visual Lisp: [Select]
  1. (entmod (subst (cons 8 (cdr (assoc 8 (entget cld)))) (cons 8 (cdr (assoc 8 el))) el))

Is the same as:
Code - Auto/Visual Lisp: [Select]
  1. (entmod (subst (assoc 8 (entget cld)) (assoc 8 el) el))

 ;)
Fixed ... funny thing is I know that but did not translate to my fingers LOL.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: MLeader Attribute Text filtering
« Reply #11 on: October 26, 2016, 01:05:53 PM »
Some minor efficiency improvements:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:bar ( / dis ent enx idx lst mls pls pnt tmp )
  2.     (if (and (setq mls (ssget "_x" '((0 . "multileader") (8 . "revs"))))
  3.              (setq pls (ssget "_x" '((0 . "lwpolyline")  (8 . "rev*"))))
  4.         )
  5.         (progn
  6.             (repeat (setq idx (sslength pls))
  7.                 (setq lst (cons (ssname pls (setq idx (1- idx))) lst))
  8.             )
  9.             (repeat (setq idx (sslength mls))
  10.                 (setq enx (entget (ssname mls (setq idx (1- idx))))
  11.                       pnt (cdr (assoc 10 enx))
  12.                       ent (car lst)
  13.                       dis 1e308
  14.                 )
  15.                 (foreach ply lst
  16.                     (if (< (setq tmp (distance pnt (vlax-curve-getclosestpointto ply pnt))) dis)
  17.                         (setq dis tmp ent ply)
  18.                     )
  19.                 )
  20.                 (entmod (subst (assoc 8 (entget ent)) (assoc 8 enx) enx))
  21.             )
  22.         )
  23.     )
  24.     (princ)
  25. )

ronjonp

  • Needs a day job
  • Posts: 7527
Re: MLeader Attribute Text filtering
« Reply #12 on: October 26, 2016, 05:09:18 PM »
...

Just curious here... How are you pasting the code with the numbers labeling each line? Im just using notepad.
Here is a nice read on formatting your posts. Glad we got the problem sorted :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: MLeader Attribute Text filtering
« Reply #13 on: October 26, 2016, 05:23:29 PM »
Cool. Thanks for sharing that!
Civil3D 2020

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: MLeader Attribute Text filtering
« Reply #14 on: March 31, 2017, 03:12:47 PM »
I hate to bring this topic back. I have downloaded the REV dwg and with the routine it works. However, I am not getting drawings where this does not work. The blocks look the same but the way they are compiled looked slightly different.

The original REV mleader property was a source block "Triangle".

These new REV mleader property has a source block "User Block".

So I guess what property do I need to change to get this to work with these revised revs?

Thanks for the input again.
Civil3D 2020