MLEADER DXF Help

MLEADER DXF Help

RGrandmaison
Advocate Advocate
1,549 Views
3 Replies
Message 1 of 4

MLEADER DXF Help

RGrandmaison
Advocate
Advocate

I'm trying to obtain the following two points after creating an MLeader with a predefined landing, 2 Maxpoints, and no Content:

 

The "bend" at the landing/leader.

The "end" of the landing where the grip exists to stretch it out.

 

I can see that the bend point is two index locations after (302 . "LEADER{") so I can grab that value, and I can see after (304 . "LEADER_LINE{") the length of the leader is given as (41 . 1.1234). If I  knew if there was a polar angle supplied by one of the other group codes, I could use polar to calculate the location of the stretch grip for the landing, but it's not very obvious here.

 

And the arrowtip might be to the left of the right of the bend point at the start of the landing, and the end of the landing grip may be to the left or the right of the bend point. Make sense?

 

(I'm building a routine to do weld symbols.)

 

Any help/ideas/advice?

 

 

0 Likes
1,550 Views
3 Replies
Replies (3)
Message 2 of 4

devitg
Advisor
Advisor
Please show us your sample.dwg with such mleader .
0 Likes
Message 3 of 4

trevor.bird.au
Advocate
Advocate

Hi Robert,

 

The code below will determine the 2 points you're looking for which I've called LeaderLanding:P1 and LeaderLanding:P2.

 

The angle of the leader landing line (dogleg) is stored as a unit vector; DXF code 11 in the Leader section of the MLeader DXF code list.

 

As examples, I've included 2 methods for calculating the angle of the leader landing line:

(atan (cadr Leader_11) (car Leader_11)) is ok in a 2D plane (in radians).

(leemac:acos (leemac:vxv Leader_11 '(1.0 0.0 0.0)) will calculate the angle (in radians) if the leader was created in 3D.

 

The method I used to calculate LeaderLanding:P2 does not require an angle; the method uses the leader landing line unit vector and length and some Lee Mac magic Smiley LOL

 

I've also set ssget to a forced single object selection (:S+.) on unlocked layers only (:L).

 

I hope this helps.

 

 

Regards,

Trevor

;;  MLeaderPoints.lsp by Trevor Bird
;;
;;  2018-01-24

;;------------------------------------------------------------------------------
(defun c:mleaderpoints
  (
    /

    ->rtd

    col_ActiveBlock

    LeaderLanding:Angle
    LeaderLanding:P1
    LeaderLanding:P2
    LeaderLanding:vxv
    Leader_10
    Leader_11
    Leader_40
    Leader_DXF

    MULTILEADER_DXF
    MULTILEADER_ename

    obj_AD
    obj_circle:P1
    obj_circle:P2

    ssC
    ss_Filter
    ss_MULTILEADER
    sv_cvport
  )
  (defun ->rtd (x) (* (/ x pi) 180.0))


  (setq obj_AD    (vlax-get-property (vlax-get-acad-object) 'ActiveDocument)
        sv_cvport (getvar 'CVPORT)
  );setq


  (if (= sv_cvport 1)
    (setq col_ActiveBlock (vlax-get-property obj_AD 'PaperSpace))
    (setq col_ActiveBlock (vlax-get-property obj_AD 'ModelSpace))
  );if (= sv_cvport 1)


  (setq ss_Filter '((0 . "MULTILEADER")))

  (if (= sv_cvport 1)
    (setq ss_Filter (append ss_Filter (list (cons 410 (getvar 'CTAB)))))
    (setq ss_Filter (append ss_Filter '((410 . "Model"))))
  );if (= sv_cvport 1)




  (setq ss_MULTILEADER  (ssget ":S+.:L" ss_Filter))
;  (setq ss_MULTILEADER  (ssget ":L" ss_Filter))


  (cond
    ( (not ss_MULTILEADER)
      (princ "\nNo MLeaders selected.")
    );(not ss_MULTILEADER)


    (ss_MULTILEADER
      (setq ssC -1)

      (repeat (sslength ss_MULTILEADER)
        (setq MULTILEADER_ename   (ssname ss_MULTILEADER (setq ssC  (1+ ssC)))
              MULTILEADER_DXF     (entget MULTILEADER_ename)

              Leader_DXF          (cdr (member '(302 . "LEADER{") MULTILEADER_DXF))
              Leader_10           (cdr (assoc 10  Leader_DXF))  ;  Last Leader Line Point
              Leader_11           (cdr (assoc 11  Leader_DXF))  ;  Dogleg Vector
              Leader_40           (cdr (assoc 40  Leader_DXF))  ;  Dogleg Length

              LeaderLanding:Angle (atan (cadr Leader_11) (car Leader_11))

              LeaderLanding:vxv   (leemac:vxv Leader_11 '(1.0 0.0 0.0))
;              LeaderLanding:Angle  (leemac:acos LeaderLanding:vxv)

              LeaderLanding:P1    Leader_10
              LeaderLanding:P2    (mapcar '+ LeaderLanding:P1 (leemac:vxs Leader_11 Leader_40))
        );setq

        (princ "\nLeader_11          \t") (prin1 Leader_11) (princ "\t\tDogleg Vector")
        (princ "\nLeader_40          \t") (prin1 Leader_40) (princ "\t\tDogleg Length")
        (princ "\nLeaderLanding:Angle\t") (prin1 (->rtd LeaderLanding:Angle))
        (princ "\nLeaderLanding:vxv  \t") (prin1 (->rtd (leemac:acos LeaderLanding:vxv)))


        (setq obj_circle:P1 (vlax-invoke-method col_ActiveBlock 'AddCircle (vlax-3D-point LeaderLanding:P1) (/ Leader_40 10.0))
              obj_circle:P2 (vlax-invoke-method col_ActiveBlock 'AddCircle (vlax-3D-point LeaderLanding:P2) (/ Leader_40 10.0))
        );setq

        (vlax-put-property obj_circle:P1 'Color acRed)
        (vlax-put-property obj_circle:P2 'Color acYellow)

        (vlax-release-object obj_circle:P1)
        (vlax-release-object obj_circle:P2)
      );repeat (sslength ss_MULTILEADER)
    );ss_MULTILEADER
  );cond


  (vlax-release-object col_ActiveBlock)
  (vlax-release-object obj_AD)


  (princ)
);c:mleaderpoints




;;------------------------------------------------------------------------------
;; Vector x Scalar - Lee Mac
;; Args: v - vector in R^n, s - real scalar

(defun leemac:vxs ( v s )
  (mapcar '(lambda ( n ) (* n s)) v)
)


;; Vector Dot Product  -  Lee Mac
;; Args: u,v - vectors in R^n

(defun leemac:vxv ( u v )
    (apply '+ (mapcar '* u v))
)


;; ArcCosine  -  Lee Mac
;; Args: -1 <= x <= 1

(defun leemac:acos ( x )
    (if (<= -1.0 x 1.0)
        (atan (sqrt (- 1.0 (* x x))) x)
    )
)




;;------------------------------------------------------------------------------
(princ "\nMLeaderPoints loaded. Start command with MLEADERPOINTS.")
(princ)

 

0 Likes
Message 4 of 4

devitg
Advisor
Advisor

Please see it at 

 

 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/leader-and-block-count/td-p/3243536

 

 

 

Oleg , aka FATTY the odl horse,  is a friend  of mine , he help me a lot. He is from Russia, Saint Petersburg 

 

;; add mleader with block count info
;; feel free to squiggle it
; author FATTY the OH also know as OLEG
;https://forums.autodesk.com/t5/user/viewprofilepage/user-id/523211
(VL-LOAD-COM)
(DEFUN C:MLBC  (/
                ACSP
                ADOC
                AXSS
                CNT
                I
                LST_COUNT
                LST_NAME
                MLEAD
                NM
                NUM
                P1
                P2
                PTARR
                SS
                STR_DATA
                TABLE_DATA
                TABLE_HEADERS
                TMP)

  (OR ADOC
      (SETQ ADOC
             (VLA-GET-ACTIVEDOCUMENT
               (VLAX-GET-ACAD-OBJECT)
               )
            )
      )
  (IF (AND
        (= (GETVAR "tilemode") 0)
        (= (GETVAR "cvport") 1)
        )
    (SETQ ACSP (VLA-GET-PAPERSPACE ADOC))
    (SETQ ACSP (VLA-GET-MODELSPACE ADOC))
    )
  (SETVAR 'QTEXTMODE 0)
  (SETQ SS (SSGET '((0 . "INSERT"))))
  (SETQ AXSS (VLA-GET-ACTIVESELECTIONSET ADOC))
  (VLAX-FOR A  AXSS
    (SETQ NM (VLAX-GET A 'EFFECTIVENAME))
    (SETQ LST_NAME
           (CONS NM LST_NAME))
    (IF (NOT (MEMBER NM LST_COUNT))
      (SETQ LST_COUNT (CONS NM LST_COUNT))))
  (SETQ TABLE_HEADERS
         '("BlockName" "Quantity"))
  (SETQ CNT 1
        NUM 0
        TABLE_DATA NIL)
  (FOREACH I  LST_COUNT
    (SETQ TMP        (ITOA (LENGTH (VL-REMOVE-IF-NOT (FUNCTION (LAMBDA (X) (EQ X I))) LST_NAME)))
          TMP        (LIST I TMP)
          TABLE_DATA (CONS TMP TABLE_DATA)))

  (SETQ TABLE_DATA (APPEND (LIST TABLE_HEADERS) (VL-SORT TABLE_DATA (FUNCTION (LAMBDA (A B) (< (CAR A) (CAR B)))))))

  (SETQ STR_DATA (VL-STRING-RIGHT-TRIM "\n"
                                       (APPLY 'STRCAT
                                              (MAPCAR (FUNCTION (LAMBDA (X) (STRCAT (CAR X) "\t\t" (CADR X) "\n")))
                                                      TABLE_DATA))))


  (SETQ P1 (GETPOINT "\nPick arrow point >> \n")
        P2 (GETPOINT P1 "\nPick text point >> \n")
        )
  (SETQ PTARR (VLAX-MAKE-VARIANT
                (VLAX-SAFEARRAY-FILL
                  (SAFEARRAY VLAX-VBDOUBLE '(0 . 5))
                  (APPLY 'APPEND (LIST P1 P2))))
        )

  (SETQ MLEAD (VLA-ADDMLEADER ACSP PTARR 0))
  (VLA-PUT-CONTENTTYPE MLEAD ACMTEXTCONTENT)
  (VLA-PUT-TEXTHEIGHT MLEAD (GETVAR "dimtxt")) ;<--change  text height here
  (VLA-PUT-LANDINGGAP MLEAD 0.09)
  (VLA-PUT-TEXTSTRING MLEAD STR_DATA)

  (VLA-PUT-DOGLEGGED MLEAD :VLAX-TRUE)
  (VLA-PUT-DOGLEGLENGTH MLEAD 0.05)
  ;;borrowed from Lee Mac:
  (VLA-SETDOGLEGDIRECTION
    MLEAD
    0
    (VLAX-3D-POINT
      (LIST
        (IF (<= (CAR P1) (CAR P2))
          1
          -1)
        0
        0
        )
      )
    )
  (IF (>= (CAR P2) (CAR P1))
    (VLA-PUT-TEXTJUSTIFY MLEAD ACATTACHMENTPOINTMIDDLELEFT)
    (VLA-PUT-TEXTJUSTIFY MLEAD ACATTACHMENTPOINTMIDDLERIGHT)
    )

  (VLA-PUT-TEXTLEFTATTACHMENTTYPE MLEAD 2)
  (VLA-PUT-TEXTRIGHTATTACHMENTTYPE MLEAD 2)
  (VLA-PUT-TEXTFRAMEDISPLAY MLEAD :VLAX-TRUE) ;<-- to display text frame
  (VLA-PUT-LEADERLINEWEIGHT MLEAD 0)
  (VLA-PUT-LEADERTYPE MLEAD 1)

  (VLA-REGEN ADOC ACACTIVEVIEWPORT)
  (PRINC)
  )
(PROMPT "\n")
(PROMPT "\t\t<<< Start command with MLBC\t>>> ")
(PRIN1)
0 Likes