Author Topic: Mleader Help Needed  (Read 4275 times)

0 Members and 1 Guest are viewing this topic.

cmwade77

  • Swamp Rat
  • Posts: 1443
Mleader Help Needed
« on: December 17, 2009, 03:13:50 PM »
I am trying to combine all of our custom mleaders routines into one to simplify things, to where you simply have to press tab to change the arrowheads or Shift+Tab (or something like that, I haven't decided yet) to change the content (i.e. from text to different blocks), my problem is changing the coordinates once I have the mleader inserted:

Code: [Select]
(defun c:dmleader ()
(setq *thisdrawing* (vla-get-activedocument
(vlax-get-acad-object)
     ) ;_ end of vla-get-activedocument
     *modelspace*  (vla-get-ModelSpace *thisdrawing*))
(command "annoautoscale" "4")
(setq pt1 "")
(while (or (= pt1 nil) (= pt1 null) (= pt1 ""))
(progn
(setq pt1 (getpoint "\nSelect starting point of leader:  "))
(if pt1 (or (= pt1 nil) (= pt1 null) (= pt1 ""))
(princ "\n*** You must select a starting point for the leader ***")
)
)
)
(SETQ PTTST NIL)
(SETQ PTTST (OSNAP pt1 "_NEA"))
(setq pt2 (trans (cadr (grread t 4 4)) 1 0))
(if (> (car pt1) (car pt2))
(setq pt3 (polar pt2 (* pi (/ 180 180.0)) 0.25))
(setq pt3 pt2)
)
(setq newpoints (vlax-make-safearray vlax-vbDouble '(1 . 9)))
(vlax-safearray-put-element newpoints 1 (car pt1))
(vlax-safearray-put-element newpoints 2 (cadr pt1))
(vlax-safearray-put-element newpoints 3 (caddr pt1))
(vlax-safearray-put-element newpoints 4 (car pt2))
(vlax-safearray-put-element newpoints 5 (cadr pt2))
(vlax-safearray-put-element newpoints 6 (caddr pt2))
(vlax-safearray-put-element newpoints 7 (car pt3))
(vlax-safearray-put-element newpoints 8 (cadr pt3))
(vlax-safearray-put-element newpoints 9 (caddr pt3))
(setq leaderLineIndex 0)
(setq mlobj (vla-AddMleader *modelspace* newpoints leaderLineIndex))
(setq Loop T)
(while (/= Loop nil)
 (setq input (grread t 4 4))
(setq CurrentPosition (trans (cadr input) 1 0))
(if (> (car pt1) (car CurrentPosition))
(setq pt3 (polar CurrentPosition (* pi (/ 180 180.0)) 0.25))
(setq pt3 CurrentPosition)
)
(vlax-safearray-put-element newpoints 4 (car CurrentPosition))
(vlax-safearray-put-element newpoints 5 (cadr CurrentPosition))
(vlax-safearray-put-element newpoints 6 (caddr CurrentPosition))
(vlax-safearray-put-element newpoints 7 (car pt3))
(vlax-safearray-put-element newpoints 8 (cadr pt3))
(vlax-safearray-put-element newpoints 9 (caddr pt3))

(vla-put-coordinates mlobj newpoints); <---- This line seems to be the problem
);_while

)
Everything that I can find indicates that (vla-put-coordinates mlobj newpoints) should work, but I get error: ActiveX Server returned the error:
unknown name: Coordinates

If anyone has any ideas I would greatly appreciate it, once I get this, I think the rest should be relatively easy.

Chris

  • Swamp Rat
  • Posts: 548
Re: Mleader Help Needed
« Reply #1 on: December 17, 2009, 03:36:10 PM »
help doesnt say that multileader is an object that this can be used on.  The only program I have that feeds points to a Mleader uses this:
Code: [Select]
(while (< n (length pt_list))
    (setq pt (nth n pt_list))
    (vlax-safearray-put-element ptarray (+ (* n 3) 1) (car pt))
    (vlax-safearray-put-element ptarray (+ (* n 3) 2) (cadr pt))
    (vlax-safearray-put-element ptarray (+ (* n 3) 3) (caddr pt))
    (setq n (1+ n))
  ) ;_ end of while
But I'm not really sure how the program works.  I think that this is a program to convert a regular mtext and leader object into a mleader object.
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Mleader Help Needed
« Reply #2 on: December 17, 2009, 03:56:42 PM »
Hmm..Under Mleader it says it can be, see attached screen shot.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Mleader Help Needed
« Reply #3 on: December 17, 2009, 06:31:09 PM »
Ok, I found a workaround to the problem, now I have a different problem, the landing always goes to the right (even when it should point to the left):
Code: [Select]
(defun c:dmleader ()
(setq *thisdrawing* (vla-get-activedocument
(vlax-get-acad-object)
      ) ;_ end of vla-get-activedocument
      *modelspace*  (vla-get-ModelSpace *thisdrawing*))
(command "annoautoscale" "4")
(setq pt1 "")
(while (or (= pt1 nil) (= pt1 null) (= pt1 ""))
(progn
(setq pt1 (getpoint "\nSelect starting point of leader:  "))
(if pt1 (or (= pt1 nil) (= pt1 null) (= pt1 ""))
(princ "\n*** You must select a starting point for the leader ***")
)
)
)
(SETQ PTTST NIL)
(SETQ PTTST (OSNAP pt1 "_NEA"))
(setq pt2 (trans (cadr (grread t 4 4)) 1 0))
(if (> (car pt1) (car pt2))
(setq pt3 (polar pt2 (* pi (/ 180 180.0)) 0.25))
(setq pt3 pt2)
)
(setq newpoints (vlax-make-safearray vlax-vbDouble '(1 . 6)))
(vlax-safearray-put-element newpoints 1 (car pt1))
(vlax-safearray-put-element newpoints 2 (cadr pt1))
(vlax-safearray-put-element newpoints 3 (caddr pt1))
(vlax-safearray-put-element newpoints 4 (car pt2))
(vlax-safearray-put-element newpoints 5 (cadr pt2))
(vlax-safearray-put-element newpoints 6 (caddr pt2))
(setq leaderLineIndex 0)
(setq mlobj (vla-AddMleader *modelspace* newpoints leaderLineIndex))
(setq Loop T)
(while (/= Loop nil)
(setq input (grread t 4 4))
(setq CurrentPosition (trans (cadr input) 1 0))
(if (> (car pt1) (car CurrentPosition))
(setq pt3 (polar CurrentPosition (* pi (/ 180 180.0)) 0.25))
(setq pt3 CurrentPosition)
)
(vlax-safearray-put-element newpoints 4 (car CurrentPosition))
(vlax-safearray-put-element newpoints 5 (cadr CurrentPosition))
(vlax-safearray-put-element newpoints 6 (caddr CurrentPosition))
(entdel (entlast))
(setq mlobj (vla-AddMleader *modelspace* newpoints 0))

(if (= (car input) 3)
(setq Loop nil)
)
;(princ (car input))

);_while

)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Mleader Help Needed
« Reply #4 on: December 17, 2009, 10:13:03 PM »
Look at the dogleg setting.

Ok, I found a workaround to the problem, now I have a different problem, the landing always goes to the right (even when it should point to the left):
Code: [Select]
(defun c:dmleader ()
(setq *thisdrawing* (vla-get-activedocument
(vlax-get-acad-object)
      ) ;_ end of vla-get-activedocument
      *modelspace*  (vla-get-ModelSpace *thisdrawing*))
(command "annoautoscale" "4")
(setq pt1 "")
(while (or (= pt1 nil) (= pt1 null) (= pt1 ""))
(progn
(setq pt1 (getpoint "\nSelect starting point of leader:  "))
(if pt1 (or (= pt1 nil) (= pt1 null) (= pt1 ""))
(princ "\n*** You must select a starting point for the leader ***")
)
)
)
(SETQ PTTST NIL)
(SETQ PTTST (OSNAP pt1 "_NEA"))
(setq pt2 (trans (cadr (grread t 4 4)) 1 0))
(if (> (car pt1) (car pt2))
(setq pt3 (polar pt2 (* pi (/ 180 180.0)) 0.25))
(setq pt3 pt2)
)
(setq newpoints (vlax-make-safearray vlax-vbDouble '(1 . 6)))
(vlax-safearray-put-element newpoints 1 (car pt1))
(vlax-safearray-put-element newpoints 2 (cadr pt1))
(vlax-safearray-put-element newpoints 3 (caddr pt1))
(vlax-safearray-put-element newpoints 4 (car pt2))
(vlax-safearray-put-element newpoints 5 (cadr pt2))
(vlax-safearray-put-element newpoints 6 (caddr pt2))
(setq leaderLineIndex 0)
(setq mlobj (vla-AddMleader *modelspace* newpoints leaderLineIndex))
(setq Loop T)
(while (/= Loop nil)
(setq input (grread t 4 4))
(setq CurrentPosition (trans (cadr input) 1 0))
(if (> (car pt1) (car CurrentPosition))
(setq pt3 (polar CurrentPosition (* pi (/ 180 180.0)) 0.25))
(setq pt3 CurrentPosition)
)
(vlax-safearray-put-element newpoints 4 (car CurrentPosition))
(vlax-safearray-put-element newpoints 5 (cadr CurrentPosition))
(vlax-safearray-put-element newpoints 6 (caddr CurrentPosition))
(entdel (entlast))
(setq mlobj (vla-AddMleader *modelspace* newpoints 0))

(if (= (car input) 3)
(setq Loop nil)
)
;(princ (car input))

);_while

)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Mleader Help Needed
« Reply #5 on: December 18, 2009, 11:06:09 AM »
I have been looking at that, but it always seems to go to 1,0,0 or -1,0,0 for some reason....   :x


cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Mleader Help Needed
« Reply #7 on: December 18, 2009, 12:11:26 PM »
Ok, here is what I have, but the landing always seems to go to the same place for some reason:
Code: [Select]
(vl-cmdf "._insert" "Leaderm08.dwg")(command)
(defun c:dmleader ( / *thisdrawing* *modelspace* *paperspace* PTTST pt1 pt2 pt3 newpoints leadeLineIndex mltype Loop input CML CurrentPosition )
(load "standards.lsp")
(setq *thisdrawing* (vla-get-activedocument
(vlax-get-acad-object)
      ) ;_ end of vla-get-activedocument
      *modelspace*  (vla-get-ModelSpace *thisdrawing*)
  *paperspace*  (vla-get-PaperSpace *thisdrawing*))
(command "annoautoscale" "4")
(setq pt1 "")
(while (or (= pt1 nil) (= pt1 null) (= pt1 ""))
(progn
(setq pt1 (getpoint "\nSelect starting point of leader:  "))
(if pt1 (or (= pt1 nil) (= pt1 null) (= pt1 ""))
(princ "\n*** You must select a starting point for the leader ***")
)
)
)
(SETQ PTTST (OSNAP pt1 "_NEA"))
(IF (= PTTST NIL)
(SETVAR "CMLEADERSTYLE" "BEINOB-R1")
(SETVAR "CMLEADERSTYLE" "BEIOB-R1")
    )
(setq pt2 (trans (cadr (grread t 4 4)) 1 0))
(if (> (car pt1) (car pt2))
(setq pt3 (polar pt2 (* pi (/ 180 180.0)) 0.25))
(setq pt3 pt2)
)
(setq newpoints (vlax-make-safearray vlax-vbDouble '(1 . 6)))
(vlax-safearray-put-element newpoints 1 (car pt1))
(vlax-safearray-put-element newpoints 2 (cadr pt1))
(vlax-safearray-put-element newpoints 3 (caddr pt1))
(setq leaderLineIndex 0)
(setq mltype "MTEXT")
(setq Loop T)
(setq mlobj nil)
(while (/= Loop nil)
(setq input (grread t 4 4))
(if (and (= (car input) 2) (= (cadr input) 9))
(progn
(setq CML (getvar "cmleaderstyle"))
(cond
((= CML "BEINOB-R1")
(SETVAR "CMLEADERSTYLE" "BOX-R1")
)
((= CML "BOX-R1")
(SETVAR "CMLEADERSTYLE" "LOOP-R1")
)
((= CML "BEIOB-R1")
(SETVAR "CMLEADERSTYLE" "BEINOB-R1")
)
((= CML "LOOP-R1")
(SETVAR "CMLEADERSTYLE" "BEIOB-R1")
)
)

)
)

(if (and (= (car input) 2) (= (cadr input) 32))
(progn
(cond
((= mltype "MTEXT")
(setq mltype "1M08")
)
((= mltype "1M08")
(setq mltype "PL-08")
)
((= mltype "PL-08")
(setq mltype "AH08")
)
((or (= mltype "AH08") (= mltype "R-AHRN08") (= mltype "L-AHRN08"))
(setq mltype "MTEXT")
)
((= mltype "R-PL08")
(setq mltype "R-AHRN08")
)
((= mltype "L-PL08")
(setq mltype "L-AHRN08")
)
)
)
)
(if (and (= (car input) 2) (= (cadr input) 110))
(progn
(setq input (grread t 4 4))
(setq CurrentPosition (trans (cadr input) 1 0))
(cond
((= mltype "PL-08")
(if (> (car CurrentPosition) (car pt1))
(setq mltype "R-PL08")
(setq mltype "L-PL08")
)
)
((= mltype "AH08")
(if (> (car CurrentPosition) (car pt1))
(setq mltype "R-AHRN08")
(setq mltype "L-AHRN08")
)
)
((or (= mltype "R-AHRN08") (= mltype "L-AHRN08"))
(setq mltype "AH08")
)
((or (= mltype "R-PL08") (= mltype "L-PL08"))
(setq mltype "PL-08")
)
)
(setq input (grread t 4 4))
)
)

(if (and (not (= (car input) 3)) (not (= (car input) 5)))
(princ (cadr input))
)

(if (= (car input) 3)
(setq Loop nil)
(setq input (grread t 4 4))
)

(if (/= Loop nil)
(progn
(setq CurrentPosition (trans (cadr input) 1 0))
(if (> (car pt1) (car CurrentPosition))
(setq pt3 (polar CurrentPosition (* pi (/ 180 180.0)) 0.25))
(setq pt3 CurrentPosition)
)
(vlax-safearray-put-element newpoints 4 (car CurrentPosition))
(vlax-safearray-put-element newpoints 5 (cadr CurrentPosition))
(vlax-safearray-put-element newpoints 6 (caddr CurrentPosition))

(if (/= mlobj nil)
(entdel (entlast)))

(setq mlobj (vla-AddMleader *paperspace* newpoints 0))
; Code from: http://www.theswamp.org/index.php?topic=30817.0
(vla-setdoglegdirection mlobj 0 (vlax-3D-point (list (if (<= (car pt1) (car CurrentPosition)) 1 -1) 0 0)))
; End of code from: http://www.theswamp.org/index.php?topic=30817.0
      (cond
((or (= mltype "R-PL08") (= mltype "L-PL08"))
(if (> (car CurrentPosition) (car pt1))
(setq mltype "R-PL08")
(setq mltype "L-PL08")
)
)
((or (= mltype "R-AHRN08") (= mltype "L-AHRN08"))
(if (> (car CurrentPosition) (car pt1))
(setq mltype "R-AHRN08")
(setq mltype "L-AHRN08")
)
)
)
(cond
((= mltype "MTEXT")
; Code from: http://www.theswamp.org/index.php?topic=30817.0
(if (>= (car pt1) (car CurrentPosition))
(vla-put-TextJustify mlobj acAttachmentPointMiddleLeft)
(vla-put-TextJustify mlobj acAttachmentPointMiddleRight)
)
;End of code from: http://www.theswamp.org/index.php?topic=30817.0
(vla-put-TextString mlobj "EXAMPLE")
(setq mltype "MTEXT")
)
(T
(vla-put-ContentBlockName mlobj mltype)
)
)
)
)

);_while
(if (= mltype "MTEXT")
(vla-put-TextString mlobj "")
)
(command "._select" (entlast) "")
(command "_.mleadercontentedit")
)


Chris

  • Swamp Rat
  • Posts: 548
Re: Mleader Help Needed
« Reply #8 on: December 18, 2009, 03:02:05 PM »
does VLA-PUT-DOGLEGLENGTH have any effect on which way it goes (specifying a negative or positive number?)
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Mleader Help Needed
« Reply #9 on: December 18, 2009, 03:25:10 PM »
It does; however, it puts it near 0,0 (not exactly at 0,0 though....grr), I have been trying everything, nothing seems to work.

Chris

  • Swamp Rat
  • Posts: 548
Re: Mleader Help Needed
« Reply #10 on: December 18, 2009, 03:54:40 PM »
I havent tested your code, or thoroughly read through it, but what is it you are trying to accomplish.  I might have something that already does it.
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Mleader Help Needed
« Reply #11 on: December 18, 2009, 04:08:47 PM »
Basically what I have are several mleader routines that set the arrow heads (some of them set it to a dot if not pointing to an object) and also sets the content, in some cases these are specific blocks, in other cases it is just text, also on certain blocks pressing n will add a note bubble. It also sets the layer, arrowhead and text sizes per our standards.

What I am trying to do is combine these routines into one, where you press TAB to cycle between the different Arrowheads and Press space to cycle between the different types of content.

The LISP routine works fairly well, as far as I can tell so far, I only have two outstanding items:
  • Fix this alignment issue (A pain in the neck)
  • Make the routine work with polar tracking and ortho

If yhou have something that can accomplish this (even if some modifications are needed), that would be cool.

Chris

  • Swamp Rat
  • Posts: 548
Re: Mleader Help Needed
« Reply #12 on: December 18, 2009, 05:00:33 PM »
I do have a program http://www.theswamp.org/index.php?topic=24798.0;all that Ronjonp wrote:
It only aligns the text, but maybe it is something you can take and modify and run with it.
Code: [Select]
(defun c:multileaderalign (/ al alpt cnt d1 dif dll doc el obj pt pt2 ss xpt vs)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (if (and (setq ss (ssget '((0 . "MULTILEADER"))))
           (setq al (car (entsel "\nSelect leader to align to: ")))
           (setq alpt (cdr (assoc 12 (entget al))))
           ;;change from assoc 10 to 12
           (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 obj (vlax-ename->vla-object ml)
                   el  (entget ml)
                   pt  (cdr (assoc 12 el))
                   ;;change from assoc 10 to 12
                   pt2 (list xpt (cadr pt))
                   dif (distance pt (list xpt (cadr pt)))
                   dll (vla-get-dogleglength obj)
                   d1  (distance pt alpt)
                   cnt 0
             )
             (if (= (vla-get-doglegged obj) :vlax-true)
               (while (and (not (equal pt2 xpt 0.01)) (<= cnt 2))
                 (setq dif (* -1 dif))
                 (vla-put-dogleglength obj (+ dll dif))
                 (vla-update obj)
                 (setq el  (entget (vlax-vla-object->ename obj))
                       pt  (cdr (assoc 12 el))
                       ;;change from assoc 10 to 12
                       pt2 (car pt)
                       cnt (1+ cnt)
                 )
               )
             )
           )
           (vla-endundomark doc)
    )
  )
  (princ)
)

    (defun c:mla ()
      (c:multileaderalign)
    ) ;_ end of defun
Christopher T. Cowgill, P.E.
AEC Collection 2020 (C3D)
Win 10

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Mleader Help Needed
« Reply #13 on: January 05, 2010, 03:02:35 PM »
Thank you for that, the trick seems to be with the vla-put-dogleglength (seems to require it twice to actually get it in there though)   :loco:

So, I am almost satisfied with the routine now, there are a few minor problems that I would like to fix:
  • Respect Polar Sanp and Ortho Mode
  • Being able to toggle Ortho and Polar Modes while drawing the leader
  • Be able to align to the last angle used and align to the x or y of the last leader drawn (I tried this but couldn't get it working, so I currently say that it is one or the other)
  • Alternatively to the one above: Allow the use of Polar Tracking
  • Ignore any keystrokes that are not used, right now this causes an error
Aside from these few minor items, all seems to be working fairly well. If anyone has any ideas on how to fix any of the above, I would love to hear them.
Also please note that I write my code using Notepad++, so I set the indents for what works best with that, just in case any of the indents seems to be off.