Author Topic: QLEADER to MLEADER  (Read 4102 times)

0 Members and 1 Guest are viewing this topic.

jmyrwen

  • Guest
QLEADER to MLEADER
« on: October 16, 2016, 12:33:04 AM »
Hi all, i have code attached. Im just wondering if it could be done in the same way but instead of "QLEADER" it will be "MLEADER"? I already tried changing the command to mleader but doesn't work the same. Thank you in advance. Cheers!


(setq l_ang 90)
(defun c:q (/ sty nm p1 p2 ateblk p3)
(command "cmdecho" "0")
(setq osm (getvar "osmode"))
(setq ort (getvar "orthomode"))
;(command "osmode" "2")
(setq p1 (getpoint "\nPick origin point"))
(command "osmode" "0")
(command "orthomode" "0")
(setq p2 (getpoint "\nPick target" p1))
(princ)
(if (< (car p1) (car p2))
(progn
(if (< (cadr p1) (cadr p2))
(setq p3d (- (cadr p1) (cadr p2)))
)
(if (< (cadr p2) (cadr p1))
(setq p3d (- (cadr p2) (cadr p1)))
)
(if (< (cadr p2) (cadr p1))
(progn
(setq p3 (polar p2 (+ 0.0 (dtr (- l_ang))) (* p3d 1.0)))
(command "QLEADER" p2 p3 p1 "" "" "n")
)
)
(if (< (cadr p1) (cadr p2))
(progn
(setq p3 (polar p2 (+ 0.0 (dtr l_ang)) (* p3d 1.0)))
(command "QLEADER" p2 p3 p1 "" "" "n")
)
)
)
)
(if (< (car p2) (car p1))
(progn
(if (< (cadr p1) (cadr p2))
(setq p3d (- (cadr p1) (cadr p2)))
)
(if (< (cadr p2) (cadr p1))
(setq p3d (- (cadr p2) (cadr p1)))
)
(if (< (cadr p2) (cadr p1))
(progn
(setq p3 (polar p2 (+ 0.0 (dtr (- l_ang))) (* p3d 1.0)))
(command "QLEADER" p2 p3 p1 "" "" "n")
)
)
(if (< (cadr p1) (cadr p2))
(progn
(setq p3 (polar p2 (+ 0.0 (dtr l_ang)) (* p3d 1.0)))
(command "Qleader" p2 p3 p1 "" "" "n")
)
)
)
)
(command "osmode" osm)
(command "orthomode" ort)
)
;
(defun dtr (a)
(* pi (/ a 180.0))
)
;

ChrisCarlson

  • Guest
Re: QLEADER to MLEADER
« Reply #1 on: October 17, 2016, 07:45:41 AM »
Just quickly looking at this line

Code - Auto/Visual Lisp: [Select]
  1. (command "Qleader" p2 p3 p1 "" "" "n")

an mleader has a different format.

Code - Auto/Visual Lisp: [Select]
  1. (command "mleader" p1 p2)


This routine doesn't really do anything beyond a standard function. What is the intention?



jmyrwen

  • Guest
Re: QLEADER to MLEADER
« Reply #2 on: October 19, 2016, 01:29:34 AM »
hi, thanks for the response appreciate that, if its not possible on above code i would like the user to input their desired landing gap,(like from one point to another) not a fix distance.

ifncdylan

  • Guest
Re: QLEADER to MLEADER
« Reply #3 on: October 19, 2016, 02:38:10 AM »
If you're going to use command calls to do this, then you'll just need to use the correct syntax for the MLEADER command as described above.

Otherwise I'd suggest perhaps using a leader creation utility and create the leaders via lisp instead of command calls, it's a lot faster as well as stable and you could swap out what kind of leader you're making a lot easier. :)

jmyrwen

  • Guest
Re: QLEADER to MLEADER
« Reply #4 on: October 19, 2016, 03:05:45 AM »
yeah i think mleader cant be done in above code so im now wondering if there's any system (or lisp maybe) that could uncheck landing options

« Last Edit: October 19, 2016, 03:17:37 AM by jmyrwen »

ChrisCarlson

  • Guest
Re: QLEADER to MLEADER
« Reply #5 on: October 19, 2016, 08:54:33 AM »
Landing distance can be set in the style or after creation with

