TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Lee Mac on November 12, 2009, 08:16:53 AM

Title: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 12, 2009, 08:16:53 AM
I realise that I have laboured over the topic of aligning text to something - but I wanted to brush up on my knowledge of reactors and xData, so I have strived to create this program, which will align DText/MText to any Curve Object, and will re-align the text when the object is modified.

More as a learning exercise, but some of you may get some use out of it  8-)

(http://www.theswamp.org/screens/leemac/DTCurveV29.gif)

(http://www.theswamp.org/screens/leemac/Logo.gif)

(http://www.theswamp.org/screens/leemac/DTCurve%20Dialog.png)

Function Syntax:  DTCurve  /  DTRemove

Code: [Select]
;;;`,,`,,`,,`,,`,,`,,;;;
;;                                                                               ;;
;;;,,`,,`,,`,,`,,`,,`;;;
;;                                                                               ;;
;;                                                                               ;;
;;                     --=={  Dynamic Text Curve Align  }==--                    ;;
;;                                                                               ;;
;;  The Program will prompt the user to either Select existing text to align,    ;;
;;  or specify New Text. The user will then be prompted to select a curve, and   ;;
;;  the text specified/selected will be dynamically aligned to the selected      ;;
;;  curve.                                                                       ;;
;;                                                                               ;;
;;  Additionally, the user can press +/- to alter the text offset from the curve ;;
;;  and furthermore, toggle the text perpendicularity by pressing 'P' during     ;;
;;  text alignment. A Background Mask can be toggled by pressing 'B' when        ;;
;;  aligning MText. The Text can also be mirrored by pressing 'M' during text    ;;
;;  alignment. The TextStyle and Text Height may be altered by pressing 'S' when ;;
;;  aligning text.                                                               ;;
;;                                                                               ;;
;;  DTRemove:-                                                                   ;;
;;  ------------                                                                 ;;
;;  This function allows the user to remove Text/Object Associativity. Upon      ;;
;;  invoking this function, the user is prompted to select either Text or        ;;
;;  object.                                                                      ;;
;;                                                                               ;;
;;  If the user picks an object, all text associativity with that object is      ;;
;;  removed. If the user picks a text object, the associativity between the      ;;
;;  text and the object that it was aligned with, is removed.                    ;;
;;                                                                               ;;
;;  The user can also press 'A' to clear all associativity within the drawing.   ;;
;;                                                                               ;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;  FUNCTION SYNTAX:  DTCurve/DTRemove                                           ;;
;;                                                                               ;;
;;  Notes:-                                                                      ;;
;;  ------------                                                                 ;;
;;  Text and MText Justification will be changed to Middle Center Justification  ;;
;;  to allow text to be correctly aligned.                                       ;;
;;                                                                               ;;
;;  Background Mask functionality can only be used when aligning MText.          ;;
;;                                                                               ;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;  AUTHOR:                                                                      ;;
;;                                                                               ;;
;;  Copyright Lee McDonnell, November 2009. All Rights Reserved.               ;;
;;                                                                               ;;
;;      { Contact: Lee Mac @ TheSwamp.org, CADTutor.net }                        ;;
;;                                                                               ;;
;;  WITH ADDITIONAL THANKS TO:                                                   ;;
;;                                                                               ;;
;;    Luis Esquivel (LE)                                                        ;;
;;                                                                               ;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;  VERSION:                                                                     ;;
;;                                                                               ;;
;;     1.0   ~~   6th November 2009   ~~   First Release                    ;;
;;...............................................................................;;
;;     1.1   ~~  13th November 2009   ~~   Fixed bug that allowed text to   ;;
;;                                              aligned to multiple objects.     ;;
;;...............................................................................;;
;;     1.2   ~~  15th November 2009   ~~   Added DTRemove to remove align   ;;
;;                                              associativity.                   ;;
;;...............................................................................;;
;;     1.3   ~~  15th November 2009   ~~   Added Ability to Align MText.    ;;
;;...............................................................................;;
;;     1.4   ~~  16th November 2009   ~~   Added Ability to use a           ;;
;;                                              Background Mask, when aligning   ;;
;;                                              MText.                           ;;
;;...............................................................................;;
;;     1.5   ~~  16th November 2009   ~~   General Bug Fixes.               ;;
;;...............................................................................;;
;;     1.6   ~~  17th November 2009   ~~   Updated code to work in all UCS. ;;
;;...............................................................................;;
;;     1.7   ~~  17th November 2009   ~~   Added Logo to DTRemove function. ;;
;;...............................................................................;;
;;     1.8   ~~  17th November 2009   ~~   Fixed Bug to allow correct text  ;;
;;                                              offset/perpendicularity setting  ;;
;;                                              when updating text by Reactor.   ;;
;;                                             General Bug Fixes.               ;;
;;...............................................................................;;
;;     1.9   ~~  17th November 2009   ~~   Fixed Text Rotation bug, for     ;;
;;                                              Vertical lines.                  ;;
;;...............................................................................;;
;;     2.0   ~~  17th November 2009   ~~   General Bug Fixes.               ;;
;;                                             Added ability for user to        ;;
;;                                              manually input offset distance.  ;;
;;...............................................................................;;
;;     2.1   ~~  19th November 2009   ~~   DTRemove updated to remove all   ;;
;;                                              XData from object.               ;;
;;...............................................................................;;
;;     2.2   ~~  20th November 2009   ~~   Added Mirror Text Option.        ;;
;;...............................................................................;;
;;     2.3   ~~  25th November 2009   ~~   Added TextStyle/Height Dialog.   ;;
;;...............................................................................;;
;;     2.4   ~~   2nd December 2009   ~~   Fixed Dialog Bug.                ;;
;;...............................................................................;;
;;     2.5   ~~   3rd December 2009   ~~   Added Selection highlighting.    ;;
;;...............................................................................;;
;;     2.6   ~~   4th December 2009   ~~   Upgraded DTRemove function to    ;;
;;                                              include option to Remove All     ;;
;;                                              associativity from objects.      ;;
;;...............................................................................;;
;;     2.7   ~~   7th December 2009   ~~   Re-Structured xData Storage to   ;;
;;                                              allow text to be aligned to same ;;
;;                                              part of object upon re-alignment ;;
;;...............................................................................;;
;;     2.8   ~~  15th February 2010   ~~   Fixed realignment bug when line  ;;
;;                                              length is less than text.        ;;
;;                                             General Bug Fixes.               ;;
;;...............................................................................;;
;;     2.9   ~~  16th February 2010   ~~   Updated Code Layout.             ;;
;;                                             Added call to turn off reactor   ;;
;;                                              whilst main function is running. ;;
;;...............................................................................;;
;;                                                                               ;;
;;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=;;
;;                                                                               ;;
;;;`,,`,,`,,`,,`,,`,,;;;
;;                                                                               ;;
;;;,,`,,`,,`,,`,,`,,`;;;

Enjoy,

Lee

[ Code Updated to Version 2.9 ]

Please Note:-
All text that has been aligned using previous Versions (pre V2.7 ) of this program will need to be re-aligned, use DTRemove, then DTCurve to re-align the text. This is due to a re-structuring of the xData stored in the object.


Code available here (http://lee-mac.com/dtcurve.html).
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Andrea on November 12, 2009, 08:46:55 AM
Moouuuaahh !!

we have same thing here..
the difference is the reactors...that we don't have.. ;-)

thanks for sharing Lee..  nice code !

Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 12, 2009, 08:50:02 AM
Thanks Andrea.... I thought you may have had a similar program... that always seems to happen with us  :-P
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Andrea on November 12, 2009, 09:14:51 AM
Thanks Andrea.... I thought you may have had a similar program... that always seems to happen with us  :-P

I thing that we have same vision of the future ...that's cool..  but weird.. ;-)

one little bug for your application....it is not working on diffrent UCS.
maybe need to use some "trans" conversion...

;-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: ronjonp on November 12, 2009, 09:58:50 AM
Pretty cool Lee  8-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: m4rdy on November 12, 2009, 10:30:56 AM
Lee,
You still always amaze me .... :love:
When i use your dtcurve with the same text but align to new different object, the text is still affected to previous object. Is that a bug?
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 12, 2009, 02:03:55 PM
Lee, amazing code, now if I can just figure out how to add a background mask to the text, it would be perfect.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 13, 2009, 07:16:33 AM
Thanks Guys  8-)

> Andrea - I hadn't really thought about the UCS yet - that comes next  ;-)

> M4rdy,

I had thought about this, and wasn't really sure how to proceed, currently the user can align the same text to two objects and the text will be aligned to the object that is updated last.

I could however implement some code that will remove the associativity from any object, when the user selects text that is already aligned.

I shall investigate with the next version :)

> cmwade77

I may include an extra option for a background mask, but I have never worked with them, so I shall have to experiment a bit. :P


Thanks for the comments guys, glad you all like the program,

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 13, 2009, 11:52:55 AM
O.k., I found the problem, the routine is inserting dtext, in order for the background mask to work it needs to be mtext, any way to get this change made? (I can set the background mask once it is).

Unfortunately wipeouts don't plot correctly on our plotters, so they are not an option.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 14, 2009, 02:13:41 PM
Ok, I have updated the code in the first post to Version 1.1

In this version, I have fixed the bug that allowed a single text object to be aligned to multiple objects.

I have many many ideas for this program, but little time to work on them, so I shall update it when I can  :wink:  Keep your eyes peeled  8-)

Enjoy!

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Andrea on November 14, 2009, 03:38:51 PM
wow !! neat Lee !!

thanks.   :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 15, 2009, 06:33:56 AM
I have updated the code in the first post to Version 1.2  -  this version includes DTRemove a function to remove the text/object associativity.  8-)

Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 15, 2009, 02:45:52 PM
Ok, I had a bit of time to work on it tonight, so I have updated the first post to Version 1.3, apologies for two updates in the same day.  :oops:

In this version, the user can align DText and MText.

I have also found a few bugs that I am working to resolve, but I wanted to release this asap, so that MText could be aligned  :wink:

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 16, 2009, 01:46:20 PM
As requested, I have added the ability to use a Background Mask with MText, and have updated the code in the first post to Version 1.4
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 16, 2009, 02:55:06 PM
Wow, your code is a lot shorter than what I had for adding background masking; however, I don't know enough about VLA stuff, so my question is: How would I go about enabling background masking by default?
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 16, 2009, 03:03:58 PM
Thanks mate  :-)

I have updated the code in the first post to include your suggestion - you will find the setting just underneath the header text.

I have also fixed a few more bugs - particularly those occuring when you trying to undo the updated text alignment - this version should be slightly more stable.

Enjoy,

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 16, 2009, 03:30:34 PM
Thank you for that, I do have a few more suggestions, if I have the time today I might try to tackle them:

We quite often will go through and add all of our text at once, so these items would make the workflow much faster for us, just a thought.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 16, 2009, 03:38:08 PM
Some nice ideas, thanks :-)

But this would mean a restructure of the whole first section of the program - only for the gain of not having to repeat the command (right click on my CAD), and I have already incorporated the default text that will remember the last entered text (which does improve workflow slightly)... but if I have time after incorporating the other ideas I have in mind for this program, I may consider it.

Thanks for the suggestions and comments, I appreciate it and am glad you like the program.

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 16, 2009, 08:01:35 PM
Ok, a quick update to Version 1.6, this version should work in all UCS  ;-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 16, 2009, 08:03:07 PM
Ok, after a bit of working on it, I got it, you can insert multiple pieces of text, you can also select a new curve by pressing N when inserting text and you can type or select new text by pressing T while inserting text.

It seems to all work fairly well, but I am sure there are better ways to do this.

I change the command name to IT, because I am changing the behavior of the function and some authors prefer that and also to prevent a version conflict. Lee, please feel free to change it back or to ask me to if you want, I just don't want to cause anyone any offense. As I said before, this is our preferred workflow here, so getting it working this way was something that made sense for us.

Please note that mine was based off of version 1.5, as 1.6 was posted while I was typing this, so it may not work in all UCS.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 16, 2009, 08:09:09 PM
Chris,

Feel free to modify my code to suit your needs - it is freeware after all. But I do thank you for changing the filename to prevent clashes with users expecting different results.

I haven't perused your code in great detail, but it looks like you have made my text/curve selections sub functions and call them through the main GrRead loop. I personally don't like to use "flags" to exit loops, but that is just my personal peference, and I'm sure others will differ.

Glad you could make use of it,

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 17, 2009, 10:58:02 AM
Yeah, I agree, it was just the fast way to get it up and running for my users, they love the idea of having the text move when our linework changes. I am going to continue to work on it to make it better and more stable, as well as incorporate your latest version of course. Any suggestions for improvement on the code are more than welcome of course, as I said, you know a great deal more than I do about LISP.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 17, 2009, 11:28:50 AM
Thanks Chris -

I do have a few ideas that I am working on, and there is a major bug that I will have to fix - which will mean a restructure of the xData.

But I shall work on it later tonight  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 17, 2009, 03:05:24 PM
I am curious, what is the major bug? I haven't come across it yet I suppose, but I would like to know, so that if it might impact my users I can tell them.

Also, I have incorporated the code that works with any ucs, as well as added these features that I needed to the code that I posted earlier:
I also cleaned up my code a bit, although I do still use the loop with a flag, as I am not quite sure how else to accomplish the same effect at the moment. And of course, feel free to use or modify any of the code that you might want, all I ask is credit in the remarks as appropriate.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 17, 2009, 03:25:55 PM
The major bug is the fact that if two different Text objects are aligned with varying offset/perpendicularity, when updated, they will be aligned to the last used offset/perpendicularity setting.

I have been working on the code though, and will post the update soon (I also have another thing to add first)  ;-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 17, 2009, 03:36:53 PM
Ok, that explains why I haven't seen it, in general our text will be drawn with a 0 offset and not perpendicular, but it is nice to have the option when needed.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 17, 2009, 03:44:53 PM
I have updated the code in the first post to include a "logo", when using the DTRemove function - showing the user which text/objects are aligned  8-)

(http://www.theswamp.org/screens/leemac/Logo.gif)

Enjoy!

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 17, 2009, 05:01:43 PM
Ok, I think this is close to being completely clean of bugs - I have updated the code in the first post to Version 1.8.

This Version will now correctly re-align text when objects are updated - using the perpendicularity and offset distance that the user originally specified.

Please Note:-
All text that has been aligned using previous Versions of this program will need to be re-aligned, use DTRemove, then DTCurve to re-align the text. This is due to a re-structuring of the xData stored in the object.


Let me know if you find any further bugs  8-)

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 17, 2009, 06:11:57 PM
O.k., I found a bug that hopefully has a fairly simple fix, the text on vertical lines faces the wrong direction. (See attached screen shot) The text should be rotated 180 degrees.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 17, 2009, 06:18:54 PM
Ahh, this bug only occurs when the text is aligned with zero offset, hence no definite normal vector to determine the orientation of the text - I shall look into it  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 17, 2009, 06:35:05 PM
Correction - it happens all the time.

Will get it sorted  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 17, 2009, 06:49:58 PM
Ok, it seemed to be just a simple rounding error - let me know how you get on with it now.  :-)

Code in first post updated.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 17, 2009, 07:11:22 PM
Sorry for all the updates...

Just had an idea to allow the user to manually input the offset distance - and also a few other bug fixes to do with the rounding of doubles..  :-)

Code in first post updated to Version 2.0

Bug-less me hopes  :wink:
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 17, 2009, 07:13:37 PM
Much better, thank you.

Here is the latest on my IT as well, with a few bug fixes along the way in my code and combining with your code through version 1.9.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 17, 2009, 07:17:02 PM
Nice one Chris,

Just a small thing, but when setting Text Layers/Styles etc, you could got the VL route and use (vla-put-StyleName tObj... or (vla-put-Height tObj... which saves you using command calls, and entlast.  :-)

 
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 17, 2009, 07:27:31 PM
Yeah, I am going to clean it up, but I have to learn it all first (your code will be a great help with this)

Also, the one attached to this email incorporates your 2.0 routine.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 17, 2009, 07:33:28 PM
No problem Chris, happy I could help with your learning  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 17, 2009, 07:36:30 PM
Oops spoke too soon, it looks like your code doesn't show creating layers or text styles, hmm, well, I will have to look into it, honestly I don't know much bout the VL route, just enough to be dangerous.  :lol:

Seriously, if you have any suggestions on where I can figure some of this out, I would appreciate it.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 17, 2009, 07:40:39 PM
Yeah, you will still have to accomodate for missing styles/layers etc  ;-)

To add a Layer in VL for example:

Code: [Select]
(vla-add
  (vla-get-layers
    (vla-get-ActiveDocument
      (vlax-get-acad-object)))  "New Layer")

But, it is much better practice to store the ActiveDocument in a variable, so that vlax-get-acad-object is not called multiple times.

The VLIDE help files on Visual LISP are mostly based around VBA, but you can read between the lines to get to know what is going on with Visual LISP.

I would still say that the best method is learning from example, and where better to find a multitude of examples than on a forum... :-)

Otherwise, AfraLISP has a section on Visual LISP that may help  :-)

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 18, 2009, 12:23:25 PM
Ok, thank you, I have setting colors and linetypes down, now how do I set the Plot Style? Also, I do I set the lineweight to "Default"?

Never mind, I figured it out, thank you, I am working to cleanup the code now and will post the updated version shortly, as I would love to get some more input on the code.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 18, 2009, 12:55:26 PM
Ok, now how do I define a text style as annotative? I can't seem to find that anywhere.

But I can find a previous post that I had made about using entmake to create annotative text, but in this case I want to set the style as annotative.


This is what I have so far:
Code: [Select]
(setq ITstyle (vla-add (vla-get-textstyles doc) *IT$tStyle*))
(vla-put-fontfile ITstyle *IT$tFont*)

(vla-put-width ITStyle *IT$tWf*)
(vla-put-obliqueangle ITstyle "0")

(if (= *IT$Anno* T)
(progn
(vla-put-height ITstyle *IT$tSze*)
(vla-put-annotative ITStyle T); <---This line is what doesn't work
)
(vla-put-height ITstyle "0")
)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 18, 2009, 03:37:26 PM
Ok, here is my cleaned up code, I was able to remove the error handling modifications that I made (which didn't always work all that well anyway) due to the changes, but I can't get the style working properly us the VL methods with annotative scaling, I left the code that I was trying, but remarked it out.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 18, 2009, 05:03:58 PM
Nice one Chris,

To be honest, I have never used annotative text, but that said - I cannot immediately see a way in VL to define a Text Style as Annotative - I would be interested if anyone else could offer a method to accomplish such a task.  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: T.Willey on November 18, 2009, 05:46:04 PM
To add annotative options to text, a simple way is:
Code: [Select]
(entmod
    (append
        (entget (tblobjname "style" <TextStyleNameHere>))
        (list '(-3 ("AcadAnnotative" (1000 . "AnnotativeData") (1002 . "{") (1070 . 1) (1070 . 1) (1002 . "}"))))
    )
)

A little more experimenting might show how to use ActiveX, but I don't add Xdata too often, so maybe this will get the juices flowing.

Edit:  Should add I don't work in an Acad that uses annotative, so that was a real quick look into it.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 18, 2009, 06:11:05 PM
Give this a shot:

Code: [Select]
(defun putAnno (styl / xtype xval)
  ;; by Lee McDonnell
 
  (setq xtype
    (vlax-make-variant
      (vlax-safearray-fill
        (vlax-make-safearray
          vlax-vbInteger '(0 . 7))
        '(1001 1000 1070 1000 1002 1070 1070 1002))))

  (setq xval
    (vlax-make-variant
      (vlax-safearray-fill
        (vlax-make-safearray
          vlax-vbVariant '(0 . 7))
        (list "AcadAnnotative" "AnnotativeData" 1 "AnnotativeData" "{" 1 1 "}"))))

  (vla-setXData
    (vla-item
      (vla-get-TextStyles
        (vla-get-ActiveDocument
          (vlax-get-acad-object))) styl) xtype xval))


Requires valid TextStyle String argument
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 18, 2009, 06:19:59 PM
Ok, that worked great, thank you; however, when the text gets created it is not annotative, I am able to use the CHPROP command to change it; however, I would like to avoid that, if I can, so any suggestions would be greatly appreciated, I have attached the latest code here.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 18, 2009, 06:56:06 PM
A quick test with:

Code: [Select]
(vla-AddMText
  (vla-get-ModelSpace
    (vla-get-ActiveDocument
      (vlax-get-acad-object)))
  (vlax-3D-point (getpoint)) 0 "Lee Mac")


After using PutAnno, seems to work fine for me  :?

*assuming that the annotative textstyle that was used in "putAnno" is current.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 18, 2009, 07:14:16 PM
I see the problem, only if the style is current when the text gets created, so I suppose I could set it current, then set it back as soon as the text is created.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: T.Willey on November 18, 2009, 07:28:51 PM
I see the problem, only if the style is current when the text gets created, so I suppose I could set it current, then set it back as soon as the text is created.

Or after it's created, just assign it to any style you want.  That is the problem with ActiveX calls.  You create the entity, then change the properties that are not set by the creation of it.  Unlike ' entmake ' ing.... where you can tell it what properties you want it to posses when creating the entity.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 18, 2009, 07:31:34 PM
True, but it will correctly assign the style, however will not make the text annotative  :|
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 18, 2009, 07:33:11 PM
I have been trying this:

Code: [Select]
(defun putAnnoObj (obj flag / xtype xval)
  ;; By Lee McDonnell

  (setq xtype
    (vlax-make-variant
      (vlax-safearray-fill
        (vlax-make-safearray
          vlax-vbInteger '(0 . 5))
        '(1001 1000 1002 1070 1070 1002))))

  (setq xval
    (vlax-make-variant
      (vlax-safearray-fill
        (vlax-make-safearray
          vlax-vbVariant '(0 . 5))
        (list "AcadAnnotative" "AnnotativeData" "{" flag 1 "}"))))

  (vla-setXData obj xtype xval))

(defun c:test (/ obj)

   (vla-put-StyleName
    (setq obj
      (vla-AddMText
        (vla-get-ModelSpace *doc)
          (vlax-3D-point (getpoint)) 0 "Lee Mac")) <Valid Style Name>)

  (putAnnoObj obj 1) ;; 1 for Annotative
  )

Using a valid Annotative Style Name which is not set to current.

The Text is created, however it is not visible, but the properties seem to be correct  :?
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 18, 2009, 07:43:42 PM
Here is my solution, I simply change the test style right before the text gets created and change it right back after it has been created, it works well and gets rid of the need for the chprop command.

Thank you all for all of your help in getting this working right, my users will appreciate it, we had an older version that did something similar, but there was no preview of where it was going to insert and it definitely didn't have the reactors, it also didn't work anywhere near as well as this does with xrefs.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 18, 2009, 07:46:07 PM
I'm glad you got it working Chris - well done. I hadn't tested the code with xRefs, but I'm very glad that you report it works!

But I am still curious as to how one would make the text annotative without setting the textstyle as current - I realise that it is easier to just set the Textstyle, but my curiosity gets the better of me...  :evil:
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 18, 2009, 07:56:02 PM
oops, I spoke too soon, the text comes out really small for some reason, I have to figure out how to set the paper height, any suggestions?
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: T.Willey on November 18, 2009, 07:58:13 PM
Maybe this will help.  I don't remember much, but I do remember doing something, and this looks like what I did, even though I didn't check it ( I know it's my thread ).

[ http://www.theswamp.org/index.php?topic=29287.0 ]
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 19, 2009, 11:21:11 AM
Was thinking of moving this thread to the "Show your Stuff" forum, what you reckon CAB (or other Mods)?
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: CAB on November 19, 2009, 12:13:28 PM
Just re post your first post in the Show Your Stuff and link back to this thread for those who might want to read all the
verbal traffic that lead to the development  of the final routine. And link this thread back to the Show Your Stuff .

Or is better to have it all in one place?
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 19, 2009, 12:17:26 PM
Ok, I actually found the problem, the dimscale needs to be set the same as 1/cannoscale due to how I am handling things, so I added some code to ensure that the Dimscale is set to 1/cannoscale when using annotative scaling and scaling by dimscale.

Thank you both for helping me get this routine running properly, you have helped me a lot.

I had to make a minor revision - the previous one errored out if the dimscale was already the same as 1/cannoscale, the code attached to this message has been updated.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 19, 2009, 12:41:03 PM
Just re post your first post in the Show Your Stuff and link back to this thread for those who might want to read all the
verbal traffic that lead to the development  of the final routine. And link this thread back to the Show Your Stuff .

Or is better to have it all in one place?


No, I think your idea is best, with the links - thanks  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 19, 2009, 12:42:24 PM
Ok, I actually found the problem, the dimscale needs to be set the same as 1/cannoscale due to how I am handling things, so I added some code to ensure that the Dimscale is set to 1/cannoscale when using annotative scaling and scaling by dimscale.

Thank you both for helping me get this routine running properly, you have helped me a lot.

I'm glad you finally got it working properly Chris, thanks for fully testing my routine also - I wouldn't have picked up a few of the bugs otherwise  ;-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 19, 2009, 12:55:27 PM
I have a correction to a previous post, the routine doesn't work with xrefs or blocks all the time.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 19, 2009, 02:36:46 PM
Ok, I have it working now with Xrefs and blocks, although xrefs and blocks are slow to use, but they work, also the slowness only applies to xrefs and blocks, nothing else is slow.

I modified a routine from the express tools, but all of the code in included here (with all applicable copyright information), so you should not need the express tools installed to use this. Ifanyone has a better suggestion on how to handle it, feel free to let me know.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: SteveK on November 19, 2009, 05:22:57 PM
Excellent program Lee, thanks!

Just a couple of notes:
I haven't been following the development and I notice DTRemove doesn't remove the xdata heading DTCURVE from the curve, just the rest, is this intentional? (I suppose for multiple aligned text?)

Also, one error I've received occurs in new drawings after aligning text to a curve once, immediately afterwards if I use DTREMOVE or DTCURVE I receive ** Error: Automation Error. Invalid class **. Something at my end?

Anyways when it matters it works great.  :-)

Steve
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 19, 2009, 05:44:08 PM
Ok, I have on more update to my IT, it allows you to specify the offset of the background mask.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 19, 2009, 06:30:07 PM
Excellent program Lee, thanks!

Just a couple of notes:
I haven't been following the development and I notice DTRemove doesn't remove the xdata heading DTCURVE from the curve, just the rest, is this intentional? (I suppose for multiple aligned text?)

Also, one error I've received occurs in new drawings after aligning text to a curve once, immediately afterwards if I use DTREMOVE or DTCURVE I receive ** Error: Automation Error. Invalid class **. Something at my end?

Anyways when it matters it works great.  :-)

Steve

Hi Steve,

Many thanks for your comments, I'm glad you like the program.

Thanks for alerting me to the fact that the xData header is not completely removed - for the object selection, all xdata should be removed - I shall update the code with this.

As for the error you are receiving, I cannot seem to replicate it - at exactly which point do you receive the error?

Thanks,

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 19, 2009, 06:37:12 PM
Code in first post updated to Version 2.1, All xData is now removed when using DTRemove  :wink:
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: SteveK on November 19, 2009, 07:05:41 PM
Great, ta. (and download counter back to 1  :|)

It's annoying I can't produce the error every time, but this is what I do to get the error occasionally:

EDIT: Lee I can't replicate the error at home so don't worry about it, must be something on the work machine.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Willie on November 19, 2009, 08:15:08 PM
This is a great tool Lee.  Thanks.  :-)

My suggestion:  Is it possible to add a flip/mirror option to the text to rotate it by 180?  If you have a rotated viewport, the text may show up upside down in the viewport, but it displays correctly in modelspace.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 20, 2009, 07:55:54 AM
This is a great tool Lee.  Thanks.  :-)

My suggestion:  Is it possible to add a flip/mirror option to the text to rotate it by 180?  If you have a rotated viewport, the text may show up upside down in the viewport, but it displays correctly in modelspace.

Hi Willie,

Thanks for the feedback, I'm glad you like the program  :-)

I should think I could add a mirror option for you  :wink:
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 20, 2009, 07:56:54 AM
EDIT: Lee I can't replicate the error at home so don't worry about it, must be something on the work machine.

I'm not sure what it would be, but if anyone else is having trouble, let me know  :wink:

Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on November 20, 2009, 11:20:03 AM
This is a great tool Lee.  Thanks.  :-)

My suggestion:  Is it possible to add a flip/mirror option to the text to rotate it by 180?  If you have a rotated viewport, the text may show up upside down in the viewport, but it displays correctly in modelspace.
You can also use the Annotative text idea and set it to change when you rotate viewports.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 20, 2009, 12:40:18 PM
My suggestion:  Is it possible to add a flip/mirror option to the text to rotate it by 180º?  If you have a rotated viewport, the text may show up upside down in the viewport, but it displays correctly in modelspace.

Willie, although Chris has offered another solution to this - I have added a "Mirror Text" option to the program - I figured there was no harm in adding another utility to the program in any case.

The Code in the first post has been updated to Version 2.2

But this requires another restructure of the xData, so any text aligned using previous versions, (pre 2.2) will need to be "re-aligned".

Enjoy,

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Willie on November 21, 2009, 04:07:39 AM
Cool Lee,

I am out of the office for the week, but I will try it next week.

Thanks!!  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 21, 2009, 09:16:53 AM
Cool Lee,

I am out of the office for the week, but I will try it next week.

Thanks!!  :-)

Your welcome Willie  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on November 25, 2009, 04:13:01 PM
Code updated to Version 2.3

This Version includes an option to change TextStyle and Height during Text Alignment - a suggestion from one of the guys over at CADTutor  :-)

Any comments/criticism/suggestions are welcome!

Enjoy,

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on December 01, 2009, 08:06:40 PM
Code updated to Version 2.4 to fix bug found with dialog - please report if any more bugs are found  8-)

Cheers,

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on December 02, 2009, 09:56:18 AM
Apologies, forgot to update the Version number in the Dialog title...  :oops: Code updated to reflect this.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on December 03, 2009, 02:23:37 PM
I have updated the code in the first post to Version 2.5 so that it should highlight text upon mouse-over.   :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Crank on December 04, 2009, 07:09:09 AM
Hi Lee,

Excellent tool! I use it all the time.

I wonder if it's possible to keep the text allways on te same side of the entity. Now it often jumps to the other side.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on December 04, 2009, 08:15:56 AM
Hi Lee,

Excellent tool! I use it all the time.

I wonder if it's possible to keep the text allways on te same side of the entity. Now it often jumps to the other side.

Thanks Crank  :-)

To get the text on the same side upon updating would be very difficult, as it is hard to determine a "side" to an object... but I shall investigate and see what I can come up with  :wink:
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: KOWBOI on December 04, 2009, 12:37:55 PM
I would love to use this, how can I download the code?
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on December 04, 2009, 12:39:32 PM
I'm not sure what the permissions are on this site as to how many posts you need (if any) to download attachments, but if you can, just click on the attachment in the first post  :wink:
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: cmwade77 on December 04, 2009, 01:17:03 PM
Hi Lee,

Excellent tool! I use it all the time.

I wonder if it's possible to keep the text allways on te same side of the entity. Now it often jumps to the other side.

Thanks Crank  :-)

To get the text on the same side upon updating would be very difficult, as it is hard to determine a "side" to an object... but I shall investigate and see what I can come up with  :wink:
Here's an idea, determine which side of the object the crosshairs are on (by determining the angle that they are from the object) and place the text on the side of the object that the crosshairs are on (based on that angle)?
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on December 04, 2009, 07:25:02 PM
I have updated the first post to Version 2.6 to include the option to remove all text/object associativity in the Drawing at once when using the DTRemove function.

Thanks for the suggestion Willie.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Andrea on December 06, 2009, 06:43:58 PM
I have updated the first post to Version 2.6 to include the option to remove all text/object associativity in the Drawing at once when using the DTRemove function.

Thanks for the suggestion Willie.

You did a very good job with this Lee.. :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on December 06, 2009, 06:51:09 PM
I have updated the first post to Version 2.6 to include the option to remove all text/object associativity in the Drawing at once when using the DTRemove function.

Thanks for the suggestion Willie.

You did a very good job with this Lee.. :-)

Thanks Andrea :-)

I am actually working on one final Version that uses a completely different method to re-align text and should mean that the text stays on the side that it is aligned to. But what with the Uni work, time is tight and I can only work on it when I get a spare minute...

Thanks :)

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on December 07, 2009, 12:48:35 PM
Ok, I have updated the code to Version 2.7.

In this version, I have restructured the way that the information is stored in the xData of an object, and hence any text that has been aligned with previous versions will need to be re-aligned (using DTRemove, then DTCurve).

I have changed the way that the text is re-aligned to the object, which should make it more predictable, and also should keep the text on the correct side of the object.

Of course, criticism/comments are welcome, and any bug reports.

Enjoy!

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 15, 2010, 02:20:59 PM
Following a bug report from over at CADTutor, I have updated the code in the first post to Version 2.8

However I cannot seem resolve a bug in which the user aligns 'object A', then aligns 'object B' to the same curve.

Then, if the user realigns 'object A' to the same curve again, 'object B' is used  :|

Any advice on this bug is welcome.

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: LE3 on February 15, 2010, 04:55:06 PM
Following a bug report from over at CADTutor, I have updated the code in the first post to Version 2.8

However I cannot seem resolve a bug in which the user aligns 'object A', then aligns 'object B' to the same curve.

Then, if the user realigns 'object A' to the same curve again, 'object B' is used  :|

Any advice on this bug is welcome.

Lee

First time I look at your coding style.

Did a quick review to your code, and the problem appears to be in this segment and in there it is flipping the handles - don't have much time to look in deep:
Code: [Select]
(foreach obj (vlr-owners *DCurve$Align$Reactor*)

             (if (not (vlax-erased-p obj))
               (progn

                 (vla-GetXData obj app 'typ 'val)

                 (if (and typ val)
                   (progn

                     (setq xDat (vl-remove-if-not
                                  (function
                                    (lambda (lst)
                                      (entget (handent (car lst)))))
                                 
                                  (read
                                    (vlax-variant-value
                                      (cadr
                                        (vlax-safearray->list val))))))
                     
                     (if (vl-position Hnd (mapcar (function car) xDat))
                       (progn
                         (putxDat obj app
                           (vl-prin1-to-string
                             (vl-remove-if
                               (function
                                 (lambda (x) (eq Hnd (car x)))) xDat))))))))

               (vlr-owner-remove *DCurve$Align$Reactor* obj)))

It might a good idea to place some temp string tags to display the first value, the second and third one, to verify your findings like:

Code: [Select]
        (  (eq 'ENAME (type rslt))

           (setq *Mac$Str* (vla-get-TextString
                             (setq tObj (vlax-ename->vla-object rslt)))
                 
                 tSze (vla-get-Height tObj)

                 Hnd  (vla-get-Handle tObj))

   (princ "\nHandle selected: ")
           (princ Hnd) (princ)
 

And here:
Code: [Select]
   (princ (setq msg (strcat "\n[+] or [-] for [O]ffset, [P]erpendicularity Toggle"
                           "\n[M]irror Text, [S]tyle Settings"
                           (if (eq "AcDbText" oNme) "" ", [B]ackground Mask"))))

  (setq handleStart (vla-get-handle tObj))
  (princ "\nBefore while: ")
  (princ handleStart) (princ)

  (while
    (progn
      (setq gr (grread t 15 0) code (car gr) data (cadr gr))

And:
Code: [Select]
            (  (= 25 code) nil)

            (t ))))

  (setq handleEnd (vla-get-handle tObj))
  (princ "\nEnd of while: ")
  (princ handleEnd) (princ)

  (vla-EndUndoMark doc)
  (redraw)
 

And if I may.-

1. I see that you want to keep all code clean and formatted, but I won't place my general functions inside of my main one and even in between important calls it is break by a place of a function, I know it is a preference style, but outside can be more useful, just use your own prefix_ to mark it.

2. Why call or set at the end your local variables to nil? if that it is done by autolisp ?

Hope that you won't mind, my 0.0002 cts. :)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 15, 2010, 05:21:20 PM
Following a bug report from over at CADTutor, I have updated the code in the first post to Version 2.8

However I cannot seem resolve a bug in which the user aligns 'object A', then aligns 'object B' to the same curve.

Then, if the user realigns 'object A' to the same curve again, 'object B' is used  :|

Any advice on this bug is welcome.

Lee

First time I look at your coding style.

Did a quick review to your code, and the problem appears to be in this segment and in there it is flipping the handles - don't have much time to look in deep:
Code: [Select]
(foreach obj (vlr-owners *DCurve$Align$Reactor*)

             (if (not (vlax-erased-p obj))
               (progn

                 (vla-GetXData obj app 'typ 'val)

                 (if (and typ val)
                   (progn

                     (setq xDat (vl-remove-if-not
                                  (function
                                    (lambda (lst)
                                      (entget (handent (car lst)))))
                                 
                                  (read
                                    (vlax-variant-value
                                      (cadr
                                        (vlax-safearray->list val))))))
                     
                     (if (vl-position Hnd (mapcar (function car) xDat))
                       (progn
                         (putxDat obj app
                           (vl-prin1-to-string
                             (vl-remove-if
                               (function
                                 (lambda (x) (eq Hnd (car x)))) xDat))))))))

               (vlr-owner-remove *DCurve$Align$Reactor* obj)))

It might a good idea to place some temp string tags to display the first value, the second and third one, to verify your findings like:

Code: [Select]
        (  (eq 'ENAME (type rslt))

           (setq *Mac$Str* (vla-get-TextString
                             (setq tObj (vlax-ename->vla-object rslt)))
                 
                 tSze (vla-get-Height tObj)

                 Hnd  (vla-get-Handle tObj))

   (princ "\nHandle selected: ")
           (princ Hnd) (princ)
 

And here:
Code: [Select]
   (princ (setq msg (strcat "\n[+] or [-] for [O]ffset, [P]erpendicularity Toggle"
                           "\n[M]irror Text, [S]tyle Settings"
                           (if (eq "AcDbText" oNme) "" ", [B]ackground Mask"))))

  (setq handleStart (vla-get-handle tObj))
  (princ "\nBefore while: ")
  (princ handleStart) (princ)

  (while
    (progn
      (setq gr (grread t 15 0) code (car gr) data (cadr gr))

And:
Code: [Select]
            (  (= 25 code) nil)

            (t ))))

  (setq handleEnd (vla-get-handle tObj))
  (princ "\nEnd of while: ")
  (princ handleEnd) (princ)

  (vla-EndUndoMark doc)
  (redraw)
 

And if I may.-

1. I see that you want to keep all code clean and formatted, but I won't place my general functions inside of my main one and even in between important calls it is break by a place of a function, I know it is a preference style, but outside can be more useful, just use your own prefix_ to mark it.

2. Why call or set at the end your local variables to nil? if that it is done by autolisp ?

Hope that you won't mind, my 0.0002 cts. :)

Hey Luis (think its you),

Many thanks for your time in looking at my code - it is appreciated.

I agree - the 'handle switching' does seem to be occurring when I check whether the text is already aligned to an object - and I tried to resolve it before posting the new code using the debugging strings (as you have also suggested) - and I think it occurs when I write the xdata to the object after removing the existing handle from the list, but I have no idea as to why they would switch  :|

I would normally localise all my functions within my main code, I realise that this makes them slightly slower when calling them, but it means they do not clash with functions that are perhaps defined in other programs - as you say, a prefix would get around this.

As for setting my variables to nil - this was just something I tried to see if it would fix the handle switching issue - I thought perhaps that the variable holding the text object was not being released, even though the variable was localised, so I set all variables to nil manually to make sure - but it didn't make a difference  :|

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: LE3 on February 15, 2010, 05:29:44 PM
Hi Lee,

- Is even moving the other object too... unless this is by design
- Also, on my first try I typed a text and way after end changing to mtext, is that me? or is there that change on your code?

Need to become more familiar with your code, inorder to really help you, if I get a chance later today, will give it a try.


And yes is me.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 15, 2010, 05:50:19 PM
Hi Lee,

- Is even moving the other object too... unless this is by design

No, this isn't by design - it's meant to re-align the text that you select  :|

Everything seems to be fine when aligning new text, it only seems to be when re-aligning  :-(

- Also, on my first try I typed a text and way after end changing to mtext, is that me? or is there that change on your code?

The user can either select text to align, or type new text. When typing new text, there is a setting at the top of the code that determines whether text or Mtext is created.

And yes is me.

Thought it was  :wink:
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: LE3 on February 15, 2010, 06:12:18 PM
- I am looking at your code now.

and on this line:
Code: [Select]
(vl-prin1-to-string
                             (vl-remove-if
                               (function
                                 (lambda (x) (eq Hnd (car x)))) xDat))

That sometimes return: "nil" and that it is saved.
In there with the (entget) you are trying to make sure that the handle is valid no?, that's why you recreate the xdata.

Code: [Select]
                 (vla-GetXData obj app 'typ 'val)

(print (vlax-safearray->list val))
;|
DTCURVE
Type or Select Text <TEXT1> :
Handle selected: 182
(#<variant 8 DTCURVE> #<variant 8 (("185" "181" 1.0 1.5708 0.0 6.44746 4.71239)
("182" "181" 1.0 1.5708 0.0 7.51307 4.71239))>)
Select Curve:
[+] or [-] for [O]ffset, [P]erpendicularity Toggle
[M]irror Text, [S]tyle Settings, [B]ackground Mask
Before while: 185
End of while: 185
|;
                 (if (and typ val)
 
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: LE3 on February 15, 2010, 06:29:11 PM
Also, Lee.

If you remove the lines between: (foreach obj (vlr-owners *DCurve$Align$Reactor*) ... (vlr-owner-remove *DCurve$Align$Reactor* obj)))

In your condition call where reads:

(cond (  (eq "" rslt))
        (  (eq 'STR (type rslt))

Then, I don't see the bug anymore... per my few tests.... well at least to be able to marked the code lines that are not working, and you will be able to get that fixed. :)

HTH
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 15, 2010, 06:30:42 PM
- I am looking at your code now.

and on this line:
Code: [Select]
(vl-prin1-to-string
                             (vl-remove-if
                               (function
                                 (lambda (x) (eq Hnd (car x)))) xDat))

That sometimes return: "nil" and that it is saved.
In there with the (entget) you are trying to make sure that the handle is valid no?, that's why you recreate the xdata.

Code: [Select]
                 (vla-GetXData obj app 'typ 'val)

(print (vlax-safearray->list val))
;|
DTCURVE
Type or Select Text <TEXT1> :
Handle selected: 182
(#<variant 8 DTCURVE> #<variant 8 (("185" "181" 1.0 1.5708 0.0 6.44746 4.71239)
("182" "181" 1.0 1.5708 0.0 7.51307 4.71239))>)
Select Curve:
[+] or [-] for [O]ffset, [P]erpendicularity Toggle
[M]irror Text, [S]tyle Settings, [B]ackground Mask
Before while: 185
End of while: 185
|;
                 (if (and typ val)
 

Yes, everytime I deal with the xData, I check that no text objects associated with the object have been deleted, and hence the handle isn't valid, and if they are, I remove them from the xData.

I don't think it would matter if the xData is set to 'nil' if the entity is the only one aligned to the object and then removed, as this would just be appended to when new entities are aligned - but I could be wrong of course.

Thanks for taking the time to help me Luis, I appreciate it  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 15, 2010, 06:34:33 PM
Also, Lee.

If you remove the lines between: (foreach obj (vlr-owners *DCurve$Align$Reactor*) ... (vlr-owner-remove *DCurve$Align$Reactor* obj)))

In your condition call where reads:

(cond (  (eq "" rslt))
        (  (eq 'STR (type rslt))

Then, I don't see the bug anymore... per my few tests.... well at least to be able to marked the code lines that are not working, and you will be able to get that fixed. :)

HTH

Very true - but what I don't understand is that there is nothing in that code snippet that would change the value of the 'tObj' (Text Object) variable, and hence change which text object is moved...   :|
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: LE3 on February 15, 2010, 08:16:09 PM
Lee,

It is getting difficult for me to become familiar again with object reactors, but for what I am seeing it is the way you setup the reactor, for example why there is a foreach to go over the xdata inside of the callback (modified event) instead of placing a dependent object (the selected text of new one) in the callback function defintion, that way when it is verified inside of the callback/event it will be easier to extracted there and also any extra data attached outside.

Clear as mud?

Not that I want you change anything, but did you see what I did on reactorswiz?... in there (and I know you are trying to do that too) you will see that there is a single object reactor that can handle as many objects as you want, don't know.

And yes, it is weird stuff what it is happening in the code lines, will give it another try need more coffee... :)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 15, 2010, 08:21:08 PM
It is getting difficult for me to become familiar again with object reactors, but for what I am seeing it is the way you setup the reactor, for example why there is a foreach to go over the xdata inside of the callback (modified event) instead of placing a dependent object (the selected text of new one) in the callback function defintion, that way when it is verified inside of the callback/event it will be easier to extracted there and also any extra data attached outside.

Do you mean add the new text object as another owner in the ObjectReactor? Sorry Luis if I have misunderstood.  :oops:

Not that I want you change anything, but did you see what I did on reactorswiz?... in there (and I know you are trying to do that too) you will see that there is a single object reactor that can handle as many objects as you want, don't know.

And yes, it is weird stuff what it is happening in the code lines, will give it another try need more coffee... :)

I shall take a look at your reactorswiz  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: LE3 on February 15, 2010, 08:27:38 PM
It is getting difficult for me to become familiar again with object reactors, but for what I am seeing it is the way you setup the reactor, for example why there is a foreach to go over the xdata inside of the callback (modified event) instead of placing a dependent object (the selected text of new one) in the callback function defintion, that way when it is verified inside of the callback/event it will be easier to extracted there and also any extra data attached outside.

Do you mean add the new text object as another owner in the ObjectReactor? Sorry Luis if I have misunderstood.  :oops:

Not that I want you change anything, but did you see what I did on reactorswiz?... in there (and I know you are trying to do that too) you will see that there is a single object reactor that can handle as many objects as you want, don't know.

And yes, it is weird stuff what it is happening in the code lines, will give it another try need more coffee... :)

I shall take a look at your reactorswiz  :-)

I think I posted some samples using what it is inside of that, like:
Code: [Select]
;;; function to attach the reactor to the objects
(defun keynote-attach
       (vla_bubble
vla_line
vla_arrowhead)

  ;; make sure the objects are valid
  (if (rwiz-valid-objects
(list vla_bubble vla_line vla_arrowhead))
    (progn

      ;; hacer un solo reactor para cada objeto que forma el comando inteligente

      ;; reactor vla_bubble
      ;; make sure if the reactor is there
      (if (rwiz-added-p rwiz_reactor_bubble_line_arrowhead)

;; add owner and new data to the reactor
(rwiz-owner-data-add
  ;; reactor
  rwiz_reactor_bubble_line_arrowhead
  ;; notifier
  vla_bubble
  ;; dependents
  (list vla_line vla_arrowhead))

;; make the reactor the first time and once
(setq rwiz_reactor_bubble_line_arrowhead
       ;; notify the reactor to the active document
       (vlr-set-notification
;; type of reactor: object
(vlr-object-reactor
   ;; notifier
   (list vla_bubble)
   ;; dependents
   ;; note: we need to saved the notifier object at the beginning
   ;; of the list, this will be needed in order to
   ;; retrieve the dependent objects inside of the callback
   (list (list vla_bubble vla_line vla_arrowhead))
   ;; notes:
   ;; a. in this the bubble will be used as base for the
   ;; copied event
   ;; b. since the block has attributes we are using
   ;; the subobjmodified event
   ;; c. events used modified, subobjmodified, erased and copied
   '
    ((:vlr-modified
      .
      keynote-bubble-modified)
     (:vlr-subobjmodified
      .
      keynote-bubble-subobjmodified)
     (:vlr-erased . keynote-erased)
     (:vlr-copied . keynote-bubble-copied)))
'active-document-only)))

      ;; reactor vla_line
      ;; make sure if the reactor is there
      (if (rwiz-added-p rwiz_reactor_line_bubble_arrowhead)

;; add owner and new data to the reactor
(rwiz-owner-data-add
  ;; reactor
  rwiz_reactor_line_bubble_arrowhead
  ;; notifier
  vla_line
  ;; dependents
  (list vla_bubble vla_arrowhead))

;; make the reactor the first time and once
(setq rwiz_reactor_line_bubble_arrowhead
       ;; notify the reactor to the active document
       (vlr-set-notification
;; type of reactor: object
(vlr-object-reactor
   ;; notifier
   (list vla_line)
   ;; dependents
   ;; note: we need to saved the notifier object at the beginning
   ;; of the list, this will be needed in order to
   ;; retrieve the dependent objects inside of the callback
   (list (list vla_line vla_bubble vla_arrowhead))
   ;; events: modified and erased
   '
    ((:vlr-modified
      .
      keynote-line-modified)
     (:vlr-erased . keynote-erased)))
'active-document-only)))

      ;; reactor vla_arrowhead
      ;; make sure if the reactor is there
      (if (rwiz-added-p rwiz_reactor_arrowhead_bubble_line)

;; add owner and new data to the reactor
(rwiz-owner-data-add
  ;; reactor
  rwiz_reactor_arrowhead_bubble_line
  ;; notifier
  vla_arrowhead
  ;; dependents
  (list vla_bubble vla_line))

;; make the reactor the first time and once
(setq rwiz_reactor_arrowhead_bubble_line
       ;; notify the reactor to the active document
       (vlr-set-notification
;; type of reactor: object
(vlr-object-reactor
   ;; notifier
   (list vla_arrowhead)
   ;; dependents
   ;; note: we need to saved the notifier object at the beginning
   ;; of the list, this will be needed in order to
   ;; retrieve the dependent objects inside of the callback
   (list (list vla_arrowhead vla_bubble vla_line))
   ;; events: modified and erased
   '
    ((:vlr-modified
      .
      keynote-arrowhead-modified)
     (:vlr-erased . keynote-erased)))
'active-document-only)))

      ;; make the new reactor
      (rwiz-attach
;; custom command name
"keynote"
;; dictionary name, key and objects list
;; note: the objects list is saved in order we want it to be read
(list "SYM-REACTORS"
      "CIRCLE-BUBBLE-3"
      (list vla_bubble vla_line vla_arrowhead))))))
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: LE3 on February 15, 2010, 08:38:23 PM
and Lee,

I will kept looking at your code, and will try to solved... what I posted was simple another alternative on the mean time, what you have it is working, it simple needs more eyes and debugging.

I'll post my findings if any or not.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 15, 2010, 08:40:22 PM
Thanks Luis,

I have found reactorswiz in the 'Show Your Stuff' section of the forum - quite a bit of work there, I must say.

Your reactors seem a lot more advanced than mine - using such things as:

Code: [Select]
(vlr-set-notification ... 'active-document-only)

Which I have never even seen...

And a dictionary entry:

Code: [Select]
(rwiz-attach
;; custom command name
"keynote"
;; dictionary name, key and objects list
;; note: the objects list is saved in order we want it to be read
(list "SYM-REACTORS"
      "CIRCLE-BUBBLE-3"
      (list vla_bubble vla_line vla_arrowhead))))))

Which I am not sure what it is used for  :oops:

I do only have two reactors - an object reactor with the curve objects as owners, reacting on the 'modified' callback event; and a command reactor, so that the modified callback function does not operate when an 'undo' command is called.

I didn't want to add the text objects as owners in the object reactor, as, the callback function involves modifying these objects and would hence cause the reactor to enter a recursive loop  :-(

But you seem a bit more advanced in this area after looking at your examples, so I shall study your code..

Many thanks,

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 15, 2010, 08:42:00 PM
and Lee,

I will kept looking at your code, and will try to solved... what I posted was simple another alternative on the mean time, what you have it is working, it simple needs more eyes and debugging.

I'll post my findings if any or not.

Thanks Luis, I really appreciate you donating your time to this  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: CAB on February 15, 2010, 11:28:30 PM
I haven't seen the problem yet. I tried a few test this evening & must be doing something wrong.
What process exactly is creating the problem?

See you in the morning, my morning   8-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 16, 2010, 11:19:38 AM
I haven't seen the problem yet. I tried a few test this evening & must be doing something wrong.
What process exactly is creating the problem?

See you in the morning, my morning   8-)

Sorry for late reply - our time zones aren't good for this sort of thing  8-)

The problem occurs if you do the following:


You will notice that Object A gets used in place of Object B, when re-aligning.  :-(

But there is another issue I have just found with with a (read nil), as Luis quite rightly pointed out earlier.  :oops:

Will get back to you soon,

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: CAB on February 16, 2010, 11:35:59 AM
 When you say re-align
    * Align Object A with Curve A
    * Align Object B with Curve A
    * Re-Align Object B with Curve A

You mean dtremove & then dtcurve to re attach the text?

I'm not seeing the error here in ACAD 2000
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 16, 2010, 11:39:06 AM
When you say re-align
    * Align Object A with Curve A
    * Align Object B with Curve A
    * Re-Align Object B with Curve A

You mean dtremove & then dtcurve to re attach the text?

I'm not seeing the error here in ACAD 2000


Sorry, Re-Align without using DtRemove - i.e. When the prompt appears for text, you select the text that is already aligned, (apologies for not explaining that).

The program should remove the associated xData from the object when text is selected that is already aligned, so that the text may be 're-aligned' to another/ or the same object, but, in my case, the text object handles seem to switch at this point.

Luis has provided me with some modified code to try, so I shall see what he has come up with when I get a spare minute.  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: CAB on February 16, 2010, 02:22:40 PM
The switch happens here:
Code: [Select]
 (defun putxdat (Obj App Data / ent xtype xval)

    (setq xtype
      (vlax-make-variant
        (vlax-safearray-fill
          (vlax-make-safearray
            vlax-vbInteger '(0 . 1)) '(1001 1000))))

    (setq xval
      (vlax-make-variant
        (vlax-safearray-fill
          (vlax-make-safearray
            vlax-vbVariant '(0 . 1)) (list App Data))))

    (vla-setXData Obj xtype xval)  ;  [color=red]<=====<<<  switches every other time[/color]
    )
   
    Haven't figured out why yet but here is a work around fix.
Code: [Select]
              (foreach obj (vlr-owners *DCurve$Align$Reactor*)

             (if (not (vlax-erased-p obj))
               (progn

                 (vla-GetXData obj app 'typ 'val)

                 (if (and typ val)
                   (progn
                     [color=red](setq tmp tObj)   ;   <-----------------------<<<  CAB added[/color]
                     (setq xDat (vl-remove-if-not
                                  (function
                                    (lambda (lst)
                                      (entget (handent (car lst)))))
                                  
                                  (read
                                    (vlax-variant-value
                                      (cadr
                                        (vlax-safearray->list val))))))
                    
                     (if (vl-position Hnd (mapcar (function car) xDat))
                       (progn
                         (putxDat obj app
                           (vl-prin1-to-string
                             (vl-remove-if
                               (function
                                 (lambda (x) (eq Hnd (car x)))) xDat)))))
    [color=red](if (not (equal tmp tobj)) (setq tobj tmp))  ;   <-----------------------<<<  CAB added[/color]
    )
  ))

               (vlr-owner-remove *DCurve$Align$Reactor* obj)))))
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: LE3 on February 16, 2010, 02:54:04 PM
It happens because, inside of the modified callback it does modifications in arbitrary way to all the available texts, that were attached to the lines, and that portion of code what it does is trigger the modified event to all the notifiers (lines).

For example, if you place a debug message print out on the modified callbak for the notifier, you will noticed that it will show that there is a modification, when in reality is not required but was trigger.

That's why in my case I offer a way to simple do not run any reactor while doing the attachment of existing or new text's to the lines.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: CAB on February 16, 2010, 03:11:14 PM
OK, I think I found it.
You did not localize tObj here.
Code: [Select]
(defun DTCurveUpd (Obj Reac Args
  /
  *error* ObjxDat typ val dist perp mirr para a#dif [color=red]tObj[/color])
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 16, 2010, 03:15:20 PM
Ahhh!  I understand!

So when I modify the curve object by setting the xData for it, the tObj gets re-assigned.

So I suppose the best thing to do would be to stop the reactor from reacting during that part of the code (as you suggest Luis), or as you say CAB, use a temporary variable.

Thanks guys - it would have taken me ages to figure that out! Just shows you what a new pair of eyes does...

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: LE3 on February 16, 2010, 03:23:34 PM
OK, I think I found it.
You did not localize tObj here.
Code: [Select]
(defun DTCurveUpd (Obj Reac Args
  /
  *error* ObjxDat typ val dist perp mirr para a#dif [color=red]tObj[/color])

Yes, but the problem behind scenes is that every time the user does a selection of an existing attached text, it will trigger the reactor, and if they have a lot of text objects attached, guess that Lee, don't want that.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 16, 2010, 03:25:40 PM
OK, I think I found it.
You did not localize tObj here.
Code: [Select]
(defun DTCurveUpd (Obj Reac Args
  /
  *error* ObjxDat typ val dist perp mirr para a#dif [color=red]tObj[/color])

Yes, but the problem behind scenes is that every time the user does a selection of an existing attached text, it will trigger the reactor, and if they have a lot of text objects attached, guess that Lee, don't want that.

True, although a dummy variable is an option it would be best to stop the reactor from triggering - as it is pointless if it does at this point.  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: CAB on February 16, 2010, 03:27:20 PM
Lee,
Remove my temporary code and add the localized tObj shown in RED.
Yours is missing. I added that.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: CAB on February 16, 2010, 03:30:44 PM
Yes, but the problem behind scenes is that every time the user does a selection of an existing attached text, it will trigger the reactor, and if they have a lot of text objects attached, guess that Lee, don't want that.

I don't see that happening.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: CAB on February 16, 2010, 03:33:12 PM
The problem as I see it is that this code
Code: [Select]
(vla-setXData Obj xtype xval)  triggers the reactor & changes tObj which is not a local variable to that subroutine.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: LE3 on February 16, 2010, 03:35:55 PM
Yes, but the problem behind scenes is that every time the user does a selection of an existing attached text, it will trigger the reactor, and if they have a lot of text objects attached, guess that Lee, don't want that.

I don't see that happening.

Sorry, was talking about Lee original code, later today will tried with your corrections too.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 16, 2010, 03:49:12 PM
Lee,
Remove my temporary code and add the localized tObj shown in RED.
Yours is missing. I added that.


Will do Alan, but this would wipe the value of tObj when the reactor is triggered would it not?

I would rather just stop the reactor from firing at all if that is even possible  :|
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Kerry on February 16, 2010, 03:53:15 PM

Will do Alan, but this would wipe the value of tObj when the reactor is triggered would it not?

I would rather just stop the reactor from firing at all if that is even possible  :|

haven't viewed the whole thread, but
the only way to stop a reactor foring is to remove it.
you can conditionally reduce the actions the event trap performs, but that is a different trip.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: LE3 on February 16, 2010, 03:54:46 PM
Lee,
Remove my temporary code and add the localized tObj shown in RED.
Yours is missing. I added that.


Will do Alan, but this would wipe the value of tObj when the reactor is triggered would it not?

I would rather just stop the reactor from firing at all if that is even possible  :|

AFAIK, vlr-owners - call with trigger the reactor - and that's what was happening - so it goes to whatever number of items connected to the notifier line to be updated - now without testing with CAB changes, the idea is to avoid the call or use of the reactor only when the line it is modified no?

I am out of a way to test lisp right now....
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 16, 2010, 03:55:24 PM

Will do Alan, but this would wipe the value of tObj when the reactor is triggered would it not?

I would rather just stop the reactor from firing at all if that is even possible  :|

haven't viewed the whole thread, but
the only way to stop a reactor foring is to remove it.
you can conditionally reduce the actions the event trap performs, but that is a different trip.

Ok thanks for your advice Kerry - appreciated.  :-)

How about if I set a flag when the user is in the main function, and test for the flag in the Callback function - this seems like the easiest way to go  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: LE3 on February 16, 2010, 03:56:42 PM
Lee,

What happen with the code, sent your way... did not work?
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 16, 2010, 03:57:24 PM
Lee,

What happen with the code, sent your way... did not work?

Sorry Luis, haven't got around to looking at it yet - just came back from a badminton session  8-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: CAB on February 16, 2010, 04:01:00 PM
Lee,
Remove my temporary code and add the localized tObj shown in RED.
Yours is missing. I added that.


Will do Alan, but this would wipe the value of tObj when the reactor is triggered would it not?

I would rather just stop the reactor from firing at all if that is even possible  :|

No unless I am missing something.
The routine seems to perform as expected.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Kerry on February 16, 2010, 04:01:44 PM
< .. >
How about if I set a flag when the user is in the main function, and test for the flag in the Callback function - this seems like the easiest way to go  :-)

That works for me in other situations
for instance ;
when trapping the command ended
conditionally if the command was MTEXT
if a globalVariable has a value, restore the current layer to the globalVariable value and nullify the variable.


Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 16, 2010, 04:02:18 PM
Luis,

What a superb idea - it works great!  8-)

I shall definitely use that idea in the new version, many thanks  ;-)

Luis' idea:

At start of routine:

Code: [Select]
 (if (vlr-added-p *DCurve$Align$Reactor*) (vlr-remove *DCurve$Align$Reactor*))

At end of routine:

Code: [Select]
 (if (not (vlr-added-p *DCurve$Align$Reactor*)) (vlr-add *DCurve$Align$Reactor*))

Simple and effective.

Thanks.

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: CAB on February 16, 2010, 04:07:09 PM
You still should localize tObj. IMO
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 16, 2010, 04:08:02 PM
You still should localize tObj. IMO


Of course  :-)  That should have been localised anyway - a mistake on my part  :oops:
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: CAB on February 16, 2010, 04:23:57 PM
So the only time you want the reactor turned off is when you are updating the xData.

The On / Off switch should be in the putxdata routine

Code: [Select]
Flag on or (reactor off)
(vla-setXData Obj xtype xval)
Flag Off or (reactor On)

If you add it the DTCurve routine then you will need to deal with it in the error trap as well.


I prefer Kerry's flag suggestion & use some skip code in the reactor to do nothing.
my 2 cents. 8-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 16, 2010, 04:27:50 PM
So the only time you want the reactor turned off is when you are updating the xData.

The On / Off switch should be in the putxdata routine

Code: [Select]
Flag on or (reactor off)
(vla-setXData Obj xtype xval)
Flag Off or (reactor On)

If you add it the DTCurve routine then you will need to deal with it in the error trap as well.


I prefer Kerry's flag suggestion & use some skip code in the reactor to do nothing.
my 2 cents. 8-)

Well, to be honest, I was rather it was turned off the whole time that the routine was running, so that it cannot interfere at all when the user is positioning text.

I'll think I'll use Luis' suggestion, and keep the flag suggestion in mind, in case there are any comebacks,  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Kerry on February 16, 2010, 04:36:08 PM

< .. >    & use some skip code in the reactor to do nothing.
my 2 cents. 8-)

good expression !
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: LE3 on February 16, 2010, 04:44:56 PM
Yes, but the problem behind scenes is that every time the user does a selection of an existing attached text, it will trigger the reactor, and if they have a lot of text objects attached, guess that Lee, don't want that.

I don't see that happening.

I was just able to run the code with these corrections, and to see it just add this:
Code: [Select]
(defun DTCurveUpd (Obj Reac Args / *error* ObjxDat typ val dist perp mirr para a#dif tObj)

  (defun *error* (msg)
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
        (princ (strcat "\n** Error: " msg " **")))
    (princ))

  ;; LE - debug - this cannot be called when an user select a text
  (princ "\nNotifier: ") (princ obj) (princ)

  (cond (  (and *Reactor$Command$Call* (or (wcmatch *Reactor$Command$Call* "*UNDO")
               (eq "U" *Reactor$Command$Call*))) )       

        (t (if (vlax-erased-p obj)
             (vlr-owner-remove Reac Obj)

             (progn

               (or doc (setq doc (vla-get-ActiveDocument
                                   (vlax-get-acad-object))))
               
               (vla-getXdata obj app 'typ 'val)

               (setq ObjxDat (vl-remove-if-not
                               (function
                                 (lambda (lst)
                                   (entget (handent (car lst)))))
                               
                               (read
                                 (vlax-variant-value
                                   (cadr
                                     (vlax-safearray->list val))))))

               ;(putxDat Obj app (vl-prin1-to-string ObjxDat))

               (foreach lst  ObjxDat

                 (setq tObj  (vlax-ename->vla-object (handent (car lst))))

                 (mapcar (function set) '(dist perp mirr para a#dif) (cddr lst))

                 (if (eq "AcDbText" (vla-get-ObjectName tObj))
                   (vla-put-Alignment tObj acAlignmentMiddleCenter)
                   (vla-put-AttachmentPoint tobj acAttachmentPointMiddleCenter))

                 (setq pt
                       
                   (cond (  (vlax-curve-getPointatParam Obj para))

                         (  (vlax-curve-getClosestPointto Obj
                              (vlax-get tObj
                                (if (eq "AcDbText" (vla-get-ObjectName tObj))
                                  'TextAlignmentPoint
                                  'InsertionPoint))))))

                 (setq para  (vlax-curve-getParamatPoint Obj pt)

                       deriv (+ (angle '(0 0 0)
                                       (vlax-curve-getFirstDeriv Obj para)) a#dif))

;;;                 (setq deriv (+ deriv (if (< (distance tpt (polar pt deriv 1))
;;;                                             (distance tpt (polar pt (+ deriv pi) 1))) 0 pi)))

                 (setq cAng deriv lAng (rem (+ perp cAng) (* 2. pi)))

                 (if (equal lAng (/ pi 2.) 0.001)
                   (setq lAng (/ pi 2.)))

                 (if (equal lAng (/ (* 3 pi) 2.) 0.001)
                   (setq lAng (/ (* 3 pi) 2.)))

                 (and (minusp lAng) (setq lAng (+ lAng (* 2 pi))))
                 
                 (cond (  (and (> lAng (/ pi 2)) (<= lAng pi))
                          (setq lAng (- lAng pi)))

                       (  (and (> lAng pi) (<= lAng (/ (* 3 pi) 2)))
                          (setq lAng (+ lAng pi))))

                 (  (if (eq "AcDbText" (vla-get-ObjectName tObj))
                      vla-put-TextAlignmentPoint
                      vla-put-InsertionPoint)

                      tObj (vlax-3D-point (polar pt cAng (* (vla-get-Height tObj) dist))))

                 (vla-put-Rotation tObj (+ mirr lAng)))))))
     
  (princ))

So, the code will always be triggering the reactor - and update the text all the time:
Quote
Command: DTCURVE

Type or Select Text <TEXT5> :
Select Curve:
  • or [-] for
  • ffset, [P]erpendicularity Toggle
[M]irror Text, tyle Settings, ackground Mask
Notifier: #<VLA-OBJECT IAcadLine 0b18aa84>

Also, Lee we need to add this too - and make sure the command reactor is valid:
Code: [Select]
  (cond (  (and *Reactor$Command$Call* (or (wcmatch *Reactor$Command$Call* "*UNDO")
               (eq "U" *Reactor$Command$Call*))) )       
 
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: CAB on February 16, 2010, 04:46:13 PM
Well, to be honest, I was rather it was turned off the whole time that the routine was running, so that it cannot interfere at all when the user is positioning text.

I'll think I'll use Luis' suggestion, and keep the flag suggestion in mind, in case there are any comebacks,  :-)
I hope your always honest.  8-)

That method is fine. Note that modifying the text will never fire the reactor so nothing except setting the xdata in DTCurve routine will fire the reactor.
Keep in mind that today is the first time I explored the code so you may have some tricks in there that I didn't see. :-)

Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 16, 2010, 04:49:45 PM
Well, to be honest, I was rather it was turned off the whole time that the routine was running, so that it cannot interfere at all when the user is positioning text.

I'll think I'll use Luis' suggestion, and keep the flag suggestion in mind, in case there are any comebacks,  :-)
I hope your always honest.  8-)

That method is fine. Note that modifying the text will never fire the reactor so nothing except setting the xdata in DTCurve routine will fire the reactor.
Keep in mind that today is the first time I explored the code so you may have some tricks in there that I didn't see. :-)

Of course, and I value your suggestions :-)

The curve is also modified when the user aligns the text, so I just feel it is cleaner to 'switch off the reactor' for a bit.  :-)

Thanks for your time on this Alan, it is appreciated.

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 16, 2010, 04:54:03 PM
Also, Lee we need to add this too - and make sure the command reactor is valid:
Code: [Select]
  (cond (  (and *Reactor$Command$Call* (or (wcmatch *Reactor$Command$Call* "*UNDO")
               (eq "U" *Reactor$Command$Call*))) )       
 

Thanks Luis - good point.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: CAB on February 16, 2010, 04:54:27 PM
Thanks Kerry. 8-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on February 16, 2010, 05:49:07 PM
I have updated the first post to Version 2.9.

This should hopefully resolve most (if not all) of the issues that we have discussed.

My sincere thanks go to all who have contributed along the way; - if any more bugs are found, let me know!  :-)

Thanks,

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: jitupnair on May 09, 2010, 03:13:31 AM
Lee,
Its really wonderful. Great program.

Jithesh. P. Nair

I have updated the first post to Version 2.9.

This should hopefully resolve most (if not all) of the issues that we have discussed.

My sincere thanks go to all who have contributed along the way; - if any more bugs are found, let me know!  :-)

Thanks,

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: jitupnair on May 09, 2010, 05:04:09 AM
Lee,
While aligning one text to a line using this progam, I pressed P to make the text perpendicular but before fixing the possition of text,
I changed my mind and pressed P again to make the text parallel to the Line and fixed the possition. Till here it worked fine. But when I moved the line the text become perpendicular to the line. Is there any problem with program or I did something wrong?.

Thanks & regards

Jithesh P. Nair

I have updated the first post to Version 2.9.

This should hopefully resolve most (if not all) of the issues that we have discussed.

My sincere thanks go to all who have contributed along the way; - if any more bugs are found, let me know!  :-)

Thanks,

Lee
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on May 09, 2010, 07:59:55 AM
I cannot seem to reproduce your error, does anyone else receive the same problem?
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: jitupnair on May 13, 2010, 06:18:40 AM
In my home PC its working well. But in office PC its giving the above said problem. I think Its a problem in my  AutoCAD or PC (in office).
I cannot seem to reproduce your error, does anyone else receive the same problem?
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on May 13, 2010, 10:59:15 AM
I cannot work out why that would happen, but let me know if you find anything else, or indeed if anyone else is suffering with this bug  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Willie on May 17, 2010, 09:35:35 PM
Just a suggestion for a future version.

How about a reset option to position the text back to the initial position?  Sometimes after you have used the "+" and "-" and the text position is not to your liking you can reset the position and start the "+" "-" etc. process again.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on May 18, 2010, 05:05:54 AM
Maybe I've misunderstood the request, but you could press 'O' to specify an Offset manually.  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Willie on May 18, 2010, 05:09:20 AM
Maybe I've misunderstood the request, but you could press 'O' to specify an Offset manually.  :-)

That will work.

Thanks
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on May 18, 2010, 05:22:19 AM
Excellent, let me know if you have any problems with it :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: ljh19991220 on June 14, 2010, 01:01:40 AM
thanks.  :-)  VERY GOOD
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on June 14, 2010, 03:20:15 AM
thanks.  :-)  VERY GOOD

You're very welcome - glad you like it  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: fabcad on September 06, 2010, 09:04:13 AM
Hello Lee,

Very interresting function because i manipulate a lot of texts and mtexts on map.
For your texts functions, should be an option to type zero to align the text-mtext on the polyline reference after the use of + or +.

Because we write our texts roads on polylines roads.

Thanks for your best work,

Fabrice

Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on September 06, 2010, 02:40:34 PM
Type 'O' during alignment.
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: fabcad on September 06, 2010, 03:02:11 PM
Sorry I had not seen the option Offset Thanks for your reply.

Fabrice
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on September 06, 2010, 03:04:53 PM
Sorry I had not seen the option Offset Thanks for your reply.

Fabrice


You're welcome Fabrice, I'm glad you like the program  :-)
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Dashmonkey on October 01, 2010, 04:52:24 PM
Lee, you rock my world!!!
Title: Re: Dynamic Align Text to Curve { with Reactors }
Post by: Lee Mac on October 01, 2010, 05:00:19 PM
Lee, you rock my world!!!

Hahaha Thanks Dashmonkey  :lol: