Author Topic: Functions doesn't work after reopening Form! Please help!  (Read 162 times)

TheCADnoobie

  • Member
  • *
  • Posts: 2
Functions doesn't work after reopening Form! Please help!
« on: August 26, 2018, 03:21:27 AM »
Hi everyone,

I have next problem. I created a program with only 1 form where user:
1. open modal dialog Form
2. press on Text button to close Form
3. select hatch from drawing
4. reopen Form again

Then I extract data of hatch, pattern, colors, scale etc and put them into a string type. After that I tried to put them into respective Textboxes inside of Form with

(dcl-Control-SetText testhatch/Form1/TextBox1 patname)

and I constantly getting error:
Code: [Select]
An OpenDCl function argument processing exception has occured!
Error: NIL value not allowed
Function: dcl-Control-SetText
Argument:0

I even tried instead my variable "patname" put string "example" and it gave to me same error.
I simply can't use any other function after reopening form.
Whole code is below. Thank you very much in advance on your help.
Code: [Select]
; Ensure the appropriate OpenDCL ARX file is loaded
(vl-load-com)
(setq cmdecho (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(command "_OPENDCL")
(dcl_Project_Load "testhatch" T)
(setvar "CMDECHO" cmdecho)
(princ)
   

(defun c:testhatch (/ doCont intResult result)

(defun c:testhatch/Form1#OnInitialize (/)
  (dcl-Control-SetText testhatch/Form1/TextBox1 "-")
            (dcl-Control-SetText testhatch/Form1/TextBox2 "-")
            (dcl-Control-SetText testhatch/Form1/TextBox3 "-")
            (dcl-Control-SetText testhatch/Form1/TextBox4 "-")
)

    ; define condition index for pressing a button
      (defun c:testhatch/Form1/TextButton1#OnClicked (/)
      (dcl-Form-Close testhatch/Form1 3)
  )

    ; do while form is closed after pressing a button
(setq doCont T)
    (while doCont
       (setq doCont nil)
           (setq intResult(dcl_form_show testhatch/Form1))
       (cond
            ((= intResult 2) (princ "\n*** Program closed by user. ***")(setq doCont nil))   
          ((= intResult 3) (pickHatch) (setq doCont T))
       ); cond
    ); while

  (redraw)
  (princ)

   
);testhatch program

(princ)


;===================================================================
; odabir samo hatch
(defun pickHatch (/ hatch bcolor color patname patscale ss ename colors bcolors)

  (while (not
  (setq hatch (ssget "_+.:E:S" '((0 . "HATCH")))))
  (alert "Pick HATCH!")
  )

            (setq ename (ssname hatch 0))
            (setq ss (vlax-ename->vla-object ename))
            (setq patname (vla-get-patternname ss))
              (setq color (vla-get-truecolor ss))
            (setq bcolor (vla-get-backgroundcolor ss))
  (setq patscale (vla-get-patternscale ss))

            ; create string from colors and scale
            (setq colors (princ (strcat (itoa (vla-get-red color)) "," (itoa (vla-get-green color)) "," (itoa (vla-get-blue color)))))
            (setq bcolors(princ (strcat (itoa (vla-get-red bcolor)) "," (itoa (vla-get-green bcolor)) "," (itoa (vla-get-blue bcolor)))))
            (setq scales (princ (rtos patscale 2 1)))

            ;(setq result (list patname colors bcolors scales))
           
            ; fill textboxes in gui (THIS DOESN'T WANT TO WORK!!!) ************************************
                ;(dcl-Control-SetText testhatch/Form1/TextBox1 patname)
            ;(dcl-Control-SetText testhatch/Form1/TextBox2 colors)
            ;(dcl-Control-SetText testhatch/Form1/TextBox3 bcolors)
            ;(dcl-Control-SetText testhatch/Form1/TextBox4 scales)
(princ)
        ) ; pickHatch

;===================================================================




owenwengerd

  • Administrator
  • Hero Member
  • *****
  • Posts: 2971
    • Outside The Box
Re: Functions doesn't work after reopening Form! Please help!
« Reply #1 on: August 26, 2018, 09:43:27 AM »
Your function (pickhatch) runs while the form is closed, before it is re-opened. Populating the form controls must be done after the form is re-opened, typically inside the form's OnInitialize event handler. You could save your hatch selection in a global variable. Inside OnInitialize, populate the controls when the global variable has a value.