Author Topic: Aligning multileaders  (Read 18642 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7528
Re: Aligning multileaders
« Reply #30 on: December 17, 2008, 04:33:38 PM »
Chris,

Can you post a drawing with examples? That would help a bunch.

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Chris

  • Swamp Rat
  • Posts: 548
Re: Aligning multileaders
« Reply #31 on: December 17, 2008, 05:02:14 PM »
yes, I will post them first thing tomorrow if I remember.
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

Chris

  • Swamp Rat
  • Posts: 548
Re: Aligning multileaders
« Reply #32 on: December 18, 2008, 07:48:37 AM »
Ron

Attached is a drawing with examples as you requested.
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

ronjonp

  • Needs a day job
  • Posts: 7528
Re: Aligning multileaders
« Reply #33 on: December 18, 2008, 06:51:03 PM »
Chris,

Just had a chance to look at this and at first glance I don't see an easy way to align your "new" leaders. The first point (red x) which was originally used to align the leaders has no consistency anymore?

Also,

Do you want the endpoint of the landing aligned or the left side of the text?

« Last Edit: December 18, 2008, 06:55:52 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Chris

  • Swamp Rat
  • Posts: 548
Re: Aligning multileaders
« Reply #34 on: December 19, 2008, 07:57:49 AM »
Ok, now that I have a basis for what you were using, is there an easy way to modify the red x coord?  I'm sure that the difference in location can be determined based on the new leadergap length.  I dont believe I have ever been able to successfully change the coordinates of the red x.  You must have been able to in order for your code to work, could you show me the line that changes this value, then I could use it to modify the red coord and hopefully resolve the issue.
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

ronjonp

  • Needs a day job
  • Posts: 7528
Re: Aligning multileaders
« Reply #35 on: December 19, 2008, 09:56:17 AM »
Chris,

In my code, I was not modifying this point. I was stepping the landing length until it hit the X coord then stopped. That's why I said previously that the code was "not pretty".
You can change that first point location by using entmod like so:

(setq ed (entget (setq e (car (entsel)))))
(entmod (subst (cons 10 (getpoint)) (assoc 10 ed) ed))
(entupd e)

Per my previous post, what are you aligning to?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Chris

  • Swamp Rat
  • Posts: 548
Re: Aligning multileaders
« Reply #36 on: December 19, 2008, 10:06:32 AM »
as with the original program, I would like the left aligned text to be aligned along the left edge.  I will try changing the point and see if that resolves the issue.  If I change the point in my original mlgap program, then in theory, if your program uses the red x to align, the text should align properly.  Or am I missing the point?
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

ronjonp

  • Needs a day job
  • Posts: 7528
Re: Aligning multileaders
« Reply #37 on: December 19, 2008, 11:40:35 AM »
Here you go Chris...I was over thinking the problem. All I had to do was look for assoc 12 in the list rather than 10 :ugly:

Code: [Select]
(defun c:alignlandings (/ al alpt cnt dif dll doc el obj ss vs xpt xpt2)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (if (and (setq ss (ssget ":L" '((0 . "MULTILEADER"))))
   (setq al (car (entsel "\nSelect leader to align to: ")))
   (setq alpt (cdr (assoc 12 (entget al))))
   (setq xpt (car alpt))
   (setq vs (getvar 'viewsize))
      )
    (progn (vla-endundomark doc)
   (vla-startundomark doc)
   (grdraw (polar alpt (angtof "90") vs) (polar alpt (angtof "270") vs) 1)
   (foreach ml (vl-remove al (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
     (setq el (entget ml)
   obj (vlax-ename->vla-object ml)
   xpt2 (cadr (assoc 12 el))
   dif (abs (- xpt xpt2))
   cnt -1
     )
     (if (minusp (vlax-get obj 'doglegged))
       (progn (setq dll (vla-get-dogleglength obj))
      (while (and (not (equal xpt xpt2 0.01)) (< (setq cnt (1+ cnt)) 2))
(vla-put-dogleglength obj (+ dll (setq dif (- dif))))
(setq xpt2 (cadr (assoc 12 (entget ml))))
      )
       )
     )
     (vla-update obj)
   )
   (vla-endundomark doc)
    )
  )
  (princ)
)
« Last Edit: February 10, 2010, 03:40:17 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Chris

  • Swamp Rat
  • Posts: 548
Re: Aligning multileaders
« Reply #38 on: December 19, 2008, 11:52:48 AM »
once again, thanks for your help, so based on the coding, it looks like I can just replace multileaderalign with this new version of the program?
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

ronjonp

  • Needs a day job
  • Posts: 7528
Re: Aligning multileaders
« Reply #39 on: December 19, 2008, 11:56:55 AM »
Yes you can replace the code...and you are welcome :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

cadpoobah

  • Newt
  • Posts: 48
Re: Aligning multileaders
« Reply #40 on: November 12, 2013, 02:18:20 PM »
ronjonp,

I know this is an old post, but wanted to keep my feedback with the rest of this thread.

Your "AlignLandings" is great but had me scratching my head on the alignment results until I factored in the annotation scale of the selected multileaders. I modified your "dif" variable equation as shown:
from:  dif (abs (- xpt xpt2))
    to:  dif (* (abs (- xpt xpt2)) (getvar "CANNOSCALEVALUE"))

Of course, this revised code now makes the dangerous assumption that the mleader is annotative (which ours are). I'll leave it to someone else to make it more adaptive.

Code: [Select]
(defun c:alignlandings (/ al alpt cnt dif dll doc el obj ss vs xpt xpt2)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (if (and (setq ss (ssget ":L" '((0 . "MULTILEADER"))))
   (setq al (car (entsel "\nSelect leader to align to: ")))
   (setq alpt (cdr (assoc 12 (entget al))))
   (setq xpt (car alpt))
   (setq vs (getvar 'viewsize))
      )
    (progn (vla-endundomark doc)
   (vla-startundomark doc)
   (grdraw (polar alpt (angtof "90") vs) (polar alpt (angtof "270") vs) 1)
   (foreach ml (vl-remove al (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
     (setq el (entget ml)
   obj (vlax-ename->vla-object ml)
   xpt2 (cadr (assoc 12 el))
   dif (* (abs (- xpt xpt2)) (getvar "CANNOSCALEVALUE"))
   cnt -1
     )
     (if (minusp (vlax-get obj 'doglegged))
       (progn (setq dll (vla-get-dogleglength obj))
      (while (and (not (equal xpt xpt2 0.01)) (< (setq cnt (1+ cnt)) 2))
(vla-put-dogleglength obj (+ dll (setq dif (- dif))))
(setq xpt2 (cadr (assoc 12 (entget ml))))
      )
       )
     )
     (vla-update obj)
   )
   (vla-endundomark doc)
    )
  )
  (princ)
)

Regards,

Chris
Chris Lindner
Onebutton CAD Solutions
----------------------------------------------------
www.onebuttoncad.com #dayjob
www.unpavedart.com    #sidehustle

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Aligning multileaders
« Reply #41 on: November 12, 2013, 02:47:41 PM »
The following predicate function will return T if an entity is annotative:

Code - Auto/Visual Lisp: [Select]
  1. (defun annotative-p ( ent / dic )
  2.     (and
  3.         (member  '(102 . "{ACAD_XDICTIONARY") (setq ent (entget ent)))
  4.         (setq dic (cdr (assoc 360 ent)))
  5.         (setq dic (dictsearch dic "acdbcontextdatamanager"))
  6.         (setq dic (dictsearch (cdr (assoc -1 dic)) "acdb_annotationscales"))
  7.         (dictnext (cdr (assoc -1 dic)) t)
  8.     )
  9. )

Implemented in Ron's program:
Code - Auto/Visual Lisp: [Select]
  1. (* (abs (- xpt xpt2)) (if (annotative-p ml) (getvar 'cannoscalevalue) 1.0))

ronjonp

  • Needs a day job
  • Posts: 7528
Re: Aligning multileaders
« Reply #42 on: November 12, 2013, 04:41:42 PM »
ronjonp,

I know this is an old post, but wanted to keep my feedback with the rest of this thread.

Your "AlignLandings" is great but had me scratching my head on the alignment results until I factored in the annotation scale of the selected multileaders. I modified your "dif" variable equation as shown:
from:  dif (abs (- xpt xpt2))
    to:  dif (* (abs (- xpt xpt2)) (getvar "CANNOSCALEVALUE"))

Of course, this revised code now makes the dangerous assumption that the mleader is annotative (which ours are). I'll leave it to someone else to make it more adaptive.

Regards,

Chris

Chris,

Glad you could make use of the routine. I've added Lee's annotative sub as well as check the scale factor of the mleader. When it was not equal to 1 the results were funny.

Code: [Select]
(defun c:alignlandings (/ annotative-p al alpt cnt dif dll doc o ss vs xpt xpt2)
  (vl-load-com)
  ;; Lee Mac to check if object is annotative
  (defun annotative-p (ent / dic)
    (and (member '(102 . "{ACAD_XDICTIONARY") (setq ent (entget ent)))
(setq dic (cdr (assoc 360 ent)))
(setq dic (dictsearch dic "acdbcontextdatamanager"))
(setq dic (dictsearch (cdr (assoc -1 dic)) "acdb_annotationscales"))
(dictnext (cdr (assoc -1 dic)) t)
    )
  )
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (if (and (setq ss (ssget ":L" '((0 . "MULTILEADER"))))
   (setq al (car (entsel "\nSelect leader to align to: ")))
   (setq alpt (cdr (assoc 12 (entget al))))
   (setq xpt (car alpt))
   (setq vs (getvar 'viewsize))
      )
    (progn (vla-endundomark doc)
   (vla-startundomark doc)
   (grdraw (polar alpt (angtof "90") vs) (polar alpt (angtof "270") vs) 1)
   (foreach ml (vl-remove al (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
     (if (minusp (vlax-get (setq o (vlax-ename->vla-object ml)) 'doglegged))
       (progn (setq xpt2 (cadr (assoc 12 (entget ml)))
    ;; RJP added scalefactor so landing length is calculated correctly when /= 1
    dif (* (abs (- xpt xpt2))
    (if (annotative-p ml)
      (getvar 'cannoscalevalue)
      (/ 1. (vla-get-scalefactor o))
    )
)
    cnt -1
    dll (vla-get-dogleglength o)
      )
      (while (and (not (equal xpt xpt2 0.01)) (< (setq cnt (1+ cnt)) 2))
(vla-put-dogleglength o (+ dll (setq dif (- dif))))
(setq xpt2 (cadr (assoc 12 (entget ml))))
      )
       )
     )
     (vla-update o)
   )
   (vla-endundomark doc)
    )
  )
  (princ)
)
« Last Edit: November 12, 2013, 04:46:04 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC