Author Topic: Lisp to read attribute and draw mleader with leader style  (Read 15457 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Lisp to read attribute and draw mleader with leader style
« Reply #15 on: October 31, 2013, 12:19:07 PM »
still getting ############, even after re-running new mlb2

Could you post the drawing?

linktf

  • Guest
Re: Lisp to read attribute and draw mleader with leader style
« Reply #16 on: October 31, 2013, 01:27:18 PM »
Yup, here it is. It's also taking an inordinate amount of time to save. btw, I work for a university so that why the education stamp pops up.


<DWG w/ EDU Stamp removed>
« Last Edit: October 31, 2013, 02:11:26 PM by CAB »

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Lisp to read attribute and draw mleader with leader style
« Reply #17 on: October 31, 2013, 01:42:20 PM »
Quote from: command line when viewing drawing
Non Autodesk DWG.  This DWG file was saved by a software application that was not developed or licensed by Autodesk.  Autodesk cannot guarantee the application compatibility or integrity of this file.

What software are you using?

linktf

  • Guest
Re: Lisp to read attribute and draw mleader with leader style
« Reply #18 on: October 31, 2013, 01:47:45 PM »
AutoCAD 2013 Educational

So i created two lisps. one with a set of two attributes, and another with a different set of attributes in the code. both are attached. one set works fine, but the other one seems to be doing something wonky.


Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Lisp to read attribute and draw mleader with leader style
« Reply #19 on: October 31, 2013, 01:49:17 PM »
It's also taking an inordinate amount of time to save.

Here are the results of the AUDIT command:
Quote
Auditing Header
Auditing Tables
Layout Dictionary Entry BTR doesn't point back Deleted
Auditing Entities Pass 1
Pass 1 27900   objects audited
Invalid number as X coordinate in object.
  Set to           0.000000.
Invalid number as Y coordinate in object.
  Set to           0.000000.
Pass 1 28000   objects audited
Invalid number as X coordinate in object.
  Set to           0.000000.
Invalid number as Y coordinate in object.
  Set to           0.000000.
Pass 1 180800  objects audited
Auditing Entities Pass 2
AcDbLayout(59)
Placing Layout1 in ACAD_LAYOUT dictionary
Pass 2 180800  objects audited
Auditing Blocks
 26      Blocks audited
Auditing AcDsRecords
Total errors found 4 fixed 4
Erased 0 objects

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Lisp to read attribute and draw mleader with leader style
« Reply #20 on: October 31, 2013, 01:52:32 PM »
still getting ############, even after re-running new mlb2

MLB2 performs fine for me with your posted drawing.

linktf

  • Guest
Re: Lisp to read attribute and draw mleader with leader style
« Reply #21 on: October 31, 2013, 01:56:04 PM »
well maybe its this stupid education version!

linktf

  • Guest
Re: Lisp to read attribute and draw mleader with leader style
« Reply #22 on: May 20, 2014, 10:19:07 AM »
This ####### problem has come back to haunt me. I have found out that the MLB2 works totally fine until I save the file and quit autocad. The next time I open the dwg, it has "########" instead of the attributes in the multleaders? not sure why? Here is the code i've modified and am using.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:mlb2_SSF ( / at1 at2 ent enx ins lst mld pnt )
  2.     (while
  3.         (progn
  4.             (setvar 'errno 0)
  5.             (setq ent (car (entsel "\nSelect block <exit>: ")))
  6.             (cond
  7.                 (   (= 7 (getvar 'errno))
  8.                     (princ "\nMissed, try again.")
  9.                 )
  10.                 (   (null ent)
  11.                     nil
  12.                 )
  13.                 (   (/= "INSERT" (cdr (assoc 0 (setq enx (entget ent)))))
  14.                     (princ "\nObject is not a block.")
  15.                 )
  16.                 (   (/= 1 (cdr (assoc 66 enx)))
  17.                     (princ "\nBlock is not attributed.")
  18.                 )
  19.                 (   (not
  20.                         (and
  21.                             (setq lst (vlax-invoke (vlax-ename->vla-object ent) 'getattributes)
  22.                                   lst (mapcar '(lambda ( x ) (cons (strcase (vla-get-tagstring x)) x)) lst)
  23.                             )
  24.                             (setq at1 (cdr (assoc "LAND_FEAT" lst)))
  25.                             (setq at2 (cdr (assoc "COMMENTS"  lst)))
  26.                         )
  27.                     )
  28.                     (princ "\nBlock does not contain \"LAND_FEAT\" & \"COMMENTS\" attributes.")
  29.                 )
  30.                 (   (and
  31.                         (= "" (vla-get-textstring at1))
  32.                         (= "" (vla-get-textstring at2))
  33.                     )
  34.                     (princ "\nBoth attributes are empty.")
  35.                 )
  36.                 (   (setq ins (cdr (assoc 10 enx))
  37.                           pnt (getpoint (trans ins ent 1) "\nPick leader endpoint <exit>: ")
  38.                     )
  39.                     (setq mld
  40.                         (vlax-invoke
  41.                             (vlax-get-property (LM:acdoc)
  42.                                 (if (= 1 (getvar 'cvport))
  43.                                     'paperspace
  44.                                     'modelspace
  45.                                 )
  46.                             )
  47.                             'addmleader
  48.                             (append (trans ins ent 0) (trans pnt 1 0))
  49.                             0
  50.                         )
  51.                     )
  52.                     (vla-put-textstring mld
  53.                         (strcat
  54.                             (if (= "" (vla-get-textstring at1))
  55.                                 ""
  56.                                 (strcat
  57.                                     "%<\\AcObjProp Object(%<\\_ObjId "
  58.                                     (LM:ObjectID at1)
  59.                                     ">%).TextString>%"
  60.                                     (if (= "" (vla-get-textstring at2)) "" "\n")
  61.                                 )
  62.                             )
  63.                             (if (= "" (vla-get-textstring at2))
  64.                                 ""
  65.                                 (strcat
  66.                                     "%<\\AcObjProp Object(%<\\_ObjId "
  67.                                     (LM:ObjectID at2)
  68.                                     ">%).TextString>%"
  69.                                 )
  70.                             )
  71.                         )
  72.                     )
  73.                     (vla-put-textrotation mld 0.0)
  74.                     (if (<= (car pnt) (car (trans ins ent 1)))
  75.                         (progn
  76.                             (vla-setdoglegdirection mld 0 (vlax-3D-point (trans '(-1.0 0.0) 1 0 t)))
  77.                             (vlax-invoke mld 'setleaderlinevertices 0 (append (trans ins ent 0) (trans pnt 1 0)))
  78.                         )
  79.                         (vla-setdoglegdirection mld 0 (vlax-3D-point (trans '(1.0 0.0) 1 0 t)))
  80.                     )
  81.                     (vla-regen (LM:acdoc) acactiveviewport)
  82.                     t
  83.                 )
  84.             )
  85.         )
  86.     )
  87.     (princ)
  88. )
  89.  
  90. ;; ObjectID  -  Lee Mac
  91. ;; Returns a string containing the ObjectID of a supplied VLA-Object
  92. ;; Compatible with 32-bit & 64-bit systems
  93.  
  94. (defun LM:ObjectID ( obj )
  95.     (eval
  96.         (list 'defun 'LM:ObjectID '( obj )
  97.             (if
  98.                 (and
  99.                     (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
  100.                     (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
  101.                 )
  102.                 (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
  103.                '(itoa (vla-get-objectid obj))
  104.             )
  105.         )
  106.     )
  107.     (LM:ObjectID obj)
  108. )
  109.  
  110. ;; Active Document  -  Lee Mac
  111. ;; Returns the VLA Active Document Object
  112.  
  113. (defun LM:acdoc nil
  114.     (LM:acdoc)
  115. )
  116.  

linktf

  • Guest
Re: Lisp to read attribute and draw mleader with leader style
« Reply #23 on: May 20, 2014, 11:01:00 AM »
Might be because i am using two different version of this programs. I only modified line 24-25, the attribute field, and nothing else and maybe its isn't using the fields correctly or its trying to use the same fields? I'm not too sure exactly how fields work yet. Thanks all.

nirav

  • Guest
Looking for a multileader lisp that shows an attribute of the object.
« Reply #24 on: February 21, 2015, 09:17:38 PM »
Hi all,

My name is Nirav and I am new to the swamp. I am a cad engineer (Mechanical) and mostly involved in 3D applications. At the moment, I am working on Autocad for some drawing requirements. I am totally new to visual lisp, so I am looking for some help and guidance. I want to make a lisp which would work exactly like multileader command. The only difference is that it will show any one object attribute (either TAG or PROMPT) instead of multitext. I have worked on Inventor with visual basic codes and have no idea about visual lisp.

Can anybody help me on this?
Well, I have tried to use sample codes off this forum but none of them seem to be working for me.

Thanks in advance.

Cheers,
Nirav

migs_619

  • Guest
Re: Lisp to read attribute and draw mleader with leader style
« Reply #25 on: April 03, 2015, 04:07:48 PM »
Hello Lee,

I found this routine very useful. Just one tweak to make the Z placement of mleader to be the same as the block, my blocks have different elevations and it will make it more eye pleasing if the mleaders are together with the block. Can you help me please :)

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Lisp to read attribute and draw mleader with leader style
« Reply #26 on: April 04, 2015, 08:46:31 AM »
I found this routine very useful. Just one tweak to make the Z placement of mleader to be the same as the block, my blocks have different elevations and it will make it more eye pleasing if the mleaders are together with the block. Can you help me please :)

I'm glad that you found the program useful.  :-)

I have found that supplying the ActiveX addmleader method with leader coordinates with non-zero z-component has no effect on the elevation of the resultant MLeader, and that the MLeader must be separately moved to the appropriate elevation - this is perhaps a bug with the addmleader method.

Please try the following:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:mlb2 ( / at1 at2 ent enx ins lst mld pnt )
  2.     (while
  3.         (progn
  4.             (setvar 'errno 0)
  5.             (setq ent (car (entsel "\nSelect block <exit>: ")))
  6.             (cond
  7.                 (   (= 7 (getvar 'errno))
  8.                     (princ "\nMissed, try again.")
  9.                 )
  10.                 (   (null ent)
  11.                     nil
  12.                 )
  13.                 (   (/= "INSERT" (cdr (assoc 0 (setq enx (entget ent)))))
  14.                     (princ "\nObject is not a block.")
  15.                 )
  16.                 (   (/= 1 (cdr (assoc 66 enx)))
  17.                     (princ "\nBlock is not attributed.")
  18.                 )
  19.                 (   (not
  20.                         (and
  21.                             (setq lst (vlax-invoke (vlax-ename->vla-object ent) 'getattributes)
  22.                                   lst (mapcar '(lambda ( x ) (cons (strcase (vla-get-tagstring x)) x)) lst)
  23.                             )
  24.                             (setq at1 (cdr (assoc "LAND_FEAT" lst)))
  25.                             (setq at2 (cdr (assoc "COMMENTS"  lst)))
  26.                         )
  27.                     )
  28.                     (princ "\nBlock does not contain \"LAND_FEAT\" & \"COMMENTS\" attributes.")
  29.                 )
  30.                 (   (and
  31.                         (= "" (vla-get-textstring at1))
  32.                         (= "" (vla-get-textstring at2))
  33.                     )
  34.                     (princ "\nBoth attributes are empty.")
  35.                 )
  36.                 (   (setq ins (cdr (assoc 10 enx))
  37.                           pnt (getpoint (trans ins ent 1) "\nPick leader endpoint <exit>: ")
  38.                     )
  39.                     (setq mld
  40.                         (vlax-invoke
  41.                             (vlax-get-property (LM:acdoc)
  42.                                 (if (= 1 (getvar 'cvport))
  43.                                     'paperspace
  44.                                     'modelspace
  45.                                 )
  46.                             )
  47.                             'addmleader
  48.                             (append (trans ins ent 0) (trans pnt 1 0))
  49.                             0
  50.                         )
  51.                     )
  52.                     (vla-move mld
  53.                         (vlax-3D-point 0 0 (caddr (vlax-invoke mld 'getleaderlinevertices 0)))
  54.                         (vlax-3D-point 0 0 (caddr (trans ins ent 0)))
  55.                     )
  56.                     (vla-put-textstring mld
  57.                         (strcat
  58.                             (if (= "" (vla-get-textstring at1))
  59.                                 ""
  60.                                 (strcat
  61.                                     "%<\\AcObjProp Object(%<\\_ObjId "
  62.                                     (LM:ObjectID at1)
  63.                                     ">%).TextString>%"
  64.                                     (if (= "" (vla-get-textstring at2)) "" "\n")
  65.                                 )
  66.                             )
  67.                             (if (= "" (vla-get-textstring at2))
  68.                                 ""
  69.                                 (strcat
  70.                                     "%<\\AcObjProp Object(%<\\_ObjId "
  71.                                     (LM:ObjectID at2)
  72.                                     ">%).TextString>%"
  73.                                 )
  74.                             )
  75.                         )
  76.                     )
  77.                     (vla-put-textrotation mld 0.0)
  78.                     (if (<= (car pnt) (car (trans ins ent 1)))
  79.                         (progn
  80.                             (vla-setdoglegdirection mld 0 (vlax-3D-point (trans '(-1.0 0.0) 1 0 t)))
  81.                             (vlax-invoke mld 'setleaderlinevertices 0 (append (trans ins ent 0) (trans pnt 1 0)))
  82.                         )
  83.                         (vla-setdoglegdirection mld 0 (vlax-3D-point (trans '(1.0 0.0) 1 0 t)))
  84.                     )
  85.                     (vla-regen (LM:acdoc) acactiveviewport)
  86.                     t
  87.                 )
  88.             )
  89.         )
  90.     )
  91.     (princ)
  92. )
  93.  
  94. ;; ObjectID  -  Lee Mac
  95. ;; Returns a string containing the ObjectID of a supplied VLA-Object
  96. ;; Compatible with 32-bit & 64-bit systems
  97.  
  98. (defun LM:ObjectID ( obj )
  99.     (eval
  100.         (list 'defun 'LM:ObjectID '( obj )
  101.             (if
  102.                 (and
  103.                     (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
  104.                     (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
  105.                 )
  106.                 (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
  107.                '(itoa (vla-get-objectid obj))
  108.             )
  109.         )
  110.     )
  111.     (LM:ObjectID obj)
  112. )
  113.  
  114. ;; Active Document  -  Lee Mac
  115. ;; Returns the VLA Active Document Object
  116.  
  117. (defun LM:acdoc nil
  118.     (LM:acdoc)
  119. )
  120.  

jtm2020hyo

  • Newt
  • Posts: 198
Re: Lisp to read attribute and draw mleader with leader style
« Reply #27 on: April 27, 2020, 09:16:59 AM »
I found this routine very useful. Just one tweak to make the Z placement of mleader to be the same as the block, my blocks have different elevations and it will make it more eye pleasing if the mleaders are together with the block. Can you help me please :)

I'm glad that you found the program useful.  :-)

I have found that supplying the ActiveX addmleader method with leader coordinates with non-zero z-component has no effect on the elevation of the resultant MLeader, and that the MLeader must be separately moved to the appropriate elevation - this is perhaps a bug with the addmleader method.

Please try the following:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:mlb2 ( / at1 at2 ent enx ins lst mld pnt )
  2.     (while
  3.         (progn
  4.             (setvar 'errno 0)
  5.             (setq ent (car (entsel "\nSelect block <exit>: ")))
  6.             (cond
  7.                 (   (= 7 (getvar 'errno))
  8.                     (princ "\nMissed, try again.")
  9.                 )
  10.                 (   (null ent)
  11.                     nil
  12.                 )
  13.                 (   (/= "INSERT" (cdr (assoc 0 (setq enx (entget ent)))))
  14.                     (princ "\nObject is not a block.")
  15.                 )
  16.                 (   (/= 1 (cdr (assoc 66 enx)))
  17.                     (princ "\nBlock is not attributed.")
  18.                 )
  19.                 (   (not
  20.                         (and
  21.                             (setq lst (vlax-invoke (vlax-ename->vla-object ent) 'getattributes)
  22.                                   lst (mapcar '(lambda ( x ) (cons (strcase (vla-get-tagstring x)) x)) lst)
  23.                             )
  24.                             (setq at1 (cdr (assoc "LAND_FEAT" lst)))
  25.                             (setq at2 (cdr (assoc "COMMENTS"  lst)))
  26.                         )
  27.                     )
  28.                     (princ "\nBlock does not contain \"LAND_FEAT\" & \"COMMENTS\" attributes.")
  29.                 )
  30.                 (   (and
  31.                         (= "" (vla-get-textstring at1))
  32.                         (= "" (vla-get-textstring at2))
  33.                     )
  34.                     (princ "\nBoth attributes are empty.")
  35.                 )
  36.                 (   (setq ins (cdr (assoc 10 enx))
  37.                           pnt (getpoint (trans ins ent 1) "\nPick leader endpoint <exit>: ")
  38.                     )
  39.                     (setq mld
  40.                         (vlax-invoke
  41.                             (vlax-get-property (LM:acdoc)
  42.                                 (if (= 1 (getvar 'cvport))
  43.                                     'paperspace
  44.                                     'modelspace
  45.                                 )
  46.                             )
  47.                             'addmleader
  48.                             (append (trans ins ent 0) (trans pnt 1 0))
  49.                             0
  50.                         )
  51.                     )
  52.                     (vla-move mld
  53.                         (vlax-3D-point 0 0 (caddr (vlax-invoke mld 'getleaderlinevertices 0)))
  54.                         (vlax-3D-point 0 0 (caddr (trans ins ent 0)))
  55.                     )
  56.                     (vla-put-textstring mld
  57.                         (strcat
  58.                             (if (= "" (vla-get-textstring at1))
  59.                                 ""
  60.                                 (strcat
  61.                                     "%<\\AcObjProp Object(%<\\_ObjId "
  62.                                     (LM:ObjectID at1)
  63.                                     ">%).TextString>%"
  64.                                     (if (= "" (vla-get-textstring at2)) "" "\n")
  65.                                 )
  66.                             )
  67.                             (if (= "" (vla-get-textstring at2))
  68.                                 ""
  69.                                 (strcat
  70.                                     "%<\\AcObjProp Object(%<\\_ObjId "
  71.                                     (LM:ObjectID at2)
  72.                                     ">%).TextString>%"
  73.                                 )
  74.                             )
  75.                         )
  76.                     )
  77.                     (vla-put-textrotation mld 0.0)
  78.                     (if (<= (car pnt) (car (trans ins ent 1)))
  79.                         (progn
  80.                             (vla-setdoglegdirection mld 0 (vlax-3D-point (trans '(-1.0 0.0) 1 0 t)))
  81.                             (vlax-invoke mld 'setleaderlinevertices 0 (append (trans ins ent 0) (trans pnt 1 0)))
  82.                         )
  83.                         (vla-setdoglegdirection mld 0 (vlax-3D-point (trans '(1.0 0.0) 1 0 t)))
  84.                     )
  85.                     (vla-regen (LM:acdoc) acactiveviewport)
  86.                     t
  87.                 )
  88.             )
  89.         )
  90.     )
  91.     (princ)
  92. )
  93.  
  94. ;; ObjectID  -  Lee Mac
  95. ;; Returns a string containing the ObjectID of a supplied VLA-Object
  96. ;; Compatible with 32-bit & 64-bit systems
  97.  
  98. (defun LM:ObjectID ( obj )
  99.     (eval
  100.         (list 'defun 'LM:ObjectID '( obj )
  101.             (if
  102.                 (and
  103.                     (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE"))
  104.                     (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring)
  105.                 )
  106.                 (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false)
  107.                '(itoa (vla-get-objectid obj))
  108.             )
  109.         )
  110.     )
  111.     (LM:ObjectID obj)
  112. )
  113.  
  114. ;; Active Document  -  Lee Mac
  115. ;; Returns the VLA Active Document Object
  116.  
  117. (defun LM:acdoc nil
  118.     (LM:acdoc)
  119. )
  120.  


it is possible to edit the lisp to work with multiple selected dynamic blocks and all attributes inside?, the mleader should repeat the position in of the first mleader.