Author Topic: "Rotating" MLeader block content to horizontal  (Read 8027 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: "Rotating" MLeader block content to horizontal
« Reply #15 on: January 05, 2018, 03:06:18 PM »
Well it was worth a try :) . Seems like recreating the mleader would be the easiest for this then, but you'd still have some manual cleanup.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ChrisCarlson

  • Guest
Re: "Rotating" MLeader block content to horizontal
« Reply #16 on: January 05, 2018, 04:21:55 PM »
Could you make your static blocks into dynamic block with a text rotation and "fudge" the mleaders?

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: "Rotating" MLeader block content to horizontal
« Reply #17 on: January 05, 2018, 06:38:22 PM »
Well it was worth a try :) . Seems like recreating the mleader would be the easiest for this then, but you'd still have some manual cleanup.

I thought the same and decided to try that out. :)
And saw the few problems that occur (aside from the obvious manual cleanup):
  • Mleader that has no leaders - so basically reinserting a new block is required, but how to (re)match the scale?
  • Mleader with more than one leader - couldn't replicate the multiple leaders in the newly created one (see below the code what I tried, but removed in the end)
  • Other mleader that errors on the GetLeaderLineVertices method - no idea whats wrong
Heres the sloppy code as a starting point (try it on cadpoobah's dwg to see/understand the listed problems) :
Code - Auto/Visual Lisp: [Select]
  1. (defun C:test ( / MleaderBlockAtts doc spc SS i o n L )
  2.  
  3.   ; _$ (MleaderBlockAtts (vlax-ename->vla-object (car (entsel)))) -> (("EQNOMISC" 1060 "") ("EQNO" 1059 "N0802"))
  4.   (defun MleaderBlockAtts ( mld / id L )
  5.     (and
  6.       (eq 'VLA-OBJECT (type mld)) (member (vla-get-ObjectName mld) '("AcDbMLeader" "AcDbLeader"))
  7.       (eq (vla-get-ContentType mld) acBlockContent)
  8.       (vlax-for x (vla-Item (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (vla-get-ContentBlockName mld))
  9.         (and
  10.           (eq (vla-get-ObjectName x) "AcDbAttributeDefinition") (setq id (vla-get-ObjectID x))
  11.           (setq L (cons (list (vla-get-TagString x) id (vla-GetBlockAttributeValue mld id)) L))
  12.         )
  13.       ); vlax-for
  14.     ); and
  15.     L
  16.   ); defun MleaderBlockAtts
  17.  
  18.   (and
  19.     (princ "\nSelect multileaders: ")
  20.     (setq SS (ssget "_:L-I" '((0 . "MULTILEADER"))))
  21.     (repeat (setq i (sslength SS))
  22.       (and
  23.         (setq o (vlax-ename->vla-object (ssname SS (setq i (1- i)))))
  24.         (setq n (vla-get-LeaderCount o))
  25.         (setq L (MleaderBlockAtts o))
  26.         (cond
  27.           ( (zerop n) ; Mleader that doesn't contains any leaders - lets create a block reference
  28.             (
  29.               (lambda ( / _dist _cen b atts att ll1 ll2 ur1 ur2 )
  30.                 (setq _dist (lambda (p1 p2) (apply 'distance (mapcar 'vlax-safearray->list (list p1 p2)))))
  31.                 (setq _cen (lambda ( pts ) (vlax-3D-point (apply 'mapcar (cons '(lambda (a b) (/ (+ a b) 2.)) (mapcar 'vlax-safearray->list pts))))))
  32.                 (vla-GetBoundingBox o 'll1 'ur1)
  33.                 (setq b (vlax-invoke spc 'InsertBlock '(0. 0. 0.) (vla-get-ContentBlockName o) 1 1 1 0.))
  34.                 (vla-GetBoundingBox b 'll2 'ur2)
  35.                 (vlax-invoke b 'ScaleEntity '(0. 0. 0.) (/ (_dist ll1 ur1) (_dist ll2 ur2))) ; <- THIS IS NOT CORRECT, I KNOW (but its close to the result)
  36.                 (vla-GetBoundingBox b 'll2 'ur2)
  37.                 (vla-Move b (_cen (list ll2 ur2)) (_cen (list ll1 ur1)))
  38.                 (setq atts (mapcar (function (lambda (x) (cons (vla-get-TagString x) x))) (vlax-invoke b 'GetAttributes)))
  39.                 (foreach x L
  40.                   (and
  41.                     (setq att (cdr (assoc (car x) atts)))
  42.                     (vla-put-TextString att (last x))
  43.                   )
  44.                 ); foreach
  45.                 (vla-put-Layer b (vla-get-Layer o))
  46.                 (vla-Delete o)
  47.               ); lambda
  48.             )
  49.           )
  50.           ( (>= n 1) ; Standard Mleader that contains 1+ leaders
  51.             (
  52.               (lambda ( / tmp new )
  53.                 (and
  54.                   (not (vl-catch-all-error-p (setq tmp (vl-catch-all-apply 'vla-GetLeaderLineVertices (list o 0)))))
  55.                   (setq new (vla-AddMLeader spc tmp 0))
  56.                   (progn
  57.                     (foreach x '(ArrowheadSize ArrowheadType ContentBlockName ContentType StyleName Layer LeaderType BlockConnectionType BlockScale)
  58.                       (vlax-put new x (vlax-get o x))
  59.                     ); foreach
  60.                     (foreach x L (apply 'vla-SetBlockAttributeValue (cons new (cdr x))) )
  61.                     (vla-Delete o)
  62.                   ); progn
  63.                 ); and
  64.               ); lambda
  65.             )
  66.           )
  67.         ); cond
  68.       ); and
  69.     ); repeat
  70.   ); and
  71.   (princ)
  72. ); defun

So this is what I tried to solve problem #2 - but it creates only one 'leader' for the multileader object:
Code - Auto/Visual Lisp: [Select]
  1.   (setq n (vla-get-LeaderCount o))
  2.   (not (vl-catch-all-error-p (setq tmp (vl-catch-all-apply 'vla-GetLeaderLineVertices (list o 0))))) ; 'tmp' - the initial safearray
  3.   (setq new (vla-AddMLeader spc tmp 0)) ; use 'tmp' to create the mleader (since its required)
  4.   (progn
  5.     (vla-RemoveLeader new 0) ; remove the only leader we added to the mleader, so we won't mess up the indexes
  6.     (repeat n
  7.       (setq n (1- n))
  8.       (setq tmp (vla-AddLeader new))
  9.       (vla-AddLeaderLine new tmp (vla-GetLeaderLineVertices o n))
  10.     ); repeat
  11.   ); progn
  12. ); and
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg