Author Topic: DCL (First 'crack' attempt)  (Read 2989 times)

0 Members and 1 Guest are viewing this topic.

Birdy

  • Guest
DCL (First 'crack' attempt)
« on: March 07, 2005, 09:19:47 AM »
I'm working on a routine that'll set Layer, Dimstyle, & Textstyle to our company standards for a given architectural scale via a simple dialog box.  It more or less works, but what I'd like is for it to initialize to 1" scale the first time it's run in a drawing session, and then as the user changes to another scale, have that setting stick in the dialog box.  Can't quite figure it out.  Also, <StickingMyNeckWayOut>  I'd appreciate any advice/opinions on my code.  I know it's not the most elegant, or streamlined, but I gotta walk before I can run.  I have the opinion that this may be easier (read: more streamlined) in VB(A?), but I'm just getting into LISA now....er, LISP that is, and wanna get a good handle on IT first.
Code: [Select]
 //  <SETSCALE.DCL>
  //  Created: <JAN. 2005>
  //  Modified: <>
  //  
  //  
  //  
  //  This DCL routine defines a dialog box to select a scale from user input
  //  and sets the Dimstyle, Textstyle, and Layer to the corresponding
  //  values.
  //  
  //  It is designed to run with SETSCALE.LSP
  //  


SETSCALE : dialog {
label = "Set Scale";
: text {
key = "t1";
value="Select to set Dimension, Text, and Layer Settings.";
width=40;
}
:boxed_row {
: radio_column {
: radio_button {
key = "fs";
label ="Full Scale";
}
: radio_button {
key = "hs";
label ="Half Scale";
}
: radio_button {
key="3s";
label ="3\"=1'-0\"";
}
: radio_button {
key="15s";
label ="1 1/2\"=1'-0\"";
}
: radio_button {
key = "1s";
label ="1\"=1'-0\"";
}
} //end of radio_column
: radio_column {
: radio_button {
key = "34s";
label ="3/4\"=1'-0\"";
}
: radio_button {
key = "12s";
label ="1/2\"=1'-0\"";
}
: radio_button {
key="38s";
label ="3/8\"=1'-0\"";
}
: radio_button {
key="14s";
label ="1/4\"=1'-0\"";
}
} //end of radio_column
} //end of boxed_row
:text {
value = " ...tap, tap, tap... ";}
ok_cancel;
} //end of dialog


Here's the lisp. I don't know if all the 'set_tile' calls are right.  I tried a few different things with 'em and they don't seem to have much effect.
Code: [Select]
 ;
  ;<SETSCALE>.lsp
  ;Created: <JAN. 2005>
  ;Modified: <>
  ;
  ;This LISP routine uses a dialog box to select a scale from user input
  ; and sets the Dimstyle, Textstyle, and Layer to the corresponding
  ; values.
  ;
  ;
  ;
