OpenDCL Forums

OpenDCL => Runtime/AutoLISP => Topic started by: Emiliano on April 21, 2012, 07:42:19 AM

Title: Problem with dcl_PictureBox_DrawRect
Post by: Emiliano on April 21, 2012, 07:42:19 AM
I can not understand ...

The following code works fine:

Code (autolisp) Select

 (dcl_PictureBox_DrawRect NomeApp_NomeForm_PictureBox1 (list (list 10 10 300 20.0 1)))

 

but if I use the following returns the error "invalid argument":
Code (autolisp) Select

 (setq LunghSettore 300)
 (setq CoordX 10)
 (setq CoordY 10)

 (dcl_PictureBox_DrawRect NomeApp_NomeForm_PictureBox1 (list (list CoordX CoordY LunghSettore 20.0 1)))


Can you help?
 
Title: Re: Problem with dcl_PictureBox_DrawRect
Post by: roy_043 on April 21, 2012, 09:32:45 AM
Check if NomeApp_NomeForm_PictureBox1 is the correct symbol name for the control.

Edit: changed control-name as per OP's request.
Title: Re: Problem with dcl_PictureBox_DrawRect
Post by: Emiliano on April 22, 2012, 02:34:45 AM
It has the correct name.
I forgot to change the code before returning in the forum.  :'(
I do not like to be mentioned the name of the application.
At this regard you wonder if you can, please change it in your answer.  :-[
I've corrected my post.

You have any idea why it does not work?
Title: Re: Problem with dcl_PictureBox_DrawRect
Post by: roy_043 on April 22, 2012, 01:41:41 PM
Maybe you have not set up the OnPaint event for the picture box? Temp graphics disappear whenever Windows repaints the control. The picture box is repainted by Windows after the OnInitialize event of the form. Any temp graphics created in the OnInitialize function will be lost.

Code (autolisp) Select

(defun c:NomeApp ( / c:NomeApp_NomeForm_OnInitialize c:NomeApp_NomeForm_PictureBox1_OnPaint CoordX CoordY LunghSettore pictureIsDoneP)

  (defun c:NomeApp_NomeForm_OnInitialize ()
    (print "c:NomeApp_NomeForm_OnInitialize")
  )

  (defun c:NomeApp_NomeForm_PictureBox1_OnPaint (HasFocus /)
    (print "c:NomeApp_NomeForm_PictureBox1_OnPaint")
    (if pictureIsDoneP
      (print "Using stored picture")
      (progn
        (dcl_PictureBox_DrawRect NomeApp_NomeForm_PictureBox1 (list (list CoordX CoordY LunghSettore 20.0 1)))
        (dcl_PictureBox_StoreImage NomeApp_NomeForm_PictureBox1) ; Storing the image is a good idea for large images.
        (setq pictureIsDoneP T)
        (print "Picture painted and stored")
      )
    )
  )

  (setq LunghSettore 300)
  (setq CoordX 10)
  (setq CoordY 10)
  (command "_opendcl")
  (dcl_Project_Load "NomeApp" T)
  (dcl_Form_Show NomeApp_NomeForm)
)
Title: Re: Problem with dcl_PictureBox_DrawRect
Post by: roy_043 on April 23, 2012, 12:43:58 AM
My test files:
Title: Re: Problem with dcl_PictureBox_DrawRect
Post by: Emiliano on April 23, 2012, 01:33:40 AM
Thanks for the reply.
The problem was that the values ​​were real numbers: dcl_PictureBox_DrawRect accepts only integers :-(

Thanks for the advice very useful: (dcl_PictureBox_StoreImage NomeApp_NomeForm_PictureBox1)

Title: Re: Problem with dcl_PictureBox_DrawRect
Post by: Emiliano on April 23, 2012, 02:18:46 AM
I have another problem.
I use the function (dcl_PictureBox_Clear NomeApp_NomeForm_PictureBox1).

Before using this function I want to check if the form and then the PictureBox is already open, because otherwise it gives me error.
How can I do?

I tried with the event OnInitialize but this is started before the Modeless Form is open
Title: Re: Problem with dcl_PictureBox_DrawRect
Post by: Fred Tomke on April 23, 2012, 03:36:05 AM
Hi,

you can use (if NomeApp_NomeForm_PictureBox1 T) to test whether the control is already available or not.

Regards, Fred
Title: Re: Problem with dcl_PictureBox_DrawRect
Post by: roy_043 on April 23, 2012, 04:18:59 AM
Quote from: Emiliano on April 23, 2012, 01:33:40 AM
The problem was that the values ​​were real numbers: dcl_PictureBox_DrawRect accepts only integers :-(

I don't think that was the problem. My test shows that integers are accepted. And in your first post you have said:

Quote from: Emiliano on April 21, 2012, 07:42:19 AM
The following code works fine:
Code (autolisp) Select

 (dcl_PictureBox_DrawRect NomeApp_NomeForm_PictureBox1 (list (list 10 10 300 20.0 1)))


This may however be version-dependent. I have use ODCL version 7.0.0.1.
Title: Re: Problem with dcl_PictureBox_DrawRect
Post by: Emiliano on April 23, 2012, 05:06:38 AM
Quote from: Fred Tomke on April 23, 2012, 03:36:05 AM
Hi,

you can use (if NomeApp_NomeForm_PictureBox1 T) to test whether the control is already available or not.

Regards, Fred

I tried your code but it does not work.
I also tried using:

(if (= (NomeApp_NomeForm_PictureBox1) T)

both return

; Error: wrong function: <Name entità: 14e69d08>

Do you have any idea?
Title: Re: Problem with dcl_PictureBox_DrawRect
Post by: Emiliano on April 23, 2012, 05:09:40 AM
Quote from: roy_043 on April 23, 2012, 04:18:59 AM
Quote from: Emiliano on April 23, 2012, 01:33:40 AM
The problem was that the values ​​were real numbers: dcl_PictureBox_DrawRect accepts only integers :-(

I don't think that was the problem. My test shows that integers are accepted. And in your first post you have said:

Quote from: Emiliano on April 21, 2012, 07:42:19 AM
The following code works fine:
Code (autolisp) Select

 (dcl_PictureBox_DrawRect NomeApp_NomeForm_PictureBox1 (list (list 10 10 300 20.0 1)))


This may however be version-dependent. I have use ODCL version 7.0.0.1.

It is true but when I insert the values ​​stored as variables setq will not work if they are real values​​.
I use ODCL version 7.0.0.2.
However, somehow it works now.
Title: Re: Problem with dcl_PictureBox_DrawRect
Post by: roy_043 on April 23, 2012, 06:45:19 AM
@ Emiliano:
I did not read your reply #5 properly, hence my strange reply #8.
You are right: dcl_PictureBox_DrawRect only accepts integers or "integers as reals" (e.g. 20.0).
Title: Re: Problem with dcl_PictureBox_DrawRect
Post by: Emiliano on April 23, 2012, 06:55:44 AM
Ok!
have any solution for my reply #9?
Title: Re: Problem with dcl_PictureBox_DrawRect
Post by: roy_043 on April 23, 2012, 07:12:54 AM
The principle of Fred's suggestion:

Code (autolisp) Select
(if NomeApp_NomeForm_PictureBox1 ; ename or nil depending on visibility of dialog
 (progn
   ; Do something with NomeApp_NomeForm_PictureBox1
 )
)


See attached files.

BTW: I don't understand the function dcl_PictureBox_StoreImage anymore. It does not seem to be necessary?

Edit: Name has been corrected.
Title: Re: Problem with dcl_PictureBox_DrawRect
Post by: Emiliano on April 24, 2012, 01:19:15 AM
Ok thanks,
now it works! ; D

dcl_PictureBox_StoreImage is necessary because, otherwise, if I reduce to AutoCAD icon, the PictureBox is canceled.
Title: Re: Problem with dcl_PictureBox_DrawRect
Post by: roy_043 on April 24, 2012, 05:12:20 AM
Quote from: Emiliano on April 24, 2012, 01:19:15 AM
dcl_PictureBox_StoreImage is necessary because, otherwise, if I reduce to AutoCAD icon, the PictureBox is canceled.
If you try the code attached to my post #13 you will see that even without dcl_PictureBox_StoreImage the image does not disappear if the cad program is resized or minimized.
Title: Re: Problem with dcl_PictureBox_DrawRect
Post by: roy_043 on May 25, 2012, 12:47:22 AM
I must have been sleeping when I wrote posts #13 and #15. Because the function (dcl_PictureBox_StoreImage) is definitely required to preserve the image. In fact the code attached to my post #13 still uses it. ::)