Author Topic: Stored variable ?  (Read 10175 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Stored variable ?
« Reply #15 on: February 20, 2004, 12:48:41 PM »
How can I get this code to do nothing if the cancel button is selected on the dialog box? Where in the code should I place it?


Code: [Select]

(defun C:GO ()
  (setq DWG-NAME (strcase (getvar "DWGNAME")))
  (setq DWG-SEQ (substr DWG-NAME 3 2))
  (if (or (= T (wcmatch DWG-SEQ "FP")) (= T (wcmatch DWG-SEQ "SR")))
    (CONTINUE-ON)
    (alert
      "\nThis will not work in the drawing you are in. ABORTING!!!!!!!!!"
    )
  )
  (princ)
)

(defun CONTINUE-ON ()
  (setq REGION# "R3")
  (setq DWGTYPE "FP")
  (setq RNAMES '("R3" "R4" "R8" "R9" "R11"))
  (setq dcl_id (load_dialog "Gset.dcl"))
  (if (not (new_dialog "Gset" dcl_id))
    (exit)
  )
  (start_list "selections")
  (mapcar 'add_list RNAMES)
  (end_list)
  (action_tile "rb1" "(setq DWGTYPE \"FP\")")
  (action_tile "rb2" "(setq DWGTYPE \"SR\")")
  (action_tile
    "cancel"
    "(done_dialog) (setq userclick nil)"
  )
  (action_tile
    "accept"
    (strcat
      "(progn
       (setq REGION# (atof (get_tile \"selections\")))"
      " (done_dialog)(setq userclick T))"
    )
  )
  (start_dialog)
  (unload_dialog dcl_id)
  (if userclick
    (progn
      (setq REGION# (fix REGION#))
      (setq REGION# (nth REGION# RNAMES))
    )
  )
  (DO_WORK5)
  (setq REGION# nil
DWGTYPE nil
RNAMES nil
DCL_ID nil
  )
  (princ)
)

(defun DO_WORK5 ()
  (if (= DWGTYPE "FP") (FP-DWG))
  (if (= DWGTYPE "SR") (SR-DWG))
  (while (equal 8 (logand 8 (getvar "undoctl")))
    (command "_.undo" "_end")
  )        
  (while (not (equal 8 (logand 8 (getvar "undoctl"))))
    (command "_.undo" "_begin")
  )
)

(defun FP-DWG ()
  (DO-ALL)
  (C:INSERTDIM)
  (setq RLAYER (strcat REGION# DWGTYPE))
  (eval (list (read (strcat "C:" RLAYER))))
  (princ)
)

(defun SR-DWG ()
  (DO-ALL)
  (setq RLAYER (strcat REGION# DWGTYPE))
  (eval (list (read (strcat "C:" RLAYER))))
  (princ)
)

(defun DO-ALL ()
  (command "audit" "y" "")
  (setq *doc* (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vla-AuditInfo *doc* :vlax-true)
  (repeat 3
    (vla-PurgeAll *doc*)
  )
  (command "limmax" "10000,10000")
  (command ".regen")
  (princ)
)
[/quote]
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Stored variable ?
« Reply #16 on: February 20, 2004, 01:00:40 PM »
(quit) or (exit) to call your error trap.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

SMadsen

  • Guest
Stored variable ?
« Reply #17 on: February 20, 2004, 02:02:02 PM »
Don, here are some commented alterations to the code you posted. You might just find some answers to your questions in there.

Code: [Select]
(defun CONTINUE-ON (/ REGION# DWGTYPE RNAMES DCL_ID myAction)
  (setq REGION# "R3")
  (setq DWGTYPE "FP")
  (setq RNAMES '("R3" "R4" "R8" "R9" "R11"))
  (setq dcl_id (load_dialog "Gset.dcl"))
 
  ;; I like to use COND instead of (if (not (new_dialog ...))(exit)).
  ;; First off, I don't like EXIT or QUIT and secondly, you get a
  ;; nice wrap-around of all dialog-based calls
  (cond
    ((new_dialog "Gset" dcl_id)

     (start_list "selections")
     (mapcar 'add_list RNAMES)
     (end_list)
     (action_tile "rb1" "(setq DWGTYPE \"FP\")")
     (action_tile "rb2" "(setq DWGTYPE \"SR\")")
     ;; If you're using the default OK & Cancel buttons, there's
     ;; no need to assign actions - they are precoded.
     ;; You do need to set REGION#, though. But you are setting
     ;; a default value at the beginning so there's no need to
     ;; read it if the user didn't select anything else.
     ;; Why not put assigment of REGION# where it belongs: the
     ;; popup (or list_box?) where the user selects it?
     ;; This will  assign REGION# to whichever item the user
     ;; selects - WHEN he/she makes a selection:
     (action_tile "selections" "(setq REGION# (nth (atoi $value) RNAMES))")

     ;; How to get the button hit on exit?
     ;; START_DIALOG returns a value that is normally defined by
     ;; DONE_DIALOG. But the predefined OK and Cancel buttons return
     ;; 1 and 0, respectively (if they've not been overriden by other
     ;; tiles)
     (setq myAction (start_dialog))
    )
  )
  (unload_dialog dcl_id)
  ;; Check if OK was hit. If so do your stuff, otherwise do nawt
  ;; Pass local vars as arguments to DO_WORK5
  (if (= myAction 1)
    (DO_WORK5 REGION# DWGTYPE)
  )
  ;; no need to set vars to nil if they're localized
  ;; (setq REGION# nil .. etc. deleted
  (princ)
)

(defun DO_WORK5   (REGION# DWGTYPE)
  ;; After inspecting the DWGTYPE argument, pass
  ;; the arguments to the lucky function
  (if (= DWGTYPE "FP") (FP-DWG REGION# DWGTYPE))
  (if (= DWGTYPE "SR") (SR-DWG REGION# DWGTYPE))
  ;; This below I'm won't comment
  (while (equal 8 (logand 8 (getvar "undoctl")))
    (command "_.undo" "_end")
  )
  (while (not (equal 8 (logand 8 (getvar "undoctl"))))
    (command "_.undo" "_begin")
  )
)

(defun FP-DWG (REGION# DWGTYPE)
  (DO-ALL)
  ;; If you're using REGION# or DWGTYPE in C:INSERTDIM
  ;; then make sure they are passed as arguments
  (C:INSERTDIM)
  (setq RLAYER (strcat REGION# DWGTYPE))
  (eval (list (read (strcat "C:" RLAYER))))
  (princ)
)

(defun SR-DWG (REGION# DWGTYPE)
  (DO-ALL)
  (setq RLAYER (strcat REGION# DWGTYPE))
  (eval (list (read (strcat "C:" RLAYER))))
  (princ)
)

;; Important: one of the changes here makes the document
;; object a local variable that is released after use! If you
;; are using it as a global variable somewhere else then make
;; sure you are getting the doc in those routines, also.
;; Alternatively, don't adopt the changes!
(defun DO-ALL (/ doc)
  (command "audit" "y" "")
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vla-AuditInfo doc :vlax-true)
  (repeat 3
    (vla-PurgeAll doc)
  )
  ;; No need to use the slow COMMAND for this one
  (setvar "LIMMAX" '(10000.0 10000.0))
  ;; Why not regen with the document already at hand?
  (vla-regen doc acAllViewports)
  ;; Don't go without cleaning up
  (vlax-release-object doc)
  ;; If this is not the last routine then it'd be good
  ;; to remove the PRINC if it's included somewhere else
  ;; (and it is :)
  (princ)
)

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Stored variable ?
« Reply #18 on: February 20, 2004, 03:34:58 PM »
Thanks SMadsen for the critique. I'm always looking for better (smarter) ways for doing something. I'm still very new to Visual Lisp. I'm still learning to walk before I can run.

Thanks again..

Don
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Stored variable ?
« Reply #19 on: February 20, 2004, 11:43:55 PM »
Quote from: dvarino
.....I'm still learning to walk before I can run.....


Many of us here are still learning to crawl .... and have not yet progressed enough to even call ourselves crawlers.

The fact is that you will never know ALL there is to know about programming in any particular language. Some of the more elegant and resourceful coders like Stig and Matt would likely agree. I have been coding in Lisp for 10 years and have written applications that are around 1 meg in lisp. Very very complex routines, yet I still find new ways to implement code that I surprise myself regularly.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Stored variable ?
« Reply #20 on: February 23, 2004, 03:48:14 PM »
I'm modifying the code below to add additional features. Now I'm getting "too few arguments". Am I just missing something here. Any comments welcome.


Code: [Select]

(defun C:GSA (/ REGION# DWGTYPE DWGTYPE1 RNAMES DCL_ID myAction)
(setvar "CMDECHO" 0)
 (setq REGION# "R3")
 (setq DWGTYPE "FP")
  (setq RNAMES '("R3" "R4" "R8" "R9" "R11"))
  (setq dcl_id (load_dialog "Gset.dcl"))
    (cond
    ((new_dialog "Gset" dcl_id)
     (start_list "selections")
     (mapcar 'add_list RNAMES)
     (end_list)
     (mode_tile "tog1" 1)
     (action_tile "rb1" "(setq DWGTYPE \"FP\")(mode_tile \"tog1\" 0)")
     (action_tile "rb2" "(setq DWGTYPE \"SR\")(mode_tile \"tog1\" 1)")
     (action_tile "selections" "(setq REGION# (nth (atoi $value) RNAMES))")
     (action_tile "tog1" "(setq DWGTYPE1 \"SP\")(mode_tile \"rb2\" 1)")
     (setq myAction (start_dialog))
    )
  )
  (unload_dialog dcl_id)
  (if (= myAction 1)
    (DO_WORK5 REGION# DWGTYPE)
  )
  (princ)
)

(defun DO_WORK5   (REGION# DWGTYPE)
  (if (= DWGTYPE "FP") (FP-DWG REGION# DWGTYPE))
  (if (= DWGTYPE "SR") (SR-DWG REGION# DWGTYPE))
)

(defun FP-DWG (REGION# DWGTYPE)
  (C:INSERTDIM)
  (DO-ALL)
      (if (/= DWGTYPE1 NIL)
      (INSERT_SITE_LAYERS)
              (DO-FP)
      )
  )
 
    (defun DO-FP (REGION# DWGTYPE)
  (setq RLAYER (strcat REGION# DWGTYPE))
  (eval (list (read (strcat "C:" RLAYER))))
  (princ)
)

(defun SR-DWG (REGION# DWGTYPE)
  (DO-ALL)
  (setq RLAYER (strcat REGION# DWGTYPE))
  (eval (list (read (strcat "C:" RLAYER))))
  (princ)
)

(defun DO-ALL (/ doc)
  (C:DELNUL)
  (C:FIXSEQEND)
  (command "audit" "y" "")
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (vla-AuditInfo doc :vlax-true)
  (repeat 3
    (vla-PurgeAll doc)
  )
  (setvar "LIMMIN" '(0 0))
  (setvar "LIMMAX" '(10000.0 10000.0))
  (vla-regen doc acAllViewports)
  (vlax-release-object doc)
  (princ)
)
 
  (defun INSERT_SITE_LAYERS ()
  (setq SITEL "site")
    (setq RLAYER1 (strcat REGION# SITEL))
    (eval (list (read (strcat "C:" RLAYER1))))
    (princ)
    )
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Stored variable ?
« Reply #21 on: February 23, 2004, 03:53:06 PM »
you have this (DO-FP) but it looks like it needs some arguments   (defun DO-FP (REGION# DWGTYPE)
TheSwamp.org  (serving the CAD community since 2003)

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Stored variable ?
« Reply #22 on: February 23, 2004, 03:57:07 PM »
Thanks for that. I forgot I put those in there.
(defun DO-FP () <-----Corrected.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

SMadsen

  • Guest
Stored variable ?
« Reply #23 on: February 24, 2004, 10:19:55 AM »
The idea of using local variables fades away if you don't pass arguments to DO-FP. So, if I were you, I would leave the definition of DO-FP as it is and instead call it in FP-DWG as (DO-FP REGION# DWGTYPE) - thereby passing the right arguments to DO-FP.

Also in the last function, INSERT-SITE-LAYERS, you are using REGION# without it being declared as an argument. This does not trigger a stringp error because REGION# is exposed from FP-DWG but it is risky business to use local variables exposed from a calling function.