AutoLISP - Window Reactor - Need example . . .

AutoLISP - Window Reactor - Need example . . .

bob_basques
Enthusiast Enthusiast
1,300 Views
11 Replies
Message 1 of 12

AutoLISP - Window Reactor - Need example . . .

bob_basques
Enthusiast
Enthusiast

All,

 

I'm trying to get a Window reactor going, must be doing something wrong, anyone have an example they could share?

 

Here is what I have so far:

 

(vl-load-com)

(defun DoThisForWindowStateChange (Caller CmdSet)
  (alert "The window changed state!")
  (princ)
)

(setq MyWindowReactor1
       (vlr-window-reactor nil '(
                  (:vlr-mainFrameMovedOrResized . DoThisForWindowStateChange)
                  )
     )
      )

(defun Clear_My_Reactors ()
  (if (and MyWindowReactor1 (vlr-added-p MyWindowReactor1))
    (vlr-remove MyWindowReactor1)
    )
  )

(defun Clear_All_Reactors ( / TMP)
  (vlr-remove-all :vlr-window-reactor)
  )

 

Thanks

 

bobb

 

 

0 Likes
Accepted solutions (1)
1,301 Views
11 Replies
Replies (11)
Message 2 of 12

hmsilva
Mentor
Mentor

Hi bobb,

 

untested

 

(defun DoThisForWindowStateChange (Caller CmdSet)
  (if (cadr CmdSet)
       (alert "The window has been moved!")
       (alert "The window has been resized!")
    )
)

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 3 of 12

dbroad
Mentor
Mentor
Accepted solution

Bob,

 

Your reactor works for me.  In order to get feedback, you need to have the autocad window not maximized and then move the window.  If you want to track all reactions, I would suggest starting the testing process by using the vlr-trace-reaction callback.  Then you can see the results in the trace window.

(vlr-window-reactor nil '((:vlr-docFrameMovedOrResized . vlr-trace-reaction)
		      (:vlr-mainFrameMovedOrResized . vlr-trace-reaction)))

 

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 4 of 12

bob_basques
Enthusiast
Enthusiast
Hi hmsilva,
This may have worked, but now I'm not seeming to be able to remove reactors (some previous test versions are still reacting) so I'm not sure if this new code is even being interpreted yet . . .
bobb


@hmsilva wrote:

Hi bobb,

 

untested

 

(defun DoThisForWindowStateChange (Caller CmdSet)
  (if (cadr CmdSet)
       (alert "The window has been moved!")
       (alert "The window has been resized!")
    )
)

 

Hope this helps,
Henrique


0 Likes
Message 5 of 12

bob_basques
Enthusiast
Enthusiast

dbraod,

 

Ok, Dopey me.  That's not even what I wanted the reactor for, it does actually work as defined originally.  After I read your bit about maximized windows, etc.c.c.,  I resized the window, and it all worked fine.

 

What I really want to do though, is track the scale of view inside of the map window, Zoom and pan. . . . I want to know whaen the user does a map navigation step, zoom/pan, now which reactor is that . . .?

 

Thanks everyone . . . .

 

bobb

 

 


@Anonymous wrote:

Bob,

 

Your reactor works for me.  In order to get feedback, you need to have the autocad window not maximized and then move the window.  If you want to track all reactions, I would suggest starting the testing process by using the vlr-trace-reaction callback.  Then you can see the results in the trace window.

(vlr-window-reactor nil '((:vlr-docFrameMovedOrResized . vlr-trace-reaction)
		      (:vlr-mainFrameMovedOrResized . vlr-trace-reaction)))

 


 

0 Likes
Message 6 of 12

bob_basques
Enthusiast
Enthusiast

Ok, I guess I need to do the same only with some system VARS,

specifically:


SCREENSIZE                    (read only)

VIEWSIZE                           (read only)

 

 

to startwith, so how does one selectively look at a sysvar with :vlr-sysvar-reactor . . . some sort of if then I would guess . . .

 

bobb

 

 

0 Likes
Message 7 of 12

dbroad
Mentor
Mentor

So you are using AutoCAD Map?  I know nothing about any Map specific viewing commands.  What is your goal?  Why are you tracking the scale, ie."What I really want to do though, is track the scale of view inside of the map window, Zoom and pan. . . . I want to know whaen the user does a map navigation step, zoom/pan, now which reactor is that . . .?

 

What is a map window?  Is it a viewport? What is the point of tracking view changes?  Perhaps, I can help more if I understand the rationale.  Reactors can get cumbersome and shouldn't be continuously running without good reason.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 8 of 12

bob_basques
Enthusiast
Enthusiast

@Anonymous wrote:

So you are using AutoCAD Map?

 

 

        Yes.  But there's nothing specific related to Map that I'm trying to use.

 

 

I know nothing about any Map specific viewing commands.  What is your goal?  Why are you tracking the scale, ie."What I really want to do though, is track the scale of view inside of the map window, Zoom and pan. . . . I want to know whaen the user does a map navigation step, zoom/pan, now which reactor is that . . .?

 

 

        Model Space.  I want to know when the user changes it, zoom in/out, pans, etc. and run a routine (That I've had around for literally decades) that does some automated importing of Aerial images and other DWG inserts automatically based on location.  Yes I know this is what FDO is supposed to do, but my importers work for all AutoCAD versions (that have a LISP Interpreter.)  My import tools also do a bunch of autodiscovery of services within our network for importing into the AutoCAD session.

 

 

 

What is a map window?  Is it a viewport?

 

 

        Yes, or model space actually.

 

 

What is the point of tracking view changes?  Perhaps, I can help more if I understand the rationale.  Reactors can get cumbersome and shouldn't be continuously running without good reason.

 

 

         I've tried getting reactors to work for this a number of times over the years, but I've always ended up giving up on it.  I basically want to be able to mimic a slippy map capabilitiy inside of the AutoCAD session, with some number of layers being imported automatically for the defined view.  Think super duper Google Maps.  I have over 255+ layers in my import utility right now as an example.  Using FDO to manage that number of resources has not been a effecient use of effort in the past, and it only works in MAP/CIVIL, and I need to be able to support other City vendors as well that might just have regular AutoCAD.  Your point about continuously running is not falling on deaf ears either, I understand this as well, and always intended on setting up a on/off button for this autoimport capability.  There is also the issue of not cleaning up the older imports automatically, as they can come in at different resolutions while the user is zooming/panning, which I'll need to address after getting the "model view" tracking capability functional.  We use the importer currently as a reference tool for design as well as in our mapping section for mapbook generation tasks.

 

        I'm thinking about how I might package my importer for Open Sourcing, I've thought about if for a while (years) actually, and we've recently decided to reconfigure the importer to use WMS services as a first step in that direction, but I'm starting to ramble here, anyway, I want to be able to track the 2D location, along with scale of view in Model Space.

 

I would appreciate any help you can give to the project.  Thank you very much for your offer.

 

bobb

 

 


 

0 Likes
Message 9 of 12

dbroad
Mentor
Mentor

I doubt that you will succeed in achieving what you want by using lisp.  It will probably be necessary to switch to .NET programming as that has much deeper hooks into the program than lisp.  If you want to proceed, you might use the vlr-editor-reactor or vlr-sysvar-reactor.  The main problem is that mouse panning does not call a command and does not generate changes in sysvars other than  "VIEWBACKSTATUS" and "DYNMODE".  It would be necessary for you to query the value of viewctr and viewsize within a callback triggered by whatever event would be frequently related to view changes and to compare them to previously saved viewctr and viewsize settings.  Here is a sample which should suggest failure to be able to track fluidly.  A vlr-command-reactor tracking a vlr-commandended event might be a good place to get a quiescent state to track these variables and to make adjustments but it will not be problem free.

 

(vlr-remove-all)
(setq svr (vlr-sysvar-reactor
	    (list (cons "VIEWCTR" (getvar "viewctr"))
		  (cons "VIEWSIZE" (getvar "viewsize"))
	    )
	    '((:vlr-sysvarchanged . svcbexample)

	     )
	  )
)
(defun svcbexample (r l / data ovc ovs nvc nvs)
  (setq data (vlr-data r))
  (setq	ovc (cdr (assoc "VIEWCTR" data))
	ovs (cdr (assoc "VIEWSIZE" data))
	nvc (getvar "viewctr")
	nvs (getvar "viewsize")
  )
  (if (not(equal ovc nvc))
    (progn
      (alert (strcat "\nViewctr has changed.  It was: "
		     (vl-princ-to-string ovc)
		     " It is now: "
		     (vl-princ-to-string nvc)
	     )
      )
      (setq
	data (subst (cons "VIEWCTR" nvc) (assoc "VIEWCTR" data) data)
      )
    )
  )
  (if (not(equal ovs nvs))
    (progn
      (alert (strcat "\Viewsize has changed. It was "
		     (rtos ovs)
		     ". It is now "
		     (rtos nvs)
	     )
      )
      (setq data
	     (subst (cons "VIEWSIZE" nvs ) (assoc "VIEWSIZE" data) data)
      )
    )
  )
  (vlr-data-set r data)
)

 

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 10 of 12

bob_basques
Enthusiast
Enthusiast

Whoa,

 

That does operate weirdly, doesn't it.  There's no way to perdict when the values are going to be passed back, although, I wonder about maybe trying to write the values to a file or store as a variable instead of using alerts . . .

 

bobb

 

 

0 Likes
Message 11 of 12

dbroad
Mentor
Mentor

The issue is that you will not necessarily get the trigger you need when you need it.  LISP is not the tool you need if you want live updates concerning basic screen center and size.  I suggest asking on the .NET newsgroup to see if it is either possible or advisable.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 12 of 12

bob_basques
Enthusiast
Enthusiast

Well, I think it's possible, FDO can do it.  I'm just not sure about how much effort it will take to accomplish, if the hooks are even available.

 

I also fell comfortable with LISP, not so much with .NET.  But I do have a Staffer that has moved in this direction the last couple of years, so . . . I have a way forward.

 

I'm still putzing with it a bit, another option I considered for  while was to somehow run a LISP routine in the background with a timer, that kept updating the values from the system, and then those values were read by the view tracker as needed.  Still not out of my mind completely yet as a deadend . . .

 

bobb

 

 

0 Likes