Jump to content

Recommended Posts

Posted

It still skips over the "getpoint" after adding it as a local variable, i think the dialog box when is preventing it

 

once i run the command it bring a dialog box up asking for a postcode, i enter the psotcode hit "ok" the command runs but the dialog box doesnt close. I have to press "ok" again for it to finish off the command weirdly

16 hours ago, mhupp said:

 

 

prob need to declare it as a local variable so its nil when you run the lisp and will ask you to define it.

(defun JH:insert-mapping (reference / NE NW SE SW Symbol PT Scale rotaton NEpath)

 

 

Posted

I'll take a look closer at the code later today. What dialog box are you talking about?

 

Maybe use

(setvar 'filedia 0)

Turn it back on before leaving the lisp

(setvar 'filedia 1)

 

 

Posted

I figured out what is was, as little and simple as it way. I forgot to add "done dialog" to the action tile,

getpoint now works fine, 

 

(defun JH:insert-mapping (reference / NE NW SE SW PT Scale Rotation Symbol NEpath)
  (done_dialog dlg_id)
  (setq NE (strcat (apply 'strcat reference) "NE")
        NW (strcat (apply 'strcat reference) "NW")
        SE (strcat (apply 'strcat reference) "SE")
        SW (strcat (apply 'strcat reference) "SW")
        Symbol (substr NE 1 2)
  )
  ;(setq PT (getpoint "\nInsertion point"))
  ;(setq Scale 5000)
  ;(setq Rotation 0)
  
  
  (if
    (and
      (findfile (setq NEpath (strcat "X:\\3. Event TM Plans\\Mapping\\data\\" Symbol "\\" NE ".tif")))
      (findfile (setq NWpath (strcat "X:\\3. Event TM Plans\\Mapping\\data\\" Symbol "\\" NW ".tif")))
      (findfile (setq SEpath (strcat "X:\\3. Event TM Plans\\Mapping\\data\\" Symbol "\\" SE ".tif")))
      (findfile (setq SWpath (strcat "X:\\3. Event TM Plans\\Mapping\\data\\" Symbol "\\" SW ".tif")))
    )
    (progn
      (setq echo (getvar 'cmdecho))
      (setvar 'cmdecho 0)
      (command "IMAGEATTACH" "f" NEpath "G" "E")
      (command "IMAGEATTACH" "f" NWpath "G" "E")
      (command "IMAGEATTACH" "f" SEpath "G" "E")
      (command "IMAGEATTACH" "f" SWpath "G" "E")
      (setvar 'cmdecho echo)
    )
  )
)

 

31 minutes ago, mhupp said:

I'll take a look closer at the code later today. What dialog box are you talking about?

 

Maybe use

(setvar 'filedia 0)

Turn it back on before leaving the lisp

(setvar 'filedia 1)

 

 

 

  • Like 2
Posted

Often is the smallest stuff that trips us up!

  • Like 1
  • Agree 1
Posted
1 hour ago, Charpzy said:
(defun JH:insert-mapping (reference / NE NW SE SW PT Scale Rotation Symbol NEpath)
  (done_dialog dlg_id)
  (setq NE (strcat (apply

 

So without seeing your full code, I presume then that the (JH:insert-mapping) function is called from an action tile?

The reason I ask because:

 

1) you don't call (done_dialog) with the ID of the dcl file. it should only be active within the running dialog so it doesn't need the dialog pointer. The argument supplied with (done_dialog) is to supply a return value as seen in #2 below.

 

2) I think it is better practice to supply a output code to done_dialog on the main code and use the output value to run the function.

;; Set the actions to of the buttons to close the dialog with a return value
(action_tile "accept" "(done_dialog 1)")
(action_tile "cancel" "(done_dialog 0)")

;; Start the Dialog and capture the exit value from (done_dialog) in 'ret' variable.
(setq ret (start_dialog))

;; Unload the Dialog after close.
(unload_dialog dclid)

;; Use the 'ret' variable value of the dialog to run the correct function.
(if (= ret 1)(JHinsert-mapping))

 

  • Like 1
Posted

yeah the (JH:insert-mapping) is called inside a action tile

 

I tried adding in a done_dialog into the accept action tile but I had similar issues to what I had before with the dialog box not closing, it was added different to what you have provided here so ill try add how you've suggested.

 

thank you, It makes much more sense how you put it then how I've been trying it 

 

43 minutes ago, pkenewell said:

 

So without seeing your full code, I presume then that the (JH:insert-mapping) function is called from an action tile?

The reason I ask because:

 

1) you don't call (done_dialog) with the ID of the dcl file. it should only be active within the running dialog so it doesn't need the dialog pointer. The argument supplied with (done_dialog) is to supply a return value as seen in #2 below.

 

2) I think it is better practice to supply a output code to done_dialog on the main code and use the output value to run the function.

;; Set the actions to of the buttons to close the dialog with a return value
(action_tile "accept" "(done_dialog 1)")
(action_tile "cancel" "(done_dialog 0)")

;; Start the Dialog and capture the exit value from (done_dialog) in 'ret' variable.
(setq ret (start_dialog))

;; Unload the Dialog after close.
(unload_dialog dclid)

;; Use the 'ret' variable value of the dialog to run the correct function.
(if (= ret 1)(JHinsert-mapping))

 

 

  • Like 1
Posted

I've had a bit of a re-write to fix a few issues etc but I've struggled to implement what has previously been provided to insert 4 different mapping into a specific point selected by a mouse click, atm I've got it so it inserts into the geo location

 

I would like to be able to select a centre point and all 4 mapping place around it (NE, NW, SE & SW)

code:

(defun c:POSTCODE (/ drv postco upper lower second-char num NE NW SE SW NEpath NWpath SEpath SWpath *error*)
  
  (defun *error* ()
    (if (not (member *error* '( "Console Break" "Function cancelled" "quit / exit abort")))
      (princ (strcat "Error: " msg))
    )        ;if
    (princ)
  )
  
  (if (not (setq fn (findfile "MACROS\\DIALOGS\\POSTCODE.dcl")))
    (alert "Dialog POSTCODE.dcl not found")
    (progn
      (setq dlg_id (load_dialog fn))
      (new_dialog "PostcodeDia" dlg_id)

      (action_tile "postcode-search" "(setq postco $VALUE))")

      (action_tile "accept" "(done_dialog 1)")
      (action_tile "cancel" "(done_dialog 0)")

      (setq drv (start_dialog))
      (setq upper (strcase postco)
            lower (strcase postco T)
            second-char (substr lower 2 2)
            num (atoi second-char)
      )
      (cond
        ((= drv 1)
          (progn
            (if
              (= num 1) ;if postcode starts with 1 letter return true
              (setq csv-name (substr lower 1 1)) ;example: B1 1AY
              (setq csv-name (substr lower 1 2)) ;example: DN21 1HS
            )

            (if
              (and
                (setq f (strcat "C:\\BricsCAD Scripts\\MACROS\\CSV\\" (strcase csv-name) ".csv"))
                (setq data (LM:readcsv f))
              )
              (progn
                (if
                  (and
                    (setq NE (strcat (apply 'strcat (cdr (assoc upper data))) "NE"))
                    (setq NW (strcat (apply 'strcat (cdr (assoc upper data))) "NW"))
                    (setq SE (strcat (apply 'strcat (cdr (assoc upper data))) "SE"))
                    (setq SW (strcat (apply 'strcat (cdr (assoc upper data))) "SW"))
                  )
                  (progn
                    (setq Symbol (substr NE 1 2))  ;get the two letters of the Grid reference
                    (if
                      (and
                        (findfile (setq NEpath (strcat "X:\\3. Event TM Plans\\Mapping\\data\\" Symbol "\\" NE ".tif")))
                        (findfile (setq NWpath (strcat "X:\\3. Event TM Plans\\Mapping\\data\\" Symbol "\\" NW ".tif")))
                        (findfile (setq SEpath (strcat "X:\\3. Event TM Plans\\Mapping\\data\\" Symbol "\\" SE ".tif")))
                        (findfile (setq SWpath (strcat "X:\\3. Event TM Plans\\Mapping\\data\\" Symbol "\\" SW ".tif")))
                      )
                      (progn
                        (setq echo (getvar 'cmdecho))
                        (setvar 'cmdecho 0)
                        (command "IMAGEATTACH" "f" NEpath "G" "E") ;full path
                        (command "IMAGEATTACH" "f" NWpath "G" "E") ;full path
                        (command "IMAGEATTACH" "f" SEpath "G" "E") ;full path
                        (command "IMAGEATTACH" "f" SWpath "G" "E") ;full path
                        (setvar 'cmdecho echo)
                      );progn
                      (progn (princ "Please enter a valid postcode in the correct format. For example: \"DN15 7PQ\"") (princ))
                    );if
                  );progn
                  (progn (princ "Mapping file not found, please check files and try again.") (princ))
                );if
              );progn
              (progn (princ "Postcode not found, please check postcode and try again.") (princ))
            );if
            (princ)
          );progn
        );drv
      );cond
    );progn
  );if
);defun

 

  • 3 weeks later...
Posted (edited)

@Charpzy

1) You should always unload your dialog (unless you are looping back into it) via (unload_dialog dlg_id) right after the call to (start_dialog). Or if looping the dialog (see #3), right after the end of the dialog loop. If you don't - then starting other dialogs later on will leave memory allocated for the dialog that you are unable to clear without closing the current drawing.

 

2) You can create a (done_dialog n) action for any button or image button defined in a dialog. For example in the DCL file you could have a button called "Select Center" with the tag "selcen", then with a call in the lisp file such as (action_tile "selcen" "(done_dialog 2)") you can set the return value of the dialog (drv variable) to 2 and do the appropriate selection if the 2 is returned in the variable.

 

3) you can put all the dialog code into a (while) loop so if the drv (dialog exit value) variable is greater than 1, you can get the selection, then loop back and restart the dialog. Note when you restart the dialog you have to re-setup all the tiles and actions but with any changed values from the selection if needed. You would set the default variable values outside the loop, then within the loop you would change the values and keep them set inside the loop to re-fill any edit boxes, etc. 

Example:

(setq dlg_id (load_dialog "myDCL.dcl"))

(while (> drv 1) ; While the drv variable is greater than 1, loops back into dialog.
   (Set_tiles...)
   (action_tiles...)
   (action_tile "accept" "(done_dialog 1)")
   (action_tile "cancel" "(done_dialog 0)")
   (action_tile "selcen" "(done_dialog 2)")
   (setq drv (start_dialog))
   (cond
      ((= drv 0)
          (do_cancel stuff...)
          (unload_dialog dlg_id); unload dialog since loop will not restart.
      )
      ((= drv 1)
         (do stuff..)
         (unload_dialog dlg_id); unload dialog since loop will not restart.
      )
      ((= drv 2)
         (do stuff but don't unload dialog...set variables needed then loop will go back in)
      )
   )
) ; end of while loop

 

Edited by pkenewell

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...