TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: andy_lee on May 20, 2014, 05:08:27 AM

Title: Very strange problem
Post by: andy_lee 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"
(http://www.theswamp.org/index.php?action=dlattach;topic=47097.0;attach=27454;image)

Oh , why ? Need to run“test” twice
Normal should be like this
(http://www.theswamp.org/index.php?action=dlattach;topic=47097.0;attach=27455;image)

Title: Re: Very strange problem
Post by: irneb 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
Title: Re: Very strange problem
Post by: andy_lee 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.
Title: Re: Very strange problem
Post by: irneb 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
Title: Re: Very strange problem
Post by: andy_lee 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.
Title: Re: Very strange problem
Post by: andy_lee on May 21, 2014, 06:45:58 AM
There is no way to solve ?
Title: Re: Very strange problem
Post by: irneb 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.
Title: Re: Very strange problem
Post by: Kerry 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.  
Title: Re: Very strange problem
Post by: andy_lee 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
Title: Re: Very strange problem
Post by: Kerry 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.  )
Title: Re: Very strange problem
Post by: irneb 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?
Title: Re: Very strange problem
Post by: andy_lee 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") ,
Title: Re: Very strange problem
Post by: Kerry on May 21, 2014, 06:30:21 PM
emk2012,
A side note.
The recommended aspect ratio for Slide files is 3:2
Title: Re: Very strange problem
Post by: andy_lee 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.
Title: Re: Very strange problem
Post by: Kerry on May 21, 2014, 08:10:29 PM
I'm sure you could have :)
but it's nice of you to say so.
Title: Re: Very strange problem
Post by: Kerry 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.