(defun C:SETSCALE  (/ $VALUE DCL_ID fS fS 3s 15s 1s 34s 12s 38s 14s)
  ;DEFINE LOCAL VARIABLES
  (setvar "cmdecho" 0)
  ;Loads dialog box
  (setq dcl_id (load_dialog "SETSCALE.dcl"))
  (if (not (new_dialog "SETSCALE" dcl_id))
    (exit)
    )
  ;(set_tile "1s" "1")
  (action_tile
    "fs"
    "(setq fs $value hs \"0\" 3s \"0\" 15s \"0\" 1s \"0\" 34s \"0\" 12s \"0\" 38s \"0\" 14s \"0\")")
  (action_tile
    "hs"
    "(setq fs \"0\" hs $value 3s \"0\" 15s \"0\" 1s \"0\" 34s \"0\" 12s \"0\" 38s \"0\" 14s \"0\")")
  (action_tile
    "3s"
    "(setq fs \"0\" hs \"0\" 3s $value 15s \"0\" 1s \"0\" 34s \"0\" 12s \"0\" 38s \"0\" 14s \"0\")")
  (action_tile
    "15s"
    "(setq fs \"0\" hs \"0\" 3s \"0\" 15s $value 1s \"0\" 34s \"0\" 12s \"0\" 38s \"0\" 14s \"0\")")
  (action_tile
    "1s"
    "(setq fs \"0\" hs \"0\" 3s \"0\" 15s \"0\" 1s $value 34s \"0\" 12s \"0\" 38s \"0\" 14s \"0\")")
  (action_tile
    "34s"
    "(setq fs \"0\" hs \"0\" 3s \"0\" 15s \"0\" 1s \"0\" 34s $value 12s \"0\" 38s \"0\" 14s \"0\")")
  (action_tile
    "12s"
    "(setq fs \"0\" hs \"0\" 3s \"0\" 15s \"0\" 1s \"0\" 34s \"0\" 12s $value 38s \"0\" 14s \"0\")")
  (action_tile
    "38s"
    "(setq fs \"0\" hs \"0\" 3s \"0\" 15s \"0\" 1s \"0\" 34s \"0\" 12s \"0\" 38s $value 14s \"0\")")
  (action_tile
    "14s"
    "(setq fs \"0\" hs \"0\" 3s \"0\" 15s \"0\" 1s \"0\" 34s \"0\" 12s \"0\" 38s \"0\" 14s $value)")

  (set_tile "fs" "(setq fs $value)")
  (set_tile "hs" "(setq fs $value)")
  (set_tile "3s" "(setq fs $value)")
  (set_tile "15s" "(setq fs $value)")
  (set_tile "1s" "(setq fs $value)")
  (set_tile "34s" "(setq fs $value)")
  (set_tile "12s" "(setq fs $value)")
  (set_tile "38s" "(setq fs $value)")
  (set_tile "14s" "(setq fs $value)")
  (start_dialog)

  (cond
    ((= fs "1")
     (command "-dimstyle" "restore" "DFULL")
     (command "-layer" "s" "DFULL" "" "")
     (command "-style" "TF1" "" "" "" "" "n" "n" ""))
    ((= hs "1")
     (command "-dimstyle" "restore" "DHALF")
     (command "-layer" "s" "DFULL" "" "")
     (command "-style" "TH1" "" "" "" "" "n" "n" ""))
    ((= 3s "1")
     (command "-dimstyle" "restore" "D3")
     (command "-layer" "s" "D3" "" "")
     (command "-style" "T31" "" "" "" "" "n" "n" ""))
    ((= 15s "1")
     (command "-dimstyle" "restore" "D15")
     (command "-layer" "s" "DIMENSIONS" "" "")
     (command "-style" "T151" "" "" "" "" "n" "n" ""))
   ((= 1s "1")
     (command "-dimstyle" "restore" "D1")
     (command "-layer" "s" "DIMENSIONS" "" "")
     (command "-style" "T11" "" "" "" "" "n" "n" ""))
   ((= 34s "1")
     (command "-dimstyle" "restore" "D34")
     (command "-layer" "s" "DIMENSIONS" "" "")
     (command "-style" "T341" "" "" "" "" "n" "n" ""))
   ((= 12s "1")
     (command "-dimstyle" "restore" "D12")
     (command "-layer" "s" "DIMENSIONS" "" "")
     (command "-style" "T121" "" "" "" "" "n" "n" ""))
   ((= 38s "1")
     (command "-dimstyle" "restore" "D38")
     (command "-layer" "s" "DIMENSIONS" "" "")
     (command "-style" "T381" "" "" "" "" "n" "n" ""))
   ((= 14s "1")
     (command "-dimstyle" "restore" "D14")
     (command "-layer" "s" "DIMENSIONS" "" "")
     (command "-style" "T141" "" "" "" "" "n" "n" ""))

    ) ;end cond
 
  ) ;end defun SETSCALE


Thanks for the help folks.

kozmos

  • Newt
  • Posts: 114
DCL (First 'crack' attempt)
« Reply #1 on: March 08, 2005, 02:48:32 AM »
optimized codes
DCL
Code: [Select]

SETSCALE : dialog {
  label = "Set Scale";
  :boxed_radio_column {
    label="Set New scale";
    key="Scale" ;
    : radio_button {
      key = "fs";
      label ="Full Scale";
    }
    : radio_button {
      key = "hs";
      label ="Half Scale";
    }
    : radio_button {
      key="3s";
      label ="3\042=1'-0\042";
    }
    : radio_button {
      key="15s";
      label ="1 1/2\042=1'-0\042";
    }
    : radio_button {
      key = "1s";
      label ="1\042=1'-0\042";
    }
    : radio_button {
      key = "34s";
      label ="3/4\042=1'-0\042";
    }
    : radio_button {
      key = "12s";
      label ="1/2\042=1'-0\042";
    }
    : radio_button {
      key="38s";
      label ="3/8\042=1'-0\042";
    }
    : radio_button {
      key="14s";
      label ="1/4\042=1'-0\042";
    }
  }
  ok_cancel;
}