Code - Auto/Visual Lisp: [Select]
  1. (setq ent (vlax-ename->vla-object (ssname (ssget "_L"))))
  2. (vlax-put-property ent 'LandingGap 0.09375)

ifncdylan

  • Guest
Re: QLEADER to MLEADER
« Reply #6 on: October 19, 2016, 10:33:02 PM »
I figured I could use this kind of function myself, so here is the result I came up with

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun C:DrawMLeader ( / points props )
  3.   (setq points ((lambda ( / prmpt a ptlst)
  4.                 (setq prmpt "\nSelect first point..")
  5.                 (setq a nil)
  6.                 (while (if a (setq a (getpoint a prmpt)) (setq a (getpoint prmpt)))
  7.                   (setq ptlst (cons a ptlst))
  8.                   (setq prmpt "\nSelect next point or right-click/space to exit")) ptlst))
  9.         props (list
  10.                         (cons 'LandingGap 1.5)
  11.                         (cons 'ArrowheadSize 2.5)
  12.                         (cons 'TextHeight 2.5)
  13.                         )
  14.         )
  15.   (Make_MLeader points props)
  16.  
  17.  )
  18. (defun Make_MLeader (points props / acadObj doc modelSpace mLeaderProps mLeader)
  19.     (setq acadObj (vlax-get-acad-object)
  20.           doc (vla-get-ActiveDocument acadObj)
  21.           modelSpace (vla-get-ModelSpace doc)
  22.           points (vlax-points->safearray points)
  23.           mLeader (vla-AddMLeader modelSpace points 0)
  24.           )
  25.   (cond (mLeader
  26.     (mapcar '(lambda (a) (if (vlax-property-available-p mLeader (car a)) (vlax-put-property mLeader (car a) (cdr a)))
  27.                )
  28.                 props
  29.     )
  30.     mLeader
  31.    )
  32.    (T nil)
  33.    )
  34. )
  35. (defun vlax-points->safearray ( l / out)
  36.   (setq in (flatlist l)
  37.         out (vlax-make-safearray vlax-vbDouble (cons 0 (- (length in) 1)))
  38.         out (vlax-safearray-fill out in)
  39.   )
  40. )
  41. (defun flatlist (l)
  42.         (cond
  43.         ((null l) nil)
  44.         ((atom l) (list l))
  45.         ((atom (car l)) (cons (car l) (flatlist (cdr l))))
  46.         ((append (flatlist (car l)) (flatlist (cdr l))))
  47. )
  48. )
  49.  

You can make your point selections in your usual manner, and then just pass a list of points and properties to the command and it will create the MLeader for you using visual lisp and apply those properties to the leader.
« Last Edit: October 19, 2016, 10:45:18 PM by ifncdylan »

jmyrwen

  • Guest
Re: QLEADER to MLEADER
« Reply #7 on: October 20, 2016, 12:25:40 AM »
Hi thank you very much for the efforts, i tried your code but for some reasons nothing happen  :thinking:

jmyrwen

  • Guest
Re: QLEADER to MLEADER
« Reply #8 on: October 20, 2016, 12:27:03 AM »
Landing distance can be set in the style or after creation with

Code - Auto/Visual Lisp: [Select]
  1. (setq ent (vlax-ename->vla-object (ssname (ssget "_L"))))
  2. (vlax-put-property ent 'LandingGap 0.09375)

i am new to lisp and i dont know where or how to use it :( Thanks anyway.

ifncdylan

  • Guest
Re: QLEADER to MLEADER
« Reply #9 on: October 20, 2016, 12:45:37 AM »
Hi thank you very much for the efforts, i tried your code but for some reasons nothing happen  :thinking:

You might need to install the visual lisp extensions? They aren't distributed with AutoCAD anymore.

As far as using the code goes, once you've got the extensions installed and the functions loaded in your file, instead of:
Code - Auto/Visual Lisp: [Select]
  1. (command "mleader" pt1 pt2 pt3)
You would use the custom command giving it the list of points and any properties you want (e.g. the landing gap):
Code - Auto/Visual Lisp: [Select]
  1. (Make_MLeader (list pt1 pt2 pt3) (list '(LandingGap . 1.5)))

i am new to lisp and i dont know where or how to use it :( Thanks anyway.

That code will also require the visual lisp extensions if you haven't installed them; either way, that could would set the landing gap of the last inserted object (presumably the MLeader you just created). Be careful though, as if the last object you doesn't have the LandingGap property then it will produce an error.

jmyrwen

  • Guest
Re: QLEADER to MLEADER
« Reply #10 on: October 20, 2016, 02:22:03 AM »
this is what i did, i load it and invok the command but nothing happens< i didnt get the visual lisp extension

ifncdylan

  • Guest
Re: QLEADER to MLEADER
« Reply #11 on: October 20, 2016, 05:57:03 AM »
Nothing which uses a visual lisp command will work without installing the extension, which you can get from the autocad site under your specific product :)

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: QLEADER to MLEADER
« Reply #12 on: October 20, 2016, 08:07:36 AM »
@jmyrwen:
I have a hunch that you are not testing the actual command in ifncdylan's code. The command is called DrawMLeader.

jmyrwen

  • Guest
Re: QLEADER to MLEADER
« Reply #13 on: October 20, 2016, 01:54:31 PM »
@jmyrwen:
I have a hunch that you are not testing the actual command in ifncdylan's code. The command is called DrawMLeader.

i know the command, did you try it your own?

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: QLEADER to MLEADER
« Reply #14 on: October 20, 2016, 02:08:20 PM »
@jmyrwen:
I have a hunch that you are not testing the actual command in ifncdylan's code. The command is called DrawMLeader.

i know the command, did you try it your own?
Yup. Works OK. Note: I use BricsCAD.

jmyrwen

  • Guest
Re: QLEADER to MLEADER
« Reply #15 on: October 23, 2016, 02:29:36 PM »
I give up so i ended up with the following routine and 'it's working fine except that i cannot change the angle to 45 degrees instead of 90. Please help :( Thank you.

PS: I tried changing "setq l_45" but did'nt work

Code - Auto/Visual Lisp: [Select]
  1. (setq l_ang 90)
  2. (defun c:mm (/ sty nm p1 p2 ateblk p3)
  3.   (command "cmdecho" "0")
  4.   (setq osm (getvar "osmode"))
  5.   (setq ort (getvar "orthomode"));
  6.   (command "osmode" "15359")
  7.   (setq p1 (getpoint "\nPick origin point:)"))
  8.   (command "osmode" "0")
  9.   (command "orthomode" "0")
  10.   (setq p2 (getpoint "\nPick target" p1))
  11.   (princ)
  12.   (if (< (car p1) (car p2))
  13.     (progn
  14.       (if (< (cadr p1) (cadr p2))
  15.         (setq p3d (- (cadr p1) (cadr p2)))
  16.       )
  17.       (if (< (cadr p2) (cadr p1))
  18.         (setq p3d (- (cadr p2) (cadr p1)))
  19.       )
  20.       (if (< (cadr p2) (cadr p1))
  21.         (progn
  22.           (setq p3 (polar p2 (+ 0.0 (dtr (- l_ang))) (* p3d 1.0)))
  23.         )
  24.       )
  25.       (if (< (cadr p1) (cadr p2))
  26.         (progn
  27.           (setq p3 (polar p2 (+ 0.0 (dtr l_ang)) (* p3d 1.0)))
  28.         )
  29.       )
  30.     )
  31.   )
  32.   (if (< (car p2) (car p1))
  33.     (progn
  34.       (if (< (cadr p1) (cadr p2))
  35.         (setq p3d (- (cadr p1) (cadr p2)))
  36.       )
  37.       (if (< (cadr p2) (cadr p1))
  38.         (setq p3d (- (cadr p2) (cadr p1)))
  39.       )
  40.       (if (< (cadr p2) (cadr p1))
  41.         (progn
  42.           (setq p3 (polar p2 (+ 0.0 (dtr (- l_ang))) (* p3d 1.0)))
  43.         )
  44.       )
  45.       (if (< (cadr p1) (cadr p2))
  46.         (progn
  47.           (setq p3 (polar p2 (+ 0.0 (dtr l_ang)) (* p3d 1.0)))
  48.         )
  49.       )
  50.     )
  51.   )
  52.   (command "_mleader" "L" "H" "o" "m" "3" "x" p2 p3 p1 "XX-XX")
  53.   (command "osmode" osm)
  54.   (COMMAND "DDEDIT" "L")
  55.   (command "orthomode" ort)
  56. )
  57. ;
  58. (defun dtr (a)
  59.   (* pi (/ a 180.0))
  60. );                             
  61.  

ifncdylan

  • Guest
Re: QLEADER to MLEADER
« Reply #16 on: October 23, 2016, 09:35:28 PM »
Considering that code draws a 90 degree angled mleader, perhaps you could try changing the text '90' to '45' in the code :)

jmyrwen

  • Guest
Re: QLEADER to MLEADER
« Reply #17 on: October 23, 2016, 10:13:36 PM »
Considering that code draws a 90 degree angled mleader, perhaps you could try changing the text '90' to '45' in the code :)

tried that but no luck :/

ifncdylan

  • Guest
Re: QLEADER to MLEADER
« Reply #18 on: October 24, 2016, 10:32:23 PM »
Well, something must be horribly wrong with your CAD setup because I ran that code which made a 90degree angled leader after asking for 2 points, then I simply changed that l_ang variable to 45 and it worked fine.

You mentioned you tried to do "setq l_45 90" and it didn't work. If that's what you're talking about, that's because you didn't change the l_ang variable, you created a new variable called l_45 with the value of 90.

(setq l_ang 90) in the original code should be replaced with (setq l_ang 45) if you want to change the l_ang variable.