Search code examples
stringdialoglisptypeerrorautolisp

Lisp: `stringtype nil` error trying to get info from a dialogue box and add it with other strings


The program basically gets info from a points description and gets the text from a text item and adds the text item to the points description. The dialogue boxes allow for the user to select some parameters, like is it for lots, lots and blocks, or other. I have been working on this program for multiple days now and it is so close to working. I can get through the dialogue boxes with no problem, and I can get the desired effect with some of the trees (ones where it is simply just getting the info from the point and text item and adding them together like lots). The problem comes when I ask the user to input a number (in this case it is a block number I.E. Block 1) Upon putting in the number and selecting the point and a text item, I get string type nil error. Right now I think it could be due to trying to add a string which contains a space " " or the input on the dialogue box maybe isn't a string

Here is strcat function I am referencing: (vlax-put-property p_obj 'rawdescription (strcat p_desc " BLOCK " type1 " " obj))

And here is the program getting the info from the box:

(action_tile "type1" "(setq type1 $value)")

Below are the relevant snippets of the code, not the entire program

Here is the combining function

(defun c:txcm_block ( / c_doc p_desc p_obj t_obj t1 t_strg text1 ts obj type1 number)
(vl-load-com)
(while
(setq c_doc (vla-get-ActiveDocument (vlax-get-acad-object))
        p_obj (vlax-ename->vla-object (car (entsel "\nSelect Point: ")))
        t_strg (vlax-ename->vla-object (car (entsel "\nPick Text.. "))))
  (setq obj (vla-get-textstring t_strg))
          (setq p_desc(vlax-get p_obj 'rawdescription))
          (vlax-put-property p_obj 'rawdescription (strcat p_desc " BLOCK " type1 " " obj))
)
(princ)
)

Here is the Dialogue Function:

(defun c:nest2 ( / dcl_id2 number1 flag2)

(setq dcl_id2 (load_dialog "textcombine(input).dcl"))

(setq flag2 4)

(if (not (new_dialog "nest2" dcl_id2)) (exit))

(while (> flag2 2)

(set_tile "type1" "Enter Block Number")
(mode_tile "type1" 2)
(action_tile "type1" "(setq type1 $value)")

(action_tile
    "accept"
    "(done_dialog 4)"
)
(action_tile
    "cancel"
     "(done_dialog 0)
      (setq result nil)
      (c:txcm)"
)
(setq flag2 (start_dialog))


(if (= flag2 4)
 
    (progn   

    (setq result T)
    (c:txcm_block)

    )
)

)
(unload_dialog dcl_id2)
)

And here is the nested DCL Code:

nest2 : dialog {
       
 label = "Block Number";

    : edit_box
    {
    label = "Enter Block Number: ";
    mnemonic = "N";
    key = "type1";
    alighnment = centered;
    edit_limit = 30;
    edit_width = 30;
    }
    : button    
    {
    key = "accept";
    label = "Ok";
    is_default = true;
    fixed_width = true;
    alignment = right;
        allow_accept = true;
    }
    : button    
    {
    key = "cancel";
    label = "Go Back";
    fixed_width = true;
    alignment = centered;
    }

 
    : errtile
    {
    width = 17;
    }
         }

Any help would be appreciated! I have been all over the internet, but I feel like I am stuck. If you need more info, let me know!


Solution

  • You do seem to be setting the variable type1 inside your (c:nest2), and you do call (c:txcm_block) from (c:nest2), but (c:txcm_block) declares type1 as its local variable, so type1 is set to NIL on entry to (c:txcm_block).

    NIL is not a string, so strcat naturally complains and bails.

    Remove type1 from the local variables declaration list in (c:txcm_block) and put it on the local variables declaration list in (c:nest2).

    In general, to deal with such situations, use your debugger to "break on error", then inspect the execution trace and check the current values of the variables of interest (like type1) at that point.