AutoLISP codes:
Code: [Select]

(defun C:SETSCALE (/ dcl_id item scale)
  (setvar "cmdecho" 0)
  (if (setq dcl_id (load_dialog "SETSCALE.dcl"))
    (if (not (new_dialog "SETSCALE" dcl_id))
      (exit)
      (progn
(set_tile "Scale" "fs")
(foreach item '("fs" "hs" "15s" "38s" "1s" "34s" "14s" "12s" "3s")
 (action_tile item "(setq scale $key)")
)
(if (= (start_dialog) 1)
 (cond ((= scale "fs")
(command "-dimstyle" "restore" "DFULL")
(command "-layer" "s" "DFULL" "" "")
(command "-style" "TF1" "" "" "" "" "n" "n" "")
)
((= scale "hs")
(command "-dimstyle" "restore" "DHALF")
(command "-layer" "s" "DFULL" "" "")
(command "-style" "TH1" "" "" "" "" "n" "n" "")
)
((= scale "3s")
(command "-dimstyle" "restore" "D3")
(command "-layer" "s" "D3" "" "")
(command "-style" "T31" "" "" "" "" "n" "n" "")
)
((= scale "15s")
(command "-dimstyle" "restore" "D15")
(command "-layer" "s" "DIMENSIONS" "" "")
(command "-style" "T151" "" "" "" "" "n" "n" "")
)
((= scale "1s")
(command "-dimstyle" "restore" "D1")
(command "-layer" "s" "DIMENSIONS" "" "")
(command "-style" "T11" "" "" "" "" "n" "n" "")
)
((= scale "34s")
(command "-dimstyle" "restore" "D34")
(command "-layer" "s" "DIMENSIONS" "" "")
(command "-style" "T341" "" "" "" "" "n" "n" "")
)
((= scale "12s")
(command "-dimstyle" "restore" "D12")
(command "-layer" "s" "DIMENSIONS" "" "")
(command "-style" "T121" "" "" "" "" "n" "n" "")
)
((= scale "38s")
(command "-dimstyle" "restore" "D38")
(command "-layer" "s" "DIMENSIONS" "" "")
(command "-style" "T381" "" "" "" "" "n" "n" "")
)
((= scale "14s")
(command "-dimstyle" "restore" "D14")
(command "-layer" "s" "DIMENSIONS" "" "")
(command "-style" "T141" "" "" "" "" "n" "n" "")
)
 )
)
      )
    )
  )
)
KozMos Inc.

SMadsen

  • Guest
DCL (First 'crack' attempt)
« Reply #2 on: March 08, 2005, 05:02:54 AM »
kozmos, now you made the radio buttons into a cluster (good idea), you could handle the cluster as a whole instead of dealing with each button:
Code: [Select]
(defun C:SETSCALE (/ dcl_id items scale)
  (defun doCommand (args)
    (if (tblsearch "DIMSTYLE" (car args))
      (command "-DIMSTYLE" "Restore" (car args))
      (princ (strcat "\nCould not restore dimstyle \"" (car args) "\""))
    )
    (if (tblsearch "LAYER" (cadr args))
      (command "-LAYER" "Set" (cadr args) "")
      (princ (strcat "\nCould not find layer \"" (cadr args) "\""))
    )
    (if (vl-cmdf "-STYLE" (caddr args) "" "" "" "" "n" "n" "")
      (princ (strcat "\nText style \"" (caddr args) "\" set"))
      (princ (strcat "\nCould not create text style \"" (caddr args) "\""))
    )
  )

  (setvar "cmdecho" 0)
  (setq dcl_id (load_dialog "SETSCALE.dcl"))
  (setq items '(("fs" "DFULL" "DFULL" "TF1")     ("hs" "DHALF" "DFULL" "TH1")
                ("3s" "D3" "D3" "T31")           ("15s" "D15" "DIMENSIONS" "T151")
                ("1s" "D1" "DIMENSIONS" "T11")   ("34s" "D34" "DIMENSIONS" "T341")
                ("12s" "D12" "DIMENSIONS" "T121")("38s" "D38" "DIMENSIONS" "T381")
                ("14s" "D14" "DIMENSIONS" "T141")
               )
  )

  (cond ((new_dialog "SETSCALE" dcl_id)
         (set_tile "Scale" "fs")
         (action_tile "Scale" "(setq scale $value)")
         (if (= (start_dialog) 1)
           (doCommand (cdr (assoc scale items)))
         )
        )
  )
  (princ)
)

Birdy

  • Guest
DCL (First 'crack' attempt)
« Reply #3 on: March 08, 2005, 07:14:35 AM »
Hey thanks for the input.  While I was waiting for some responses I plowed through the Swamp and found links to JefferyPSanders site and a link to your site Stig.(and a few others)  Spent most of the workday there and really learned a lot.  If I can indulge a few questions, I'd appreciate it.

kozmos:

In your optimized dcl, you have
Code: [Select]
label ="3\042=1'-0\042";

Is there any special significance to the \042 as opposed to \" ?

Thanks for the "(foreach item  " tip.  I had streamlined mine somewhat (ie, got the garbage stuff out, but this is especially nice.

Also, thanks for the kind word "optimized"  LOL very well put.

Stig:

Am I correct that you've added some error handling code? Nice.

Very nice improvements, thanks.  Is there a way that this could be modified, so that each time a user activates the command the default selection is the one checked from a previous choice? IOW, if I pick 3"=1'-0" scale, the next time Ii envoke the command, 3"=1'-0" is preselected.

TIA

kozmos

  • Newt
  • Posts: 114
DCL (First 'crack' attempt)
« Reply #4 on: March 08, 2005, 10:56:26 AM »
1: \042 = \" both in LISP and DCL
2: you can use getcfg/setcfg to save/read the value of "Scale"
Code: [Select]

(defun C:SETSCALE (/ dcl_id items scale)
  (defun doCommand (args)
    (if (tblsearch "DIMSTYLE" (car args))
      (command "-DIMSTYLE" "Restore" (car args))
      (princ (strcat "\nCould not restore dimstyle \"" (car args) "\""))
    )
    (if (tblsearch "LAYER" (cadr args))
      (command "-LAYER" "Set" (cadr args) "")
      (princ (strcat "\nCould not find layer \"" (cadr args) "\""))
    )
    (if (vl-cmdf "-STYLE" (caddr args) "" "" "" "" "n" "n" "")
      (princ (strcat "\nText style \"" (caddr args) "\" set"))
      (princ (strcat "\nCould not create text style \"" (caddr args) "\""))
    )
  )

  (setvar "cmdecho" 0)
  (setq dcl_id (load_dialog "SETSCALE.dcl"))
  (setq items '(("fs" "DFULL" "DFULL" "TF1")     ("hs" "DHALF" "DFULL" "TH1")
                ("3s" "D3" "D3" "T31")           ("15s" "D15" "DIMENSIONS" "T151")
                ("1s" "D1" "DIMENSIONS" "T11")   ("34s" "D34" "DIMENSIONS" "T341")
                ("12s" "D12" "DIMENSIONS" "T121")("38s" "D38" "DIMENSIONS" "T381")
                ("14s" "D14" "DIMENSIONS" "T141")
               )
  )

  (cond ((new_dialog "SETSCALE" dcl_id)
         (if (member (setq scale (getcfg "AppData/ArchScale/ActiveScale")) '("" nil))
             (setq scale "fs")
         )
         (set_tile "Scale" scale)
         (action_tile "Scale" "(setq scale $value)")
         (if (= (start_dialog) 1)(progn
           (setcfg "AppData/ArchScale/ActiveScale" scale)
           (doCommand (cdr (assoc scale items)))
         ) )
        )
  )
  (princ)
)
KozMos Inc.

Birdy

  • Guest
DCL (First 'crack' attempt)
« Reply #5 on: March 08, 2005, 11:33:00 AM »
Egzachary what I'm lookin for.  Many thanks!

Now I've got a bit to digest on this...hopefully it'll sink in.

Thanks again :)