Author Topic: vla-getboundingbox of a block of multileader  (Read 326 times)

0 Members and 1 Guest are viewing this topic.

AARYAN

  • Newt
  • Posts: 72
vla-getboundingbox of a block of multileader
« on: June 14, 2022, 04:38:15 AM »
Hi All,

I am writing a routine and stuck at a point where I need to get the bounding box of a block created with multileader.

1. Setup the mleaderstyle.
2. Inserted Mleader using lisp.
3. (entnext (entlast)) returns nil. Anyway to get the limits?

Thank you in advance for your help!
« Last Edit: June 14, 2022, 10:04:01 AM by AARYAN »

mhupp

  • Newt
  • Posts: 174
Re: vla-getboundingbox of a block of multileader
« Reply #1 on: June 14, 2022, 07:20:17 AM »
Post your code if you want help with it.

kreaten_vhar

  • Mosquito
  • Posts: 3
Re: vla-getboundingbox of a block of multileader
« Reply #2 on: June 14, 2022, 08:06:06 AM »
I had a similar desire in a recent routine I've been working on. I found Lee Mac's Bounding box function http://www.lee-mac.com/boundingbox.html

Using that function in a call like so:

(LM:boundingbox (vlax-ename->vla-object (cdar (entget (entlast)))))

will get you the 4 points that make up the bounds of the most recently added object.

edit:

(vlax-ename->vla-object (cdar (entget (entlast))))

is probably the heart of what you want I'm guessing. As I had a similar experience using (entget (entlast)) not returning what I wanted because I wasn't aware what was going on in the background with regards to the Acad DB. Worth noting I still don't and I'm not sure how mleaders are handled lol
« Last Edit: June 14, 2022, 08:18:22 AM by kreaten_vhar »

AARYAN

  • Newt
  • Posts: 72
Re: vla-getboundingbox of a block of multileader
« Reply #3 on: June 14, 2022, 08:32:42 AM »
Thanks for the reply guys!

I am simply using the command option to insert the multileader.

Code: [Select]
(command "_.MLeader" pt1 pt2)
(while (> (getvar "cmdactive") 1) (command ""))
(setq emleader (entlast))
(setq eblock (entnext emleader)) ; return nil.

I know the last line is not correct, I am looking to just get extent of the block that is drawn with multileader. The MleaderStyle content type is block. I believe I can use that block name to insert in the drawing and get the extent but the user can make changes to the block scale in the multileaderstyle and therefore, I assume its best to select the block that is drawn with multileader (which will have all settings applied e.g. scale) and get its extent. I will be adding the same block multiple times vertically or horizontally.

P.S. (vlax-ename->vla-object (cdar (entget (entlast)))) gives me the mleader and not the block.

Thank you!

kreaten_vhar

  • Mosquito
  • Posts: 3
Re: vla-getboundingbox of a block of multileader
« Reply #4 on: June 14, 2022, 08:39:28 AM »
Hmm, yeah, I'm not too sure lol.

Could Entsel be of any use to you? It would prompt you to select the block outright.

mhupp

  • Newt
  • Posts: 174
Re: vla-getboundingbox of a block of multileader
« Reply #5 on: June 14, 2022, 12:50:03 PM »
Code - Auto/Visual Lisp: [Select]
  1. (command "_.MLeader" pt1 pt2)
  2. (setq emleader (car (entlast))) ;this will get the entity name
  3.  

that is all you need.

Code - Auto/Visual Lisp: [Select]
  1. (setq eblock (entnext emleader))
is nil because the last entity is emleader their isn't anything after it.

mhupp

  • Newt
  • Posts: 174
Re: vla-getboundingbox of a block of multileader
« Reply #6 on: June 14, 2022, 01:13:25 PM »
P.S. (vlax-ename->vla-object (cdar (entget (entlast)))) gives me the mleader and not the block.

Code - Auto/Visual Lisp: [Select]
  1. (setq mleader (vlax-invoke (vlax-ename->vla-object (car (entlast)))) 'explode))
  2.     (foreach ent mleader
  3.       (if (eq (vla-get-Objectname ent) "AcDbBlockReference")
  4.         (progn
  5.           (setq x (vla-get-XScaleFactor ent))
  6.           (setq y (vla-get-YScaleFactor ent))
  7.           (setq z (vla-get-ZScaleFactor ent))
  8.         )
  9.       )
  10.       (vla-delete ent)
  11.     )

This makes a copy of the mleader and explodes it. then steps thought each entity and if its a block pulls the scale factors for x y and z.
« Last Edit: June 14, 2022, 08:31:20 PM by mhupp »

AARYAN

  • Newt
  • Posts: 72
Re: vla-getboundingbox of a block of multileader
« Reply #7 on: June 15, 2022, 12:10:14 AM »
vla-explode does not work with multileader objects. I tried already, any other method?

Code: [Select]
(setq sblock (vla-insertblock vspace (vlax-3d-point (cdr (assoc 15 (entget emleader)))) block scale scale scale rotation))
(setq icount 0)
(foreach satt (vlax-safearray->list (vlax-variant-value (vla-getattributes sblock)))
 (if (= icount 0)
  (vla-put-textstring satt "test")
  (vla-put-textstring satt ""))
 (setq icount (1+ icount)))
(vla-getboundingbox sblock 'lminpt 'lmaxpt)
(vla-delete sblock)

This is the best solution I could see so far. Inserting the block, apply the scale from the multileader style and getting the limits and finally delete the block that created.

Thanks for your inputs!

mhupp

  • Newt
  • Posts: 174
Re: vla-getboundingbox of a block of multileader
« Reply #8 on: June 15, 2022, 12:21:52 AM »
vla-explode does not work with multileader objects. I tried already, any other method?

Your right its probably because the leader is a anonymous type block.

prob easier to get the scale and block name with visual lisp.
Code - Auto/Visual Lisp: [Select]
  1. (setq mleader (vlax-ename->vla-object (car (entlast))))
  2. (setq scale (vla-get-ArrowheadSize mleader))
  3. (setq blkname (vla-get-arrowheadblock mleader))

« Last Edit: June 15, 2022, 12:51:15 AM by mhupp »

AARYAN

  • Newt
  • Posts: 72
Re: vla-getboundingbox of a block of multileader
« Reply #9 on: June 15, 2022, 03:22:52 AM »
vla-get-arrowheadblock returns ""

I am not changing the arrow head to block. The actual content type is a block. The code I wrote (see above) did the job and I was expecting the bounding box without having to add, get the box and delete the block.

Thanks!

mhupp

  • Newt
  • Posts: 174
Re: vla-getboundingbox of a block of multileader
« Reply #10 on: June 15, 2022, 07:27:37 AM »
vla-get-arrowheadblock returns ""

I am not changing the arrow head to block. The actual content type is a block. The code I wrote (see above) did the job and I was expecting the bounding box without having to add, get the box and delete the block.

Thanks!

that means the mleader doesn't have a block for the arrowhead. Its probably only a solid or a hatch.