Author Topic: mleader with lenght field  (Read 1635 times)

0 Members and 1 Guest are viewing this topic.

sport

  • Mosquito
  • Posts: 2
mleader with lenght field
« on: October 30, 2020, 12:06:02 PM »
I´m trying to create a lisp, by try and error, and copy paste of several sources (sorry if i dont put the credits here... i dont remember, any way. I want to be able to click a polyline and add an mleader with its area or length as a field. But i cant make it work. Can you please help me

(defun c:test (/ p1 p2 obj )
 (vl-load-com)
 (if (and (setq p1 (getpoint "\nPick First Point: "))
          (setq p2 (getpoint "\nPick Next Point: " p1))
     )
 

   (progn
     (setq obj
            (vlax-invoke
              (vlax-get (vla-get-ActiveDocument (vlax-get-acad-object))
                        (if (= 1 (getvar 'CVPORT))
                          'PaperSpace
                          'ModelSpace
                        )
              )
              'AddMLeader
              (append p1 p2)
              0
            )
     )
 
   (setq s
                              (strcat "%<\\AcObjProp Object(%<\\_ObjId "
                                      (itoa (vla-get-objectid (vlax-ename->vla-object (car (entsel "\nSeleccione Objeto: ")))))
                                      ">%).Area \\f \"%lu2%pr2%th44\">%"
                                      " m{\\H0.7x;\\S2^;}")))
   
   
 )
    (vla-put-textstring obj s)
 (princ)
)

ronjonp

  • Needs a day job
  • Posts: 7531
Re: mleader with lenght field
« Reply #1 on: October 30, 2020, 01:16:36 PM »
Welcome  to TheSwamp :) .. give this a try:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ e obj p1 p2 s)
  2.   (while (and (setq e (entsel "\nSeleccione Objeto: "))
  3.               (setq p1 (cadr e))
  4.               (vlax-property-available-p (setq e (vlax-ename->vla-object (car e))) 'area)
  5.               (setq p2 (getpoint p1 "\nPick a point: "))
  6.               (setq obj (vlax-invoke
  7.                           (vlax-get (vla-get-activedocument (vlax-get-acad-object))
  8.                                     (if (= 1 (getvar 'cvport))
  9.                                       'paperspace
  10.                                       'modelspace
  11.                                     )
  12.                           )
  13.                           'addmleader
  14.                           (append p1 p2)
  15.                           0
  16.                         )
  17.               )
  18.          )
  19.       obj
  20.       (strcat "%<\\AcObjProp Object(%<\\_ObjId "
  21.               (itoa (vla-get-objectid e))
  22.               ">%).Area \\f \"%lu2%pr2%th44\">%"
  23.               " m{\\H0.7x;\\S2^;}"
  24.       )
  25.     )
  26.     (command "_.regen")
  27.   )
  28.   (princ)
  29. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

sport

  • Mosquito
  • Posts: 2
Re: mleader with lenght field
« Reply #2 on: October 30, 2020, 02:09:00 PM »
Thanks ronjonp!!! It works perfect :)


Welcome  to TheSwamp :) .. give this a try:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ e obj p1 p2 s)
  2.   (while (and (setq e (entsel "\nSeleccione Objeto: "))
  3.               (setq p1 (cadr e))
  4.               (vlax-property-available-p (setq e (vlax-ename->vla-object (car e))) 'area)
  5.               (setq p2 (getpoint p1 "\nPick a point: "))
  6.               (setq obj (vlax-invoke
  7.                           (vlax-get (vla-get-activedocument (vlax-get-acad-object))
  8.                                     (if (= 1 (getvar 'cvport))
  9.                                       'paperspace
  10.                                       'modelspace
  11.                                     )
  12.                           )
  13.                           'addmleader
  14.                           (append p1 p2)
  15.                           0
  16.                         )
  17.               )
  18.          )
  19.       obj
  20.       (strcat "%<\\AcObjProp Object(%<\\_ObjId "
  21.               (itoa (vla-get-objectid e))
  22.               ">%).Area \\f \"%lu2%pr2%th44\">%"
  23.               " m{\\H0.7x;\\S2^;}"
  24.       )
  25.     )
  26.     (command "_.regen")
  27.   )
  28.   (princ)
  29. )

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: mleader with lenght field
« Reply #3 on: October 30, 2020, 02:59:17 PM »
I like to use this subroutine to mimic the mleader command - I mainly just like seeing the arrow and landing as I'm picking it's location.

Code: [Select]
(defun AT:MLeaderDraw (point / *error* elast)
  ;; Dynamically place a Multileader and have EName returned
  ;; point - starting point (must be UCS)
  ;; Alan J. Thompson, 04.11.11
  (defun *error* (m) (and cmd (setvar 'CMDECHO cmd)) elast)
  (if (and (vl-consp point) (getcname "mleader"))
    (progn (setq cmd (getvar 'CMDECHO))
           (setq elast (entlast))
           (setvar 'CMDECHO 0)
           (princ "\nSpecify other point: ")
           (vl-cmdf "_.mleader" "_non" point PAUSE)
           (while (eq 1 (logand 1 (getvar 'CMDACTIVE))) (vl-cmdf ""))
           (and (equal elast (setq elast (entlast))) (setq elast nil))
           (*error* nil)
    )
  )
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7531
Re: mleader with lenght field
« Reply #4 on: October 30, 2020, 03:44:38 PM »
Thanks ronjonp!!! It works perfect :)


Welcome  to TheSwamp :) .. give this a try:
Code - Auto/Visual Lisp: [Select]
  1. ...

Glad to help :)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC