Author Topic: Dynamic Align Text to Curve { with Reactors }  (Read 57613 times)

0 Members and 1 Guest are viewing this topic.

LE3

  • Guest
Re: Dynamic Align Text to Curve { with Reactors }
« Reply #120 on: February 16, 2010, 03:56:42 PM »
Lee,

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

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dynamic Align Text to Curve { with Reactors }
« Reply #121 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-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dynamic Align Text to Curve { with Reactors }
« Reply #122 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.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Dynamic Align Text to Curve { with Reactors }
« Reply #123 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.


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dynamic Align Text to Curve { with Reactors }
« Reply #124 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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dynamic Align Text to Curve { with Reactors }
« Reply #125 on: February 16, 2010, 04:07:09 PM »
You still should localize tObj. IMO
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dynamic Align Text to Curve { with Reactors }
« Reply #126 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:

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dynamic Align Text to Curve { with Reactors }
« Reply #127 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-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dynamic Align Text to Curve { with Reactors }
« Reply #128 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,  :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Dynamic Align Text to Curve { with Reactors }
« Reply #129 on: February 16, 2010, 04:36:08 PM »

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

good expression !
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

LE3

  • Guest
Re: Dynamic Align Text to Curve { with Reactors }
« Reply #130 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*))) )       
 

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dynamic Align Text to Curve { with Reactors }
« Reply #131 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. :-)

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dynamic Align Text to Curve { with Reactors }
« Reply #132 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

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Dynamic Align Text to Curve { with Reactors }
« Reply #133 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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Dynamic Align Text to Curve { with Reactors }
« Reply #134 on: February 16, 2010, 04:54:27 PM »
Thanks Kerry. 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.