Author Topic: How to set new MLeaderStyle properties  (Read 9626 times)

0 Members and 1 Guest are viewing this topic.

kenkrupa

  • Newt
  • Posts: 84
How to set new MLeaderStyle properties
« on: February 15, 2012, 12:08:12 PM »
I have been using code like this to access and set MLeaderStyle properties:
  (setq
    *acad* (vlax-get-acad-object)
    *doc* (vla-get-activedocument *acad*)
    mldict (vla-item (vla-get-dictionaries *doc*) "ACAD_MLEADERSTYLE")
    mlstyle (vla-item mldict "Standard")
  )
  (vlax-dump-object mlstyle)

... and I can then control any of those properties. Problem now is that there are two settings that are not included (see image). Anyone have a solution for this?

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: How to set new MLeaderStyle properties
« Reply #1 on: February 16, 2012, 02:54:13 PM »
I cheat around this by putting all of my mleaderstyles into a drawing, then insert that drawing as a block.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: How to set new MLeaderStyle properties
« Reply #2 on: February 16, 2012, 03:07:16 PM »
I cheat around this by putting all of my mleaderstyles into a drawing, then insert that drawing as a block.
x2
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

kenkrupa

  • Newt
  • Posts: 84
Re: How to set new MLeaderStyle properties
« Reply #3 on: February 17, 2012, 09:59:43 AM »
I guess I could do the same. Thank you both.

Xander

  • Guest
Re: How to set new MLeaderStyle properties
« Reply #4 on: February 20, 2012, 06:48:07 AM »
I personally use the DXF codes to create the MLeader styles.

Code - Auto/Visual Lisp: [Select]
  1. ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
  2. ;|
  3. <function>cadcoder:createmultileaderstyle</function>
  4. <summary>Creates a MultiLeader style in accordance with GT standards</summary>
  5. <param name="$stylename">Multileader Style name</param>
  6. <param name="$fontname">Textstyle name to use</param>
  7.  
  8. <returns>Nothing</returns>
  9. |;
  10. ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
  11. (DEFUN cadcoder:createmultileaderstyle ($stylename $fontstyle / $styleentity lst)
  12.     (DEFUN createmultileader (data / dic obj)
  13.         ;;If we can reference the Mleaderstyle dictionary object
  14.         ;;and the proposed style name doesn't exist
  15.         ;;and the entmake was successful
  16.         (IF (AND (SETQ dic (DICTSEARCH (NAMEDOBJDICT) "ACAD_MLEADERSTYLE"))
  17.                  (NOT (DICTSEARCH (SETQ dic (CDR (ASSOC -1 dic))) "GTSTD"))
  18.                  (SETQ obj (ENTMAKEX data))
  19.             )
  20.             ;;Add the style to the dictionary
  21.             (DICTADD dic (CDR (ASSOC 3 data)) obj)
  22.         )
  23.     )
  24.     ;;If the text style doesn't exist, exit
  25.     (IF (= nil (TBLSEARCH "STYLE" $fontstyle))
  26.         (EXIT)
  27.     )
  28.     ;;Create the Mleader DXF style list
  29.     (SETQ lst
  30.              (LIST
  31.                  (CONS 0 "MLEADERSTYLE")
  32.                  (CONS 100 "AcDbMLeaderStyle")
  33.                  (CONS 179 2) ;Text Attachment Point
  34.                  (CONS 170 2) ;Content Type
  35.                  (CONS 171 1) ;Draw MLeaderOrder Type
  36.                  (CONS 172 0) ;DrawLeaderOrderType
  37.                  (CONS 90 0) ;MaxLeader Segments
  38.                  (CONS 40 0.0) ;First Segment Angle Constraint
  39.                  (CONS 41 0.0) ;Second Segment Angle Constraint
  40.                  (CONS 173 1) ;Leader Line Type
  41.                  (CONS 91 (colour->mleaderstylecolour 1)) ;Leader Line Color (Red)
  42.                  (CONS 340 (TBLOBJNAME "LTYPE" "ByLayer")) ;Leader Line Type
  43.                  (CONS 92 -1) ;Leader Line weight
  44.                  (CONS 290 1) ;Enable Landing
  45.                  (CONS 42 1.5) ;Landing Gap
  46.                  (CONS 291 1) ;Enable Dog Leg
  47.                  (CONS 43 3) ;Dog Leg Length
  48.                  (CONS 3 $stylename) ;MLeaderDescription
  49.                  (CONS 341 (CDR (ASSOC 330 (ENTGET (TBLOBJNAME "BLOCK" "GT-ARR7"))))) ;Leader ArrowID
  50.                  (CONS 44 1) ;Arrow Head Size
  51.                  (CONS 300 "") ;Default Text contents
  52.                  (CONS 342 (TBLOBJNAME "STYLE" $fontstyle)) ;MTextStyleID
  53.                  (CONS 174 1) ;Text Left Attachment Type
  54.                  (CONS 178 1) ;Text Right Attachment Type
  55.                  (CONS 175 1) ;Text Angle Type
  56.                  (CONS 176 0) ;Text Alignment Type
  57.                  (CONS 93 (colour->mleaderstylecolour 3)) ;Text Color
  58.                  (CONS 45 0) ;Text Height
  59.                  (CONS 292 0) ;Enable Frame Text
  60.                  (CONS 297 1) ;Text Always Left Justify
  61.                  (CONS 46 0.18) ;Align Space
  62.                  (CONS 142 1.0) ;Scale
  63.                  (CONS 295 1) ;Overright Property Value
  64.                  (CONS 296 0) ;Is Annotative
  65.                  (CONS 143 0.0) ;Break Gap Size
  66.                  (CONS 271 0) ;Text Attachment Direction (0 = Horizontal, 1 = Vertical)
  67.                  (CONS 272 9) ;Bottom Text Attachment Direction (9 = Center, 10 = Underline & Center)
  68.                  (CONS 273 9) ;Top Text Attachment Direction (9 = Center, 10 = Underline & Center)
  69.              )
  70.     )
  71.     ;;Create the MLeader Style dictionary
  72.     (createmultileader lst)
  73.     ;;Set the new style as current
  74.     (SETVAR "CMLEADERSTYLE" $stylename)
  75.     (PRINC)
  76. )
  77.  
  78. ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
  79. ;|
  80. <function>color->mleaderstylecolor</function>
  81. <summary>Converts an ACI color to an mleader color.</sumary>
  82. <param name="c">ACI color</param>
  83.  
  84. <returns>Mleader color expressed as a 24bit value.</returns>
  85. |;
  86.  ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
  87. (DEFUN colour->mleaderstylecolour (c)
  88.     ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
  89.     ;|
  90.     <function>color:rgb->true</function>
  91.     <summary>Converts an RGB color to a true color</sumary>
  92.     <param name="r">Red color value</param>
  93.     <param name="g">Green color value</param>
  94.     <param name="b">Blue color value</param>
  95.     <returns>Color value</returns>
  96.     |;
  97.     ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
  98.  
  99.     (DEFUN color:rgb->true (r g b)
  100.         (+
  101.             (LSH (FIX r) 16)
  102.             (LSH (FIX g) 8)
  103.             (FIX b)
  104.         )
  105.     )
  106.     (COND
  107.         ((LISTP c)
  108.          (+ -1040187392 (APPLY 'color:rgb->true c))
  109.         )
  110.         ((= 0 c)
  111.          -1056964608
  112.         )
  113.         ((= 256 c)
  114.          -1073741824
  115.         )
  116.         ((< 0 c 256)
  117.          (+ -1023410176 (color:rgb->true 0 0 c))
  118.         )
  119.     )
  120. )
  121.  
  122.  
  123. ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
  124. ;|
  125. <function>mleaderstylecolor->color</function>
  126. <summary>Converts an MLeader color to the True or ACI color.</sumary>
  127. <param name="c">Mleader color</param>
  128.  
  129. <returns>True or ACI color.</returns>
  130. |;
  131.  ;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
  132. (DEFUN mleaderstylecolour->colour (c)
  133.  
  134.     ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
  135.     ;|
  136.     <function>color:true->rgb</function>
  137.     <summary>Converts an True color to a RGB color</sumary>
  138.     <param name="c">True color to convert</param>
  139.     <returns>Color value</returns>
  140.     |;
  141.     ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
  142.     (DEFUN color:true->rgb (c)
  143.         (LIST
  144.             (LSH (LSH (FIX c) 8) -24)
  145.             (LSH (LSH (FIX c) 16) -24)
  146.             (LSH (LSH (FIX c) 24) -24)
  147.         )
  148.     )
  149.     (IF (< 0 (LOGAND 16777216 c))
  150.         (LAST (color:true->rgb c))
  151.         (IF (EQUAL '(0 0 0) (SETQ c (color:true->rgb c)))
  152.             256
  153.             c
  154.         )
  155.     )
  156. )
  157.  
  158.  

MLeader color index conversions by Lee Mac
http://www.theswamp.org/index.php?topic=37313.msg454906#msg454906

The code here can be modified to update an existing style or create one from scratch. Just need to customize the settings.

DXF 297 is the always left justify.
« Last Edit: February 20, 2012, 06:56:58 AM by Xander »

kenkrupa

  • Newt
  • Posts: 84
Re: How to set new MLeaderStyle properties
« Reply #5 on: February 20, 2012, 11:41:17 AM »
Thank you very much Xander - this does the trick, except that it would not modify an existing style. Since I do want to update the style, I added a removal to the code (it does nothing if not exist, so no need to check first):
Code - Auto/Visual Lisp: [Select]
  1.     (DEFUN createmultileader (data / dic obj)
  2.         ;;If we can reference the Mleaderstyle dictionary object
  3.         ;;and the entmake was successful
  4.         (IF (AND (SETQ dic (DICTSEARCH (NAMEDOBJDICT) "ACAD_MLEADERSTYLE"))
  5.                  (SETQ dic (CDR (ASSOC -1 dic)))
  6.                  (SETQ obj (ENTMAKEX data))
  7.             )(progn
  8.             ; Remove style if present
  9.             (dictremove dic $stylename)
  10.             ;;Add the style to the dictionary
  11.             (DICTADD dic $stylename obj)
  12.         ))
  13.     )
  14.  

Also, (in case anyone else is interested) I don't use an arrow block, so just omitting the (cons 341  ...) line does the trick.

I'd like to know how you post code like that? I've tried searching Help and didn't find anything.
« Last Edit: February 20, 2012, 07:16:58 PM by kenkrupa »

Xander

  • Guest
Re: How to set new MLeaderStyle properties
« Reply #6 on: February 20, 2012, 05:26:55 PM »
How to format the code can be found here: http://www.theswamp.org/index.php?topic=4429.0

Under the 'First things First' section.

kenkrupa

  • Newt
  • Posts: 84
Re: How to set new MLeaderStyle properties
« Reply #7 on: February 20, 2012, 07:18:25 PM »

Xander

  • Guest
Re: How to set new MLeaderStyle properties
« Reply #8 on: February 20, 2012, 11:42:07 PM »
Thank you very much Xander - this does the trick, except that it would not modify an existing style. Since I do want to update the style, I added a removal to the code (it does nothing if not exist, so no need to check first):
--snip--

GASP.  I'm not sure on how this may affect the drawing later on. After all, multi-leaders 'should' be modified through the VisualLisp core.
Below is a modified version of the previous source to update (without removing) an existing style. You just need to find your DXF codes and adjust as necessary.

Code - Auto/Visual Lisp: [Select]
  1. ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
  2. ;|
  3. <function>cadcoder:updatemultileaderstyle</function>
  4. <summary>Updates an existing multileader style.</summary>
  5. <param name="$stylename">Multileader Style name</param>
  6. <returns>Nothing</returns>
  7. |;
  8. ;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-;;
  9. (DEFUN cadcoder:updatemultileaderstyle ($stylename / lst dic data)
  10.   (IF
  11.     ;;Ensure a dictionary reference
  12.     (AND (SETQ dic (DICTSEARCH (NAMEDOBJDICT) "ACAD_MLEADERSTYLE"))
  13.          ;;And ensure the multileader style exists
  14.          (SETQ data (DICTSEARCH (SETQ dic (CDR (ASSOC -1 dic))) $stylename))
  15.     )
  16.      (PROGN
  17.        ;;Adjust the DXF Codes as required
  18.        (SETQ data (SUBST (CONS 297 0) (ASSOC 297 data) data))
  19.        ;;Update the Multi-leader style entry
  20.        (ENTMOD data)
  21.        ;;Update the dictionary
  22.        (ENTUPD dic)
  23.      )
  24.   )
  25.   (PRINC)
  26. )
  27.  
« Last Edit: February 20, 2012, 11:59:28 PM by Xander »

kenkrupa

  • Newt
  • Posts: 84
Re: How to set new MLeaderStyle properties
« Reply #9 on: February 21, 2012, 10:05:14 AM »
GASP.  I'm not sure on how this may affect the drawing later on.

OMG - you're right! :-o (And this is first time I've ever used "OMG".) I now see that doing the removal and replace rendered any existing mleaders with no style at all.

Thank you for the smack upside the head!