Author Topic: Matching Another Mleader Attribute Values  (Read 6746 times)

0 Members and 1 Guest are viewing this topic.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Matching Another Mleader Attribute Values
« on: January 20, 2016, 11:23:37 AM »
Is it possible to select a MLeader that has a block with an Attributed Value to another MLeader? Where it can match the same MLeader Style and Overwrite the existing Attribute?

I have found Lee's Awesome Routine

http://www.lee-mac.com/copytext.html

But I thought this would do the job, but maybe I am missing something?

Thanks for the help.
Civil3D 2020

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Matching Another Mleader Attribute Values
« Reply #1 on: January 20, 2016, 11:56:43 AM »
I haven't yet incorporated compatibility for MLeader Attributes into my Copy/Swap Text program.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Matching Another Mleader Attribute Values
« Reply #2 on: January 20, 2016, 12:01:09 PM »
Notta problem. I just wanted to make sure I wasn't nutts. Thanks for letting me know!
Civil3D 2020

tedg

  • Swamp Rat
  • Posts: 811
Re: Matching Another Mleader Attribute Values
« Reply #3 on: January 20, 2016, 01:30:24 PM »
I haven't yet incorporated compatibility for MLeader Attributes into my Copy/Swap Text program.
Slacker...
(JK...you are the MAN!! ..you share so much I had to kid)
Windows 10 Pro 64bit, AutoCAD 2023, REVIT 2023

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Matching Another Mleader Attribute Values
« Reply #4 on: January 20, 2016, 06:34:38 PM »
I haven't yet incorporated compatibility for MLeader Attributes into my Copy/Swap Text program.
Slacker...
(JK...you are the MAN!! ..you share so much I had to kid)

 :evil:

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Matching Another Mleader Attribute Values
« Reply #5 on: January 26, 2016, 05:19:58 PM »
Lee may not have incorporated mLeaders into his routine yet, but here is what I have. Please note that this will not copy mleaderstyles, but it will copy text to and from mleaders, tables, attributes, dtext, mtext and dimensions. In short if it contains text, this routine should handle it fairly well. You can also copy a text item to multiple pieces of text, set increments for numbers and even type text to enter instead.

Please note that this code heavily relies on code from Lee Mac and a few others, which should all be documented as far as I am aware. That being said, if you do see code of yours in this routine and it is not documented, please let me know so I can fix it.

Also, if you find bugs, please let me know that as well.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Matching Another Mleader Attribute Values
« Reply #6 on: January 26, 2016, 05:29:59 PM »
Hey, Thank you for sharing. I am messing around with one now. With the Mleaders I am at do the text side of things but not with the attached attributed block. I will keep plugging around with it, (lol maybe its my machine)!
Civil3D 2020

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Matching Another Mleader Attribute Values
« Reply #7 on: January 27, 2016, 03:03:08 PM »
@ cmwade77:
Thanks for sharing your code. I am particularly interested in the way you determine which Mleader attribute is selected.

Your approach in a nutshell: You calculate a box around a selected point and then check if the (translated) insertion point of the attribute falls inside that box. This is a bit tricky as the user can easily click a point that is further away.

Another approach would be to calculate the textbox of the attribute and determine if the selected point falls inside. This would be my preference, although there is then the issue of Mtext formatting.

To improve your approach:
Use the height of the attribute when calculating the box.
Take the block scaling into account.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Matching Another Mleader Attribute Values
« Reply #8 on: January 27, 2016, 07:01:23 PM »
@ cmwade77:
Thanks for sharing your code. I am particularly interested in the way you determine which Mleader attribute is selected.

Your approach in a nutshell: You calculate a box around a selected point and then check if the (translated) insertion point of the attribute falls inside that box. This is a bit tricky as the user can easily click a point that is further away.

Another approach would be to calculate the textbox of the attribute and determine if the selected point falls inside. This would be my preference, although there is then the issue of Mtext formatting.

To improve your approach:
Use the height of the attribute when calculating the box.
Take the block scaling into account.
The problem is how the block and attributes gets attached to the mLeader, basically, it treats it as though the mleader and block are always at 0,0 if you don't use my approach, which then makes it near impossible to accurately determine if the selected point works or not.

As for selecting a point further away, my routine does account for that in that if you do not click on an object of any sort, it will create a crossing window to paste the text into.

Admittedly, it's not the prettiest way to do it, in fact my method with the crossing window is flat out brute force, but it gets the job done. Admittedly this method is based off of code that was in this office long before I ever came to work here, I believe the part of the code that this is based on is over 20 years old, so there are indeed probably better ways to handle it, if you can figure out the insertion issues.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Matching Another Mleader Attribute Values
« Reply #9 on: January 28, 2016, 03:31:49 AM »
As for selecting a point further away, my routine does account for that in that if you do not click on an object of any sort, it will create a crossing window to paste the text into.
In the situation where you select an Mleader attribute but the picked point does not fall inside the 'insertion point box' this does not occur I think.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Matching Another Mleader Attribute Values
« Reply #10 on: January 28, 2016, 07:29:41 AM »
Could I ask if this works with a MLeader Attributed Block; do you have a dwg Mleader style that works with your routine? I can get the MLeader to work with Text, but I do not know if there is something wrong with the Attached Block. I have noticed if I Explode the MLeader and then CT on the Attributed Block it does work.
Civil3D 2020

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Matching Another Mleader Attribute Values
« Reply #11 on: January 28, 2016, 10:25:18 AM »
@ MSTG007:
I think the code was created with 'imperial' units in mind. The diagonal of the box referred to before is only 0.26.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Matching Another Mleader Attribute Values
« Reply #12 on: January 28, 2016, 10:33:32 AM »
Well, This is kinda what I am playing around with.
Civil3D 2020

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Matching Another Mleader Attribute Values
« Reply #13 on: January 28, 2016, 11:25:07 AM »
The problem is related to the alignment of the attribute.
Change (2x):
Code: [Select]
(setq TestPt1
  (polar
    (vlax-safearray->list
      (vlax-variant-value (vla-get-insertionpoint Att))
    )
    (angle '(0 0 0) InsPt1)
    (distance '(0 0 0) InsPt1)
  )
)
To:
Code: [Select]
(setq TestPt1
  (mapcar
    '+
    (vlax-get Att (if (zerop (vla-get-alignment Att)) 'insertionpoint 'textalignmentpoint))
    InsPt1
  )
)

Note: Your Mleader is annotative. I expect there will be additional issues with certain anno scales.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Matching Another Mleader Attribute Values
« Reply #14 on: January 28, 2016, 01:04:21 PM »
Could I ask if this works with a MLeader Attributed Block; do you have a dwg Mleader style that works with your routine? I can get the MLeader to work with Text, but I do not know if there is something wrong with the Attached Block. I have noticed if I Explode the MLeader and then CT on the Attributed Block it does work.
Here are the leader styles that we work with.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Matching Another Mleader Attribute Values
« Reply #15 on: January 28, 2016, 01:06:29 PM »
The problem is related to the alignment of the attribute.
Change (2x):
Code: [Select]
(setq TestPt1
  (polar
    (vlax-safearray->list
      (vlax-variant-value (vla-get-insertionpoint Att))
    )
    (angle '(0 0 0) InsPt1)
    (distance '(0 0 0) InsPt1)
  )
)
To:
Code: [Select]
(setq TestPt1
  (mapcar
    '+
    (vlax-get Att (if (zerop (vla-get-alignment Att)) 'insertionpoint 'textalignmentpoint))
    InsPt1
  )
)

Note: Your Mleader is annotative. I expect there will be additional issues with certain anno scales.
The other issue with your method is accounting for the scale of the block when inserted into Modelspace and scaled up with DIMSCALE or manually scaled.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Matching Another Mleader Attribute Values
« Reply #16 on: January 28, 2016, 01:10:53 PM »
lol. Thank you for the share! Yeah.. I am still trying to fit your code into the script. Still no luck with that, keeps erroring out. But, the annotation scale is the problem. But it should work in paperspace? 
Civil3D 2020

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Matching Another Mleader Attribute Values
« Reply #17 on: January 28, 2016, 01:45:24 PM »
lol. Thank you for the share! Yeah.. I am still trying to fit your code into the script. Still no luck with that, keeps erroring out. But, the annotation scale is the problem. But it should work in paperspace?
I have not tested it with annotative styles, but it definitely should work on any nonanotative style and should work in paperspace or modelspace, so long as dimscale is set properly.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Matching Another Mleader Attribute Values
« Reply #18 on: January 28, 2016, 02:30:43 PM »
I was playing around with the drawing I have uploaded, and I drew a few MLeaders in Paperspace and set the Annotation scale to None. I am hoping I did something wrong not to get it to work. lol.
Civil3D 2020

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Matching Another Mleader Attribute Values
« Reply #19 on: January 28, 2016, 04:19:25 PM »
The other issue with your method...
My code is a minor improvement of *your* method. And yes, as I have mentioned before, there is an issue with block scaling and also with the textsize. Of course if there is only one attribute the solution can be much simpler.

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Matching Another Mleader Attribute Values
« Reply #20 on: January 28, 2016, 07:37:12 PM »
The other issue with your method...
My code is a minor improvement of *your* method. And yes, as I have mentioned before, there is an issue with block scaling and also with the textsize. Of course if there is only one attribute the solution can be much simpler.
I see, I am still learning with the mapcar stuff and yes when there is only one attribute, it is much easier. It would be even easier if AutoCAD would return the actual locations of the insertion points of the text somehow, then I could use the same as any of the other attribute stuff.

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Matching Another Mleader Attribute Values
« Reply #21 on: March 20, 2016, 09:29:18 AM »
FWIW, I have now updated my Copy or Swap Text program to enable compatibility with Dimensions & MLeader Block Attributes.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Matching Another Mleader Attribute Values
« Reply #22 on: March 20, 2016, 04:02:42 PM »
Thank you so just lee for doing that!!!! Hopefully it wasn't too hard to add! Can't wait to try it tomorrow.
Civil3D 2020

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Matching Another Mleader Attribute Values
« Reply #23 on: March 20, 2016, 04:05:42 PM »
You're welcome - I hope it works well in your testing.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Matching Another Mleader Attribute Values
« Reply #24 on: March 21, 2016, 07:51:29 AM »
Alight, I had some time to test it out. I am getting a Selected MLeader has no editable content.

Code: [Select]
Command: ctx
Formatting retained: Yes
Select source text [Settings/Exit]:
Selected MLeader has no editable content.
Formatting retained: Yes
Select source text [Settings/Exit]:
Selected MLeader has no editable content.
Formatting retained: Yes
Select source text [Settings/Exit]: *Cancel*
Command:


By the way here is a same dwg. Maybe the sway the Mleader block setup is wrong?
Civil3D 2020

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Matching Another Mleader Attribute Values
« Reply #25 on: March 21, 2016, 03:41:07 PM »
Alight, I had some time to test it out. I am getting a Selected MLeader has no editable content.

Code: [Select]
Command: ctx
Formatting retained: Yes
Select source text [Settings/Exit]:
Selected MLeader has no editable content.
Formatting retained: Yes
Select source text [Settings/Exit]:
Selected MLeader has no editable content.
Formatting retained: Yes
Select source text [Settings/Exit]: *Cancel*
Command:


By the way here is a same dwg. Maybe the sway the Mleader block setup is wrong?

Many thanks - I've found the bug: it was the result of a single missing character, and dependent on the order of the components within the block definition of the MLeader Attributed Block!

I will update the program shortly.

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Matching Another Mleader Attribute Values
« Reply #26 on: March 21, 2016, 03:43:01 PM »
Woohoo. I helped lee out! Im glad you found it!
Civil3D 2020

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Matching Another Mleader Attribute Values
« Reply #27 on: March 21, 2016, 06:35:53 PM »
Updated here (V1.6).

Thank you once again for your time testing the program - let me know how you get on with the new version  :-)

MSTG007

  • Gator
  • Posts: 2601
  • I can't remeber what I already asked! I need help!
Re: Matching Another Mleader Attribute Values
« Reply #28 on: March 22, 2016, 07:11:25 AM »
BOOM! Works! This is gonna change everything. lol! THank you again!
Civil3D 2020

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Matching Another Mleader Attribute Values
« Reply #29 on: March 22, 2016, 07:38:48 AM »
BOOM! Works! This is gonna change everything. lol! THank you again!

Fantastic! I'm delighted that you can make use of the program  :-)