TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: MSTG007 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!
-
Use NENTSEL like so:
-
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?)
(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.
-
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 (https://www.cadtutor.net/forum/topic/72594-removing-text-in-front-of-a-dash-mtext/?tab=comments#comment-578797)
-
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
-
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.
(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)
)
-
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:
(defun c:foo2
(/ stripxrefprefix a e r
) (defun stripxrefprefix
(string
/ position
) (substr string
(+ 2 position
)) string
)
)
)
)
)
)
-
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.
-
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?
-
Sure did. foo2. It seems it removed the "|".
-
So are you good?
-
Within the code, could i get to strip out the xref name and just the block name?
(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?
-
Within the code, could i get to strip out the xref name and just the block name?
(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:
(defun c:foo2
(/ stripxrefprefix a e r
) (defun stripxrefprefix
(string
/ position
) (substr string
(+ 2 position
)) string
)
)
)
)
)
-
Boom baby! you hit it....
Could I ask why was it changed to this?
(setq r (stripxrefprefix (vla-get-effectivename (vlax-ename->vla-object (car (cadddr e))))))
I dont remember seeing anything like this "cadddr e".
-
Boom baby! you hit it....
Could I ask why was it changed to this?
(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: "))
-
Nice coding Ronjonp sometimes with deep caddddd etc may be easier to understand using nth must remember though that nth starts at 0.
(vla-get-effectivename (vlax-ename->vla-object (car (nth 3 e))))
"90LU"
(vla-get-effectivename (vlax-ename->vla-object (nth 0 (nth 3 e))))
"90LU"
-
Interesting.... Thanks for sharing what it does. Always learning.... lol
-
An easy way to understand the compound list functions cadr/caddr/caddar/etc. is to recall that they are merely shorthand for a sequence of successive car/cdr functions, e.g.:
_$ (cadddr '(1 2 3 4 5 6 7 8 9))
4
Is equivalent to:
_$ (car (cdr (cdr (cdr '(1 2 3 4 5 6 7 8 9)))))
4
Likewise:
_$ (caddar '((1 2 3 4 5) 6 7 8 9))
3
Is equivalent to:
_$ (car (cdr (cdr (car '((1 2 3 4 5) 6 7 8 9)))))
3
With that knowledge, all you need to remember is that car accesses the first element of a list (car = content of the address register) and cdr removes the first element of a list returning the tail of the list (cdr = content of the decrement register):
_$ (car '(1 2 3 4 5 6 7 8 9))
1
_$ (cdr '(1 2 3 4 5 6 7 8 9))
(2 3 4 5 6 7 8 9)
And so when you see an expression such as:
(cddadr '(1 (2 3 4 5) 6 7 8 9))
You can extract the list item by reading the sequence of 'a's and 'd's from right-to-left.
In the above example, reading from right to left, we have the sequence:
dadd
Which means:
- Remove the first element and return the remainder of the list
- Extract the first element of the list
- Remove the next two elements and return the remainder of the list
Evaluating this in sequence yields:
(cddadr '(1 (2 3 4 5) 6 7 8 9))
(cddar '((2 3 4 5) 6 7 8 9))
(cddr '(2 3 4 5))
(cdr '(3 4 5))
(4 5)
Which is indeed exactly what is returned when testing the expression at the console:
_$ (cddadr '(1 (2 3 4 5) 6 7 8 9))
(4 5)
-
Nice explanation Lee! :-)
-
Haven't used xrefs in years but if for the last "(assoc 3 something)" would (assoc 3 (reverse e)) work the same no matter how deep it was nested?
-
Haven't used xrefs in years but if for the last "(assoc 3 something)" would (assoc 3 (reverse e)) work the same no matter how deep it was nested?
You have to check if there are 4 items in the list to make sure a nested object was picked. This is a little better than just using (last e):
(defun c:foo
(/ stripxrefprefix a e r
) (defun stripxrefprefix
(string
/ position
) (substr string
(+ 2 position
)) string
)
)
)
)
)
)
)
)
-
20210401 Edit: for ronionp
Haven't used xrefs in years but if for the last "(assoc 3 something)" would (assoc 3 (reverse e)) work the same no matter how deep it was nested?
You have to check if there are 4 items in the list to make sure a nested object was picked. This is a little better than just using (last e):
(defun c:foo
(/ stripxrefprefix a e r
) (defun stripxrefprefix
(string
/ position
) (substr string
(+ 2 position
)) string
)
)
)
)
)
)
)
)
I don't know if my question is relevant: if you select a dimension inside the block or an attribute of the block?
-
Nice explanation Lee! :-)
Thanks Ron! :-)
-
Ron, Lee, thank you for sharing more to this! Great information!