Author Topic: Very strange problem  (Read 4293 times)

0 Members and 1 Guest are viewing this topic.

andy_lee

  • Newt
  • Posts: 147
Very strange problem
« on: May 20, 2014, 05:08:27 AM »
Code: [Select]
(defun GetMyDocumentsDir()
  (vlax-invoke-method
    (vlax-get-property
      (vlax-create-object "wscript.shell")
      'SpecialFolders) 'Item  "MyDocuments")
)
;;Call:(GetMyDocumentsDir)
;;(BF:mkslid sldname 400 300)
;;; (SetScreenSize 400 300)
(defun SetScreenSize (Width height / doc oldsize doc w1 h1 dw dh)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (setq oldsize (getvar "SCREENSIZE"))
  (setq W1 (vla-get-width doc))
  (setq H1 (vla-get-Height doc))
  (setq dw (- w1 (car oldsize)))
  (setq dh (- h1 (cadr oldsize)))
  (vla-put-width doc (+ dw width))
  (vla-put-height doc (+ dh height))
)

(defun c:test()
(SetScreenSize  400 300)
(command "zoom" "e")
 (princ)
)

My idea is
1.Set ScreenSize to 400*300
2."zoom" "e"

But ,when I use command "test"


Oh , why ? Need to run“test” twice
Normal should be like this


andy.
Best regards.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Very strange problem
« Reply #1 on: May 20, 2014, 06:32:54 AM »
It could be that the window is still updating before running zoom extents. I.e. the extents is calculated on the previous sized window, and the new size only occurs after the zoom does.

You need to remember that you're inside Windows. A change to a GUI item's properties is handled as an event call. Simply because you sent the event doesn't mean it's going to happen immediately. If you resized the window in C#/VB/C++ you'd usually need to force the event to complete using something like Update / Refresh before you can rely on the resize to have completed.

Since you're doing this through ActiveX you could try to invoke the application's Update method: http://entercad.ru/acadauto.en/index.html?page=idh_update.htm
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

andy_lee

  • Newt
  • Posts: 147
Re: Very strange problem
« Reply #2 on: May 20, 2014, 07:05:36 AM »
It could be that the window is still updating before running zoom extents. I.e. the extents is calculated on the previous sized window, and the new size only occurs after the zoom does.

You need to remember that you're inside Windows. A change to a GUI item's properties is handled as an event call. Simply because you sent the event doesn't mean it's going to happen immediately. If you resized the window in C#/VB/C++ you'd usually need to force the event to complete using something like Update / Refresh before you can rely on the resize to have completed.

Since you're doing this through ActiveX you could try to invoke the application's Update method: http://entercad.ru/acadauto.en/index.html?page=idh_update.htm

Maybe you are right , The link is about VB ? I can't understand.
andy.
Best regards.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Very strange problem
« Reply #3 on: May 20, 2014, 08:02:00 AM »
The link is about VB ? I can't understand.
The link is pointing to the old VBA-ActiveX help documentation (which isn't available in ACad anymore).

All those vla/vlax functions are using the ActiveX objects - which are those in that link. You're already using some of those inside your SetScreenSize function - the Width and Height properties of the Document object.

The Application object is what you get from the vlax-get-acad-object. And then to invoke the Update method on it - one of 3 ways:
Code - Auto/Visual Lisp: [Select]
  1. (setq acad (vlax-get-acad-object)) ;You need the object so you can invoke its method
  2.  
  3. (vla-Update acad) ;Option 1 - shorthand works on all ACad ActiveX objects
  4. (vlax-invoke-method acad 'Update) ;Option 2 - The full fledged VisualLisp method
  5. (vlax-invoke acad 'Update) ;Option 3 - the old VitalLisp method, sometimes the most useful
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

andy_lee

  • Newt
  • Posts: 147
Re: Very strange problem
« Reply #4 on: May 20, 2014, 08:45:56 AM »
The link is about VB ? I can't understand.
The link is pointing to the old VBA-ActiveX help documentation (which isn't available in ACad anymore).

All those vla/vlax functions are using the ActiveX objects - which are those in that link. You're already using some of those inside your SetScreenSize function - the Width and Height properties of the Document object.

The Application object is what you get from the vlax-get-acad-object. And then to invoke the Update method on it - one of 3 ways:
Code - Auto/Visual Lisp: [Select]
  1. (setq acad (vlax-get-acad-object)) ;You need the object so you can invoke its method
  2.  
  3. (vla-Update acad) ;Option 1 - shorthand works on all ACad ActiveX objects
  4. (vlax-invoke-method acad 'Update) ;Option 2 - The full fledged VisualLisp method
  5. (vlax-invoke acad 'Update) ;Option 3 - the old VitalLisp method, sometimes the most useful

This ?
Code: [Select]
(vl-load-com)
(defun GetMyDocumentsDir()
  (vlax-invoke-method
    (vlax-get-property
      (vlax-create-object "wscript.shell")
      'SpecialFolders) 'Item  "MyDocuments")
)
;;Call:(GetMyDocumentsDir)
;;(BF:mkslid sldname 400 300)
;;; (SetScreenSize 400 300)
(defun SetScreenSize (Width height / doc oldsize doc w1 h1 dw dh)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (setq oldsize (getvar "SCREENSIZE"))
  (setq W1 (vla-get-width doc))
  (setq H1 (vla-get-Height doc))
  (setq dw (- w1 (car oldsize)))
  (setq dh (- h1 (cadr oldsize)))
  (vla-put-width doc (+ dw width))
  (vla-put-height doc (+ dh height))
  (vla-Update(vlax-get-acad-object))
  (vla-zoomextents (vlax-get-acad-object))
)

(defun c:test()
(SetScreenSize  400 300)   
 (princ)
)

The problem not solve.
andy.
Best regards.

andy_lee

  • Newt
  • Posts: 147
Re: Very strange problem
« Reply #5 on: May 21, 2014, 06:45:58 AM »
There is no way to solve ?
andy.
Best regards.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Very strange problem
« Reply #6 on: May 21, 2014, 07:40:46 AM »
There is no way to solve ?
Seems not. At least not the way you're thinking to do it. It doesn't seem as if the Update actually forces the resize to complete immediately. Unfortunately there's nothing else (I can think of) which is exposed through ActiveX so you can call it from Lisp.

Alternatively, you can calculate the zoom-centre & zoom-factor for the new window-size and then adjust Center/Width/Height properties of the document's view object to suit. I.e. do the zoom-extents manually without relying on it to do the calculation from the current windows size.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Very strange problem
« Reply #7 on: May 21, 2014, 07:57:16 AM »
This version works for me.
not sure if it will work in Ac2015.

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun SetScreenSize (Width height / acad doc oldsize doc w1 h1 dw dh)
  3.   (setq acad    (vlax-get-acad-object)
  4.         doc     (vla-get-ActiveDocument acad)
  5.         oldsize (getvar "SCREENSIZE")
  6.   )
  7.   (setq W1 (vla-get-width doc)
  8.         H1 (vla-get-Height doc)
  9.         dw (- w1 (car oldsize))
  10.         dh (- h1 (cadr oldsize))
  11.   )
  12.   (vla-put-width doc (+ dw width))
  13.   (vla-put-height doc (+ dh height))
  14.   (vla-Update acad)
  15.  
  16.   (vla-sendcommand doc "zoom e ")
  17. )
  18.  
  19. (defun c:test () (SetScreenSize 400 300) (princ))
  20.  
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.

andy_lee

  • Newt
  • Posts: 147
Re: Very strange problem
« Reply #8 on: May 21, 2014, 09:01:36 AM »
This version works for me.
not sure if it will work in Ac2015.


Kerry,Thank you very much! good!
But I want add 
Code: [Select]
(command "_.zoom" "_e" "._mslide" "testlid") into , how to do?
I try to do it ,but I always fail.

I think I succeeded
like this:  Right?
Code: [Select]
  (vla-sendcommand doc "zoom e ")
  (vla-sendcommand doc "mslide 11")

Thank,Kerry ,Thanks irneb
« Last Edit: May 21, 2014, 09:13:23 AM by emk2012 »
andy.
Best regards.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Very strange problem
« Reply #9 on: May 21, 2014, 09:13:50 AM »

Try something like this
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ()
  2.   (SetScreenSize 400 300)
  3.   (vl-cmdf "._mslide" "Tester2")
  4.   (princ)
  5.  )
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.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Very strange problem
« Reply #10 on: May 21, 2014, 09:14:22 AM »
But I want add 
Code: [Select]
(command "_.zoom" "_e" "._mslide" "testlid") into , how to do?
I try to do it ,but I always fail.
Oh! So you're trying to make a slide at the relevant proportions. You're probably looking to make a block-library?

Anyhow, what about adding a Paper Space Viewport of those dimensions, then going inside it and zooming extents?
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

andy_lee

  • Newt
  • Posts: 147
Re: Very strange problem
« Reply #11 on: May 21, 2014, 10:54:26 AM »

Try something like this
Code - Auto/Visual Lisp: [Select]
  1.   (vl-cmdf "._mslide" "Tester2")
  2.  


Try something like this


Hi Kerry! if like this ,the slide image size is NOT 400*300

Must use  (vla-sendcommand doc "mslide 11") ,
andy.
Best regards.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Very strange problem
« Reply #12 on: May 21, 2014, 06:30:21 PM »
emk2012,
A side note.
The recommended aspect ratio for Slide files is 3:2
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.

andy_lee

  • Newt
  • Posts: 147
Re: Very strange problem
« Reply #13 on: May 21, 2014, 08:07:43 PM »
emk2012,
A side note.
The recommended aspect ratio for Slide files is 3:2

Hi Kerry , Thank you!  I couldn't have done it without you.
andy.
Best regards.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Very strange problem
« Reply #14 on: May 21, 2014, 08:10:29 PM »
I'm sure you could have :)
but it's nice of you to say so.
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Very strange problem
« Reply #15 on: May 21, 2014, 08:17:20 PM »
Just another side note.
The "SCREENSIZE" variable will NOT be updated when using vla-put-height etc until you exit the complete lisp call chain and return to the command line. This has been an issue for about 10 years and can cause some weird problems if a subsequent call is made to (getvar "SCREENSIZE") in the current routine chain.
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.