Hi all,
I needed a sub-function that I could call with a blockname as an argument and get back a response of T or nil to verify if the blockname is or is not the last entity added to the drawing.
After texting different approaches I got it working like this:
(defun IsBlkLast (blkNm) (IF (= (CDR (ASSOC 2 (ENTGET (ENTLAST)))) blkNm) T NIL))
I tried using:
(defun IsBlkLast (blkNm) (IF (= (VLA-GET-EFFECTIVENAME (VLAX-ENAME->VLA-OBJECT (ENTLAST))) blkNm) T NIL))
But, for whatever reason beyond my understanding, it only worked while part of a longer function and only failed when called as a sub-function.
I'm just curious if anyone can shed some light on this for me. I suppose it wouldn't much matter, but I was hoping to use this universally for standard blocks as well as for dynamic blocks.
Thank you.
Solved! Go to Solution.
Solved by BlackBox_. Go to Solution.
This seems to work for me:
(vl-load-com)
(defun IsBlkLast (blockName / e v)
;; Example: (IsBlkLast "SomeBlockName") (and (setq e (entlast)) (setq v (vlax-ename->vla-object e)) (= "AcDbBlockReference" (vla-get-objectname v)) (= blockName (vla-get-effectivename v)) ) )
"How we think determines what we do, and what we do determines what we get."
@mid-awe wrote:....
I needed a sub-function that I could call with a blockname as an argument and get back a response of T or nil to verify if the blockname is or is not the last entity added to the drawing.
After texting different approaches I got it working like this:
(defun IsBlkLast (blkNm) (IF (= (CDR (ASSOC 2 (ENTGET (ENTLAST)))) blkNm) T NIL))I tried using:
(defun IsBlkLast (blkNm) (IF (= (VLA-GET-EFFECTIVENAME (VLAX-ENAME->VLA-OBJECT (ENTLAST))) blkNm) T NIL))But, for whatever reason beyond my understanding, it only worked while part of a longer function and only failed when called as a sub-function.
....
I would think you could omit the (if)'s with the T and nil at the ends, and just do:
(defun IsBlkLast (blkNm) (= (CDR (ASSOC 2 (ENTGET (ENTLAST)))) blkNm))
and similarly for the other one -- that should return T or nil without your specifying those as return values.
But as for the problem itself, could it be something like an input error, such as entering the Block name without the double-quotes it should have? If you typed in, for instance:
(IsBlkLast Toilet)
instead of
(IsBlkLast "Toilet")
it would not work right. But inside the larger routine, it might work right if the Block name is being derived or extracted in some way, rather than entered by the User. It's hard to say without seeing the larger routine.
(defun _isEntlastBlockName (blockName / o) (and (setq o (entlast)) (eq (vla-get-objectname (setq o (vlax-ename->vla-object o))) "AcDbBlockReference") (eq (strcase (if (vlax-property-available-p o 'EffectiveName) (vla-get-effectivename o) (vla-get-name o) ) ) (strcase blockName) ) ) )
@Kent1Cooper wrote:........ could it be something like an input error, such as entering the Block name without the double-quotes it should have? .....
And another possibility occurred to me: not having the upper- and lower-case combination correct, since (=) is case-sensitive. That can be prevented by applying (strcase) to both strings.
@Kent1Cooper wrote:
@mid-awe wrote:....
I needed a sub-function that I could call with a blockname as an argument and get back a response of T or nil to verify if the blockname is or is not the last entity added to the drawing.
After texting different approaches I got it working like this:
(defun IsBlkLast (blkNm) (IF (= (CDR (ASSOC 2 (ENTGET (ENTLAST)))) blkNm) T NIL))I tried using:
(defun IsBlkLast (blkNm) (IF (= (VLA-GET-EFFECTIVENAME (VLAX-ENAME->VLA-OBJECT (ENTLAST))) blkNm) T NIL))But, for whatever reason beyond my understanding, it only worked while part of a longer function and only failed when called as a sub-function.
....
I would think you could omit the (if)'s with the T and nil at the ends, and just do:
(defun IsBlkLast (blkNm) (= (CDR (ASSOC 2 (ENTGET (ENTLAST)))) blkNm))
Neat idea, Kent... Normally I avoid Entget calls that are dependent on a user selected eName, such as:
(cdr (assoc 2 (entget (car (entsel)))))
... For the obvious reason of mitigating potential error, but as Entlast will always return a valid eName, this works. Nicely done, my friend..
@alanjt_ wrote:(defun _isEntlastBlockName (blockName / o) (and (setq o (entlast)) (eq (vla-get-objectname (setq o (vlax-ename->vla-object o))) "AcDbBlockReference") (eq (strcase (if (vlax-property-available-p o 'EffectiveName) (vla-get-effectivename o) (vla-get-name o) ) ) (strcase blockName) ) ) )
Interesting AT... I've never seen an AcDbBlockReference without an EffectiveName before. I'd be interested to see a sample drawing if it's something commonplace that I've just been oblivious to.
Cheers
"How we think determines what we do, and what we do determines what we get."
@Kent1Cooper wrote:
@Kent1Cooper wrote:........ could it be something like an input error, such as entering the Block name without the double-quotes it should have? .....And another possibility occurred to me: not having the upper- and lower-case combination correct, since (=) is case-sensitive. That can be prevented by applying (strcase) to both strings.
I really dislike Autodesk's forums inability to correct mistakes, update code, etc. of our own posts (beyond the initial timeframe), as (all?) other CAD forums do.
/OffTopic
"How we think determines what we do, and what we do determines what we get."
@BlackBoxCAD wrote:Interesting AT... I've never seen an AcDbBlockReference without an EffectiveName before. I'd be interested to see a sample drawing if it's something commonplace that I've just been oblivious to.
Cheers
As far as I can remember, it dates back to versions before annotative blocks. 2006 and back, maybe?
Well that makes sense then; I was politely educated yesterday that there are many users still using +/-2004 for daily production, and I didn't realize that was an unavailable Property back then (thereabouts).
Always appreciate the clarification, AT... Cheers
"How we think determines what we do, and what we do determines what we get."
Any time. 🙂
Yeah, not every one has a need to upgrade. I have a few surveyor friends that are still running 2002 because for what they do, there's no need to upgrade. Every thing runs fine, their clients are happy and they don't have to kill themselves buying newer machines.