TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: JOHNB on September 24, 2012, 11:13:49 PM

Title: MLEADER
Post by: JOHNB on September 24, 2012, 11:13:49 PM
Hi all,
      I'm wondering if anybody knows if and how I can increment the value of the attributes in mleaders.
      For example I have a drawing with 50 parts each tagged with a mleader with attributed circle, I find
      that I don't need item 10 anymore therefore all items 11 and above will need to reduce by 1 or alternately
      I find I have to add an extra item @ say item 3 therefore items 4 and above need to increase by 1.
Hoping someone can help.
   Regards JohnB
Title: Re: MLEADER
Post by: Tharwat on September 25, 2012, 12:23:00 AM
Hi .

I think you mean Qleader and not Mleader , I am confused , so anyway you can change all the values the same way you are entering Block definition via Lisp .
A simple drawing would help a lot .
Title: Re: MLEADER
Post by: JOHNB on September 25, 2012, 05:22:23 PM
Tharwat I definitely mean mleaders.What I am wanting to do is automatically increase or decrease the numbers that appear in the block used on the end of the mleaders from a given number to another given number. I have a lisp file that works with ordinary attributed block but it does not work with mleaders because the block is not recognised as a block as it is part of the mleader. I have attached a file with mleader item numbers, now say I want to add another item @ number 2, I would want to increase the other item number by i ie 2 becomes 3, 3 become 4 and 4 becomes 5 and so on. I have also attached the lisp file that I use for ordinary attributed blocks.
Title: Re: MLEADER
Post by: Lee Mac on September 25, 2012, 08:19:13 PM
Here is a short & simple example to increment the value of a set of MLeader Block Attributes:
Code - Auto/Visual Lisp: [Select]
  1. < Incorrect code removed - updated below >

The above will increment the value of the first attribute in the attributed block associated with the MLeader.
Title: Re: MLEADER
Post by: Tharwat on September 26, 2012, 07:11:55 AM
Lee , have you tried the same code in vanilla ?
Actually I could not access the attributed block definition with entnext function , of course with the same one that is attached with Mleader entity .

Thanks
Title: Re: MLEADER
Post by: Lee Mac on September 26, 2012, 07:43:04 AM
Actually I could not access the attributed block definition with entnext function , of course with the same one that is attached with Mleader entity.

The Block & Attribute Definitions are referenced directly from the DXF data of the MLeader, with the data for each attribute represented by a block of DXF group codes:

Code: [Select]
    (344 . <block def ename>)
    ...
    (330 . <attdef ename>)
    (177 . <attribute index>)
    (44  . <attribute width factor>)
    (302 . <attribute content>)
    ...
    (330 . <attdef ename>)
    (177 . <attribute index>)
    (44  . <attribute width factor>)
    (302 . <attribute content>)
    ...
    (330 . <attdef ename>)
    (177 . <attribute index>)
    (44  . <attribute width factor>)
    (302 . <attribute content>)
    ...

Reference (http://docs.autodesk.com/ACD/2011/ENU/filesDXF/WS1a9193826455f5ffc751fd10f4618e369-5bd9.htm)
Title: Re: MLEADER
Post by: JOHNB on September 26, 2012, 05:48:19 PM
Lee,
   Many thanks for your reply.
   Unfortunately when running the lisp I get the following error message:
     ; error: Automation Error. Calling method AddItems of interface
          IAcadSelectionSet failed
   Hoping you can fix.
  Regards
   JohnB
Title: Re: MLEADER
Post by: Lee Mac on September 26, 2012, 05:59:37 PM
Unfortunately when running the lisp I get the following error message:
Code: [Select]
; error: Automation Error. Calling method AddItems of interface IAcadSelectionSet failed

Hi John,

I can't seem to replicate the error on my system, however, since the error message pertains to the Selection Set VLA-Object, try the following code which uses a different method to iterate over the set:

Code - Auto/Visual Lisp: [Select]
  1. < Incorrect code removed - updated below >
Title: Re: MLEADER
Post by: JOHNB on September 26, 2012, 07:11:35 PM
Lee,
    Still getting error messages:
    ; error: Exception occurred: 0xC0000005 (Access Violation)
    ; warning: unwind skipped on unknown exception
    Regards
   JohnB
Title: Re: MLEADER
Post by: Lee Mac on September 26, 2012, 07:35:26 PM
What version of AutoCAD are you using John? And 32-bit or 64-bit?
Title: Re: MLEADER
Post by: JOHNB on September 26, 2012, 10:41:40 PM
Autocad 2012 - 64 bit
Title: Re: MLEADER
Post by: Lee Mac on September 27, 2012, 06:32:06 AM
Sorry, I had overlooked the analogous setblockattributevalue32 method for modifying attribute values within mleader blocks on 64-bit systems; try the following updated code:

Code - Auto/Visual Lisp: [Select]
  1. ;; Increment MLeader Block Attributes  -  Lee Mac
  2. (defun c:mlinc ( / aid blk bnm doc inc lst sel )
  3.     (if (setq sel (ssget "_:L" '((0 . "MULTILEADER"))))
  4.         (progn
  5.                   blk (vla-get-blocks doc)
  6.             )
  7.             (repeat (setq inc (sslength sel))
  8.                 (setq obj (vlax-ename->vla-object (ssname sel (setq inc (1- inc)))))
  9.                 (if (and (= acblockcontent (vla-get-contenttype obj))
  10.                         (or (setq aid (cdr (assoc (setq bnm (vla-get-contentblockname obj)) lst)))
  11.                             (progn
  12.                                 (vlax-for sub (vla-item blk bnm)
  13.                                     (if (and (null aid) (= "AcDbAttributeDefinition" (vla-get-objectname sub)))
  14.                                         (if (vlax-property-available-p sub 'objectid32)
  15.                                             (setq aid (vla-get-objectid32 sub))
  16.                                             (setq aid (vla-get-objectid   sub))
  17.                                         )
  18.                                     )
  19.                                 )
  20.                                 (setq lst (cons (cons bnm aid) lst))
  21.                                 aid
  22.                             )
  23.                         )
  24.                     )
  25.                     (if (vlax-method-applicable-p obj 'setblockattributevalue32)
  26.                         (vla-setblockattributevalue32 obj aid (itoa (1+ (atoi (vla-getblockattributevalue32 obj aid)))))
  27.                         (vla-setblockattributevalue   obj aid (itoa (1+ (atoi (vla-getblockattributevalue   obj aid)))))
  28.                     )
  29.                 )
  30.             )
  31.         )
  32.     )
  33.     (princ)
  34. )
Title: Re: MLEADER
Post by: JOHNB on September 27, 2012, 05:19:16 PM
Lee,
     That works.
     Would it be possible to make it so that the value of the increment could be specified and to have the increment
     be a negative value.
   Thanks for the great work,
    JohnB
Title: Re: MLEADER
Post by: Lee Mac on September 27, 2012, 06:04:56 PM
That works.

Good stuff.

Would it be possible to make it so that the value of the increment could be specified and to have the increment be a negative value.

That's quite a simple alteration, so sure:

Code - Auto/Visual Lisp: [Select]
  1. ;; Increment MLeader Block Attributes  -  Lee Mac
  2. (defun c:mlinc ( / aid blk bnm doc inc lst num sel )
  3.     (if
  4.         (and
  5.             (setq num (getint "\nSpecify Increment: "))
  6.             (setq sel (ssget "_:L" '((0 . "MULTILEADER"))))
  7.         )
  8.         (progn
  9.                   blk (vla-get-blocks doc)
  10.             )
  11.             (repeat (setq inc (sslength sel))
  12.                 (setq obj (vlax-ename->vla-object (ssname sel (setq inc (1- inc)))))
  13.                 (if (and (= acblockcontent (vla-get-contenttype obj))
  14.                         (or (setq aid (cdr (assoc (setq bnm (vla-get-contentblockname obj)) lst)))
  15.                             (progn
  16.                                 (vlax-for sub (vla-item blk bnm)
  17.                                     (if (and (null aid) (= "AcDbAttributeDefinition" (vla-get-objectname sub)))
  18.                                         (if (vlax-property-available-p sub 'objectid32)
  19.                                             (setq aid (vla-get-objectid32 sub))
  20.                                             (setq aid (vla-get-objectid   sub))
  21.                                         )
  22.                                     )
  23.                                 )
  24.                                 (setq lst (cons (cons bnm aid) lst))
  25.                                 aid
  26.                             )
  27.                         )
  28.                     )
  29.                     (if (vlax-method-applicable-p obj 'setblockattributevalue32)
  30.                         (vla-setblockattributevalue32 obj aid (itoa (+ num (atoi (vla-getblockattributevalue32 obj aid)))))
  31.                         (vla-setblockattributevalue   obj aid (itoa (+ num (atoi (vla-getblockattributevalue   obj aid)))))
  32.                     )
  33.                 )
  34.             )
  35.         )
  36.     )
  37.     (princ)
  38. )

Thanks for the great work

Cheers John  8-)
Title: Re: MLEADER
Post by: JOHNB on September 27, 2012, 06:26:30 PM
Lee,
   That's perfect.
   Thanks for your efforts.
Many thanks
JohnB