Author Topic: Xlist Block Name to MLeader Text  (Read 4023 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2598
  • I can't remeber what I already asked! I need help!
Xlist Block Name to MLeader Text
« on: March 25, 2021, 01:12:00 PM »
I am sure this has been asked here before. I am not having any luck finding it.

Is there a way I can take the xlist Block Name (only) into a MLeader?

I have seen similar routines which take the block name from the current dwg into MLeader, but not from within a xref.


The other question i would have is if, a block is buried 4 levels down. (1.Xref, 2.Block, 3.Inside Block2. 4.Inside Block3).

Could it still get the block name?

Thanks for any help on this!

Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Xlist Block Name to MLeader Text
« Reply #1 on: March 25, 2021, 03:25:13 PM »
Use NENTSEL like so:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ a e)
  2.   (if (setq e (nentsel "\nPick a block: "))
  3.     (foreach b (append (list (car e)) (last e))
  4.       (if (setq a (cdr (assoc 2 (entget b))))
  5.         (print a)
  6.       )
  7.     )
  8.   )
  9.   (princ)
  10. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2598
  • I can't remeber what I already asked! I need help!
Re: Xlist Block Name to MLeader Text
« Reply #2 on: March 25, 2021, 04:35:44 PM »
Thanks for the hint down the road.

I was able to get the mleader in it. It now shows with the following:
MLeader Text Shows (xUtility|site - transformer_1) <--- Anyway to remove the "|" and the prior xUtility?)

Code: [Select]
(defun c:foo1 (/ a e)
  (if (setq e (nentsel "\nPick a block: "))
    (foreach b (append (list (car e)) (last e))
      (if (setq a (cdr (assoc 2 (entget b))))
       (vl-cmdf "_.Mleader" "\\" "\\" a) ;;Added MLeader
;;MLeader Text Shows (xUtility|site - transformer_1)<--- Anyway to remove the "|" and the prior xUtility?)
      )
    )
  )
  (princ)
)

thank you again.
Civil3D 2020

Tharwat

  • Swamp Rat
  • Posts: 707
  • Hypersensitive
Re: Xlist Block Name to MLeader Text
« Reply #3 on: March 25, 2021, 06:17:26 PM »
You can explore your second thread in CADTutor for more info about parsing a string in Mleader object.  :grinwink:

https://www.cadtutor.net/forum/topic/72594-removing-text-in-front-of-a-dash-mtext/?tab=comments#comment-578797

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Xlist Block Name to MLeader Text
« Reply #4 on: March 25, 2021, 06:26:05 PM »
MP to the rescue again ( he helped me with the same problem 15 years ago ) ...  use stripxrefprefix from here: http://www.theswamp.org/index.php?topic=9293.msg119755#msg119755

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2598
  • I can't remeber what I already asked! I need help!
Re: Xlist Block Name to MLeader Text
« Reply #5 on: March 26, 2021, 08:53:51 AM »
Thank you Ron for saving the day. Apparently i am 15 years to late. Anyways, the function makes sense. I am trying to figure out how to add the "Select Previous" command within the function of the routine. I am hoping that once the Mleader is created with the block values in it, i could activate the function to remove the prefix stuff inside it.

Code: [Select]
(defun StripXrefPrefix ( string / position )
    (if (setq position (vl-string-position 124 string 0 t))
        (substr string (+ 2 position))
        string
    )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:foo2 (/ a e)
  (if (setq e (nentsel "\nPick a block: "))
    (foreach b (append (list (car e)) (last e))
      (if (setq a (cdr (assoc 2 (entget b))))
       (vl-cmdf "_.Mleader" "\\" "\\" a) ;;Added MLeader
 ;;      (StripString "123|456|789" "|");; Example
       (StripString "previous" "|");;MLeader Text Shows (xUtility|site - transformer_1)<--- Anyway to remove the "|" and the prior xUtility?)
      )
    )
  )
  (princ)
)
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Xlist Block Name to MLeader Text
« Reply #6 on: March 26, 2021, 04:05:30 PM »
The code I posted retrieves all the nested blocks. Do you want all this info in the mleader?

Try this .. lists blocks from the top down:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo2 (/ stripxrefprefix a e r)
  2.   (defun stripxrefprefix (string / position)
  3.     (if (setq position (vl-string-position 124 string 0 t))
  4.       (substr string (+ 2 position))
  5.       string
  6.     )
  7.   )
  8.   (if (setq e (nentsel "\nPick a block: "))
  9.     (progn (setq r "")
  10.            (foreach b (append (list (car e)) (last e))
  11.              (and (setq a (cdr (assoc 2 (entget b)))) (setq r (strcat (stripxrefprefix a) "\\\P" r)))
  12.            )
  13.            (vl-cmdf "_.Mleader" (cadr e) "\\" r)
  14.     )
  15.   )
  16.   (princ)
  17. )
« Last Edit: March 26, 2021, 04:19:39 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2598
  • I can't remeber what I already asked! I need help!
Re: Xlist Block Name to MLeader Text
« Reply #7 on: March 29, 2021, 07:22:18 AM »
I see where your coming from with what you have posted. Within what you have shown, I am still trying to remove the "XREF|" portion of the information that list from the block down. The Block Name is what I am trying to show within the mleader text.

The last post i had, it was kind of a two step process that i tried to force but failed making it smooth lol.
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Xlist Block Name to MLeader Text
« Reply #8 on: March 29, 2021, 11:24:04 AM »
I see where your coming from with what you have posted. Within what you have shown, I am still trying to remove the "XREF|" portion of the information that list from the block down. The Block Name is what I am trying to show within the mleader text.

The last post i had, it was kind of a two step process that i tried to force but failed making it smooth lol.
The example above will remove the 'XREF|' part of the names ... did you try it?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2598
  • I can't remeber what I already asked! I need help!
Re: Xlist Block Name to MLeader Text
« Reply #9 on: March 29, 2021, 12:51:46 PM »
Sure did. foo2. It seems it removed the "|".
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Xlist Block Name to MLeader Text
« Reply #10 on: March 29, 2021, 05:54:54 PM »
So are you good?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2598
  • I can't remeber what I already asked! I need help!
Re: Xlist Block Name to MLeader Text
« Reply #11 on: March 30, 2021, 11:33:02 AM »
Within the code, could i get to strip out the xref name and just the block name?

Code: [Select]
(and (setq a (cdr (assoc 2 (entget b)))) (setq r (strcat (stripxrefprefix a) "\\\P" r)))
I thought initially it was the "|" character that was supposed to find and remove.

In the snapshot above, if it could remove the "xUtility" portion, i think it would be fine!

Just a thought, i have not tried this yet, but it should return block names for dynamic blocks too?

Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Xlist Block Name to MLeader Text
« Reply #12 on: March 30, 2021, 12:31:09 PM »
Within the code, could i get to strip out the xref name and just the block name?

Code: [Select]
(and (setq a (cdr (assoc 2 (entget b)))) (setq r (strcat (stripxrefprefix a) "\\\P" r)))
I thought initially it was the "|" character that was supposed to find and remove.

In the snapshot above, if it could remove the "xUtility" portion, i think it would be fine!

Just a thought, i have not tried this yet, but it should return block names for dynamic blocks too?
Maybe this:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo2 (/ stripxrefprefix a e r)
  2.   (defun stripxrefprefix (string / position)
  3.     (if (setq position (vl-string-position 124 string 0 t))
  4.       (substr string (+ 2 position))
  5.       string
  6.     )
  7.   )
  8.   (if (cadddr (setq e (nentsel "\nPick a block: ")))
  9.     (progn
  10.       (setq r (stripxrefprefix (vla-get-effectivename (vlax-ename->vla-object (car (cadddr e))))))
  11.       (vl-cmdf "_.Mleader" (cadr e) "\\" r)
  12.     )
  13.   )
  14.   (princ)
  15. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MSTG007

  • Gator
  • Posts: 2598
  • I can't remeber what I already asked! I need help!
Re: Xlist Block Name to MLeader Text
« Reply #13 on: March 30, 2021, 01:28:29 PM »
Boom baby! you hit it....

Could I ask why was it changed to this?

Code: [Select]
(setq r (stripxrefprefix (vla-get-effectivename (vlax-ename->vla-object (car (cadddr e))))))
I dont remember seeing anything like this "cadddr e".
Civil3D 2020

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Xlist Block Name to MLeader Text
« Reply #14 on: March 30, 2021, 03:05:59 PM »
Boom baby! you hit it....

Could I ask why was it changed to this?

Code: [Select]
(setq r (stripxrefprefix (vla-get-effectivename (vlax-ename->vla-object (car (cadddr e))))))
I dont remember seeing anything like this "cadddr e".
CADDDR looks for the 4th item in a list. If a block is selected with nentsel, the container of the item is within that 4th entry. There could also be multiple blocks within which was why I had the foreach function before.

Use this to investigate: (mapcar 'print (nentsel "\nPick a block: "))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC