Author Topic: ListTileDependencyV1-1.lsp second attempt  (Read 1425 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 327
ListTileDependencyV1-1.lsp second attempt
« on: June 13, 2022, 06:32:33 PM »
The code below uses a dos_listbox to enable the user to select the dimstyle and begin an ordinate dimension.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:DimOrd ( / *error* osm dim dim1 dimcol clay)
  2.  (defun *error* (msg)
  3.     (if osm
  4.       (setvar 'osmode osm)
  5.     )
  6.     (if (not (member msg '("Function cancelled" "quit / exit abort")))
  7.       (princ (strcat "\nError: " msg))
  8.     )
  9.     (princ)
  10.   )
  11.  
  12.   (setvar 'osmode 0)
  13.   (setvar 'cmdecho 0)
  14.   (setq clay (getvar "clayer"))
  15.   (setvar "clayer" "DIMEN")
  16.   (setq dim1 (getvar "dimscale"))
  17.    
  18.   (setq dimcol
  19.         (dos_listbox
  20.                "Dimension"
  21.                "Choose Color"
  22.                '("PANEL_BOX"
  23.            "PANEL_BOX_001"
  24.            "MODD"
  25.                       )
  26.               )
  27.   )
  28.  
  29.     (command "cecolor" "bylayer")
  30.     (setq dim (getvar 'dimscale))
  31.     (command "-dimstyle" "R" dimcol)
  32.     (command "dimscale" dim1)
  33.     (command "DIMORDINATE")
  34.      
  35.  
  36.   (while (< 0 (getvar 'cmdactive)) ;; While the command is active, pause
  37.          (command "\\") ;; Pause for user input
  38.      ) ;; end WHILE |;
  39.    
  40.    (command "cecolor" "red")
  41.    (setvar 'osmode 1)
  42.    (setvar 'cmdecho 1)
  43.    (setvar "clayer" clay)
  44.    
  45.   (princ)
  46.  
  47. )

I want to updated to use Lee Mac's listdependency where the user would pick either DimOrdinate or DimLinear and then choose from a list of available dimstyles to begin dimensioning.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:OrdLinDim ( / *error* UpdateList data dclfile dclhandle )
  2.  
  3.   ;; This program demonstrates how to update a secondary list_box based
  4.   ;; on user selection from a primary list_box.
  5.  
  6.   ;; Example courtesy of Lee Mac © 2010 (www.lee-mac.com)
  7.  
  8.   ;; Accompanying DCL File:
  9.  
  10.   (setq dclFile "OrdLinDim_ColDia.dcl")
  11.  
  12.   ;; Ensure this file resides in an AutoCAD Support Path
  13.  
  14.   (defun *error* ( msg )
  15.  
  16.     ;; Error Handler - will unload the dialog
  17.     ;; from memory should the user decide to hit Esc
  18.  
  19.     (if dclHandle (unload_dialog dclHandle))
  20.     (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
  21.         (princ (strcat "\n** Error: " msg " **")))
  22.     (princ)
  23.   )
  24.  
  25.   (defun UpdateList ( key lst )
  26.  
  27.     ;; This function updates the list_box associated with the specified key
  28.     ;; using the contents of the supplied lst
  29.  
  30.     (start_list key)
  31.     (mapcar 'add_list lst)
  32.     (end_list)
  33.   )
  34.  
  35.   ;; Data used to Populate List_Boxes:
  36.   ;; I've chosen to use this list structure because it suits the data,
  37.   ;; but there are many other possibilities.
  38.  
  39.   (setq Data
  40.    '(
  41.      ("DimLinear"   ("BLDG_" "BLDG_001" "BLDG_015" "BLDG_150" "PANEL_BOX" "PANEL_BOX_001" "PANEL_BOX_015" "PANEL_BOX_150"))
  42.      ("DimOrdinate" ("MODD" "PANEL_BOX" "PANEL_BOX_001" "PANEL_BOX_015" "PANEL_BOX_150"))
  43.          )
  44.   )
  45.  
  46.   ;; Start of Main Routine
  47.   ;; Lots of Error Trapping to make sure the Dialog Loads:
  48.  
  49.   (cond
  50.     ( (<= (setq dclHandle (load_dialog dclFile)) 0)
  51.  
  52.       (princ "\n--> DCL File not Found.")
  53.     )
  54.     ( (not (new_dialog "OrdLinDim_ColDia" dclHandle))
  55.  
  56.       (setq dclHandle (unload_dialog dclHandle))
  57.       (princ "\n--> Dialog Definition not Found.")
  58.     )
  59.     ( t
  60.       ;; Dialog Loaded Successfully.
  61.  
  62.       (or *Dstyle*  (setq *DStyle*  "0"))
  63.       (or *DType* (setq *DType* "0"))
  64.  
  65.       ;; Set up some default selections, for the first-time running of the program.
  66.       ;; The variables *Insert* & *Annonation* are intended to be global and hence will
  67.       ;; remember the user's last selections.
  68.  
  69.       ;; Populate the List_Boxes:
  70.  
  71.       ;; List_Box 'lst1'
  72.      
  73.       (UpdateList "lst1" (mapcar 'car data))
  74.       (set_tile "lst1" *DStyle*)
  75.  
  76.       ;; List_Box 'lst2'
  77.  
  78.       (UpdateList "lst2" (cadr (nth (atoi *DType*) Data)))
  79.       (set_tile "lst2" *DStyle*)
  80.  
  81.       ;; Action_tile Statements:
  82.       ;; These control what happens when the user interacts with a tile in the dialog.
  83.  
  84.       (action_tile "lst1"
  85.         (strcat
  86.           "(UpdateList \"lst2\" (setq lst2 (cadr (nth (atoi (setq *DStyle* $value)) Data))))"
  87.           "(setq *DStyle*"
  88.           "(set_tile \"lst2\""
  89.           "    (if (< (atoi *DStyle*) (length lst2)) *DStyle* \"0\")" ;;
  90.             ")"
  91.           ")"
  92.         )
  93.       )
  94.      
  95.       ;;(setvar "Clayer" "DIMEN")
  96.       ;;(setq dim1 (getvar 'dimscale))
  97.       ;;(command "cecolor" "bylayer")
  98.       ;;(setq dim (getvar 'dimscale))
  99.       ;;(command "-dimstyle" "R" Dstyle)
  100.       ;;(command "dimscale" dim1)
  101.       ;;(command "DIMORDINATE")
  102.      
  103.        ;;(while (< 0 (getvar 'cmdactive)) ;; While the command is active, pause
  104.         ;; (command "\\") ;; Pause for user input
  105.     ;; ) ;; end WHILE |;
  106.      
  107.      
  108.  
  109.       ;; Here, when the user selects an item from 'lst1', the UpdateList subfunction
  110.       ;; is fired to update the items in list_box 'lst2'.
  111.  
  112.       ;; list_box 'lst2' is also set to the value of *DStyle* if the index is
  113.       ;; available for the selected item, else the first item is selected.
  114.  
  115.       ;; Note that $value is a string containing the index of the item
  116.       ;; that the user has selected.
  117.  
  118.       (action_tile "lst2" "(setq *DStyle* $value)")
  119.    
  120.  
  121.       ;; Dialog setup, lets start it:
  122.       (start_dialog)
  123.       (setq dclHandle (unload_dialog dclHandle))
  124.     )
  125.    )
  126.   (princ)
  127. )
  128.  
  129.  

Code - Auto/Visual Lisp: [Select]
  1. // DCL File to be saved as listboxexample.dcl
  2. // Example courtesy of Lee Mac © 2010 (www.lee-mac.com)
  3. // Modified dialog name 01/28/2022
  4.  
  5. lbox : list_box { width = 25; fixed_width = true; alignment = centered; }
  6.  
  7. OrdLinDim_ColDia : dialog { label ="Dimension Styles"; spacer;
  8.   : row {
  9.     : lbox { key = "lst1"; label = "DType";}
  10.     : lbox { key = "lst2"; label = "DStyle"; }
  11.   }
  12.   ok_only;
  13. }

J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: ListTileDependencyV1-1.lsp second attempt
« Reply #1 on: June 13, 2022, 08:33:50 PM »
Not sure does it work or are you posting an example ?

Here is another way uses a library lisp, Multi getvals can simply make a list to use.

Code: [Select]
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(setq ans (ah:butts 1 "v"  '("Choose Dim " "DimLinear"  "DimOrdinate")))
(cond
((= ans "DimLinear")(setq ans2 (ah:butts 1 "v"  '("Choose Dim style" "BLDG_" "BLDG_001" "BLDG_015" "BLDG_150" "PANEL_BOX" "PANEL_BOX_001" "PANEL_BOX_015" "PANEL_BOX_150"))))
((= ans "DimOrdinate")(setq ans2 (ah:butts 1 "v"  '("Choose Dim style" "MODD" "PANEL_BOX" "PANEL_BOX_001" "PANEL_BOX_015" "PANEL_BOX_150"))))
)


« Last Edit: June 13, 2022, 08:37:40 PM by BIGAL »
A man who never made a mistake never made anything

jlogan02

  • Bull Frog
  • Posts: 327
Re: ListTileDependencyV1-1.lsp second attempt
« Reply #2 on: June 14, 2022, 11:28:02 AM »
Sorry that wasn't very clear. It's not working as is because I can't seem to figure out how to work in the command structure for the action tile.

I'm making the assumption that commented section with the setvar/getvars and commands replaces some portion of the (if...statement.

Code - Auto/Visual Lisp: [Select]
  1. (action_tile "lst1"
  2.         (strcat
  3.           "(UpdateList \"lst2\" (setq lst2 (cadr (nth (atoi (setq *DStyle* $value)) Data))))"
  4.           "(setq *DStyle*"
  5.           "(set_tile \"lst2\""
  6.           "    (if (< (atoi *DStyle*) (length lst2)) *DStyle* \"0\")" ;;
  7.             ")"
  8.           ")"
  9.         )
  10.       )
  11.      
  12.       ;;(setvar "Clayer" "DIMEN")
  13.       ;;(setq dim1 (getvar 'dimscale)) ;; updated removed second instance of getvar dimscale in OP
  14.       ;;(command "cecolor" "bylayer")
  15.       ;;(command "-dimstyle" "R" Dstyle)
  16.       ;;(command "dimscale" dim1)
  17.       ;;(command "DIMORDINATE")
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

jlogan02

  • Bull Frog
  • Posts: 327
Re: ListTileDependencyV1-1.lsp second attempt
« Reply #3 on: June 14, 2022, 01:08:59 PM »
Not sure does it work or are you posting an example ?

Here is another way uses a library lisp, Multi getvals can simply make a list to use.

Code: [Select]
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(setq ans (ah:butts 1 "v"  '("Choose Dim " "DimLinear"  "DimOrdinate")))
(cond
((= ans "DimLinear")(setq ans2 (ah:butts 1 "v"  '("Choose Dim style" "BLDG_" "BLDG_001" "BLDG_015" "BLDG_150" "PANEL_BOX" "PANEL_BOX_001" "PANEL_BOX_015" "PANEL_BOX_150"))))
((= ans "DimOrdinate")(setq ans2 (ah:butts 1 "v"  '("Choose Dim style" "MODD" "PANEL_BOX" "PANEL_BOX_001" "PANEL_BOX_015" "PANEL_BOX_150"))))
)




This seems to work out well. The dimstyles change to the user selected style, I'm not able to change from a linear dimension to a ordinate dimension when selecting either. It defaults to dimordinate every time, regardless of first selection.

EDITED:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:lcol ( / dim )
  2. (if (not AH:Butts)(load "Multi Radio buttons.lsp"))
  3. (setq ans (ah:butts 1 "v"  '("Choose Dim " "DimLinear"  "DimOrdinate")))
  4. ((= ans "DimLinear")(setq ans2 (ah:butts 1 "v"  '("Choose Dim style" "BLDG_" "BLDG_001" "BLDG_015" "BLDG_150" "PANEL_BOX" "PANEL_BOX_001" "PANEL_BOX_015" "PANEL_BOX_150"))))
  5. ((= ans "DimOrdinate")(setq ans2 (ah:butts 1 "v"  '("Choose Dim style" "MODD" "PANEL_BOX" "PANEL_BOX_001" "PANEL_BOX_015" "PANEL_BOX_150"))))
  6. )
  7.   (setvar "Clayer" "DIMEN")
  8.   (setq dim (getvar 'dimscale))
  9.   (command "-dimstyle" "R" ans2)
  10.   (command "dimscale" dim)
  11.   (if ( = (strcase ans2) "dimlinear")
  12.      (command "_dimlinear")
  13.      (command "DimOrdinate")
  14.   ;;)
  15.  
  16.  
  17.   (while (< 0 (getvar 'cmdactive)) ;; While the command is active, pause
  18.          (command "\\") ;; Pause for user input
  19.      ) ;; end WHILE |;
  20.  
  21.   (princ)
  22. )
« Last Edit: June 14, 2022, 05:28:07 PM by jlogan02 »
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: ListTileDependencyV1-1.lsp second attempt
« Reply #4 on: June 14, 2022, 08:49:19 PM »
Ok to not confuse you can change the default button selected to always be the last selected so when doing again just click OK.

Code: [Select]
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (= but1 nil)(setq but1 1))
(if (= but2 nil)(setq but2 1))
(setq ans (ah:butts but1 "v"  '("Choose Dim " "DimLinear"  "DimOrdinate")) but1 but)
(cond
((= ans "DimLinear")(setq ans2 (ah:butts but2 "v"  '("Choose Dim style" "BLDG_" "BLDG_001" "BLDG_015" "BLDG_150" "PANEL_BOX" "PANEL_BOX_001" "PANEL_BOX_015" "PANEL_BOX_150")) but2 but))
((= ans "DimOrdinate")(setq ans2 (ah:butts but2 "v"  '("Choose Dim style" "MODD" "PANEL_BOX" "PANEL_BOX_001" "PANEL_BOX_015" "PANEL_BOX_150")) but2 but))
)

change multi radio buttons.lsp
Code: [Select]
; (set_tile "Rb1" "1")
(set_tile (strcat "Rb"  (rtos ahdef 2 0) ) "1")
[code]
A man who never made a mistake never made anything

jlogan02

  • Bull Frog
  • Posts: 327
Re: ListTileDependencyV1-1.lsp second attempt
« Reply #5 on: June 15, 2022, 10:59:31 AM »
Success!! Thanks BigAl.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Dimcol ( / dim ans )
  2. (if (not AH:Butts)(load "Multi Radio buttons.lsp"))
  3. (setq ans (ah:butts 1 "v"  '("Choose Dim " "DimLinear"  "DimOrdinate")) but1 but)
  4. ((= ans "DimLinear")(setq ans2 (ah:butts 2 "v"  '("Choose Dim style" "BLDG_" "BLDG_001" "BLDG_015" "BLDG_150" "PANEL_BOX" "PANEL_BOX_001" "PANEL_BOX_015" "PANEL_BOX_150"))))
  5. ((= ans "DimOrdinate")(setq ans2 (ah:butts 2 "v"  '("Choose Dim style" "MODD" "PANEL_BOX" "PANEL_BOX_001" "PANEL_BOX_015" "PANEL_BOX_150"))))
  6. )
  7.   (setvar "Clayer" "DIMEN")
  8.   (setq dim (getvar 'dimscale))
  9.   (command "-dimstyle" "R" ans2)
  10.   (command "dimscale" dim)
  11.   (if (= (strcase ans) "DimLinear")
  12.      (command ans)
  13.      (command ans)
  14.   )    
  15.    
  16.   (while (< 0 (getvar 'cmdactive)) ;; While the command is active, pause
  17.          (command "\\") ;; Pause for user input
  18.      ) ;; end WHILE |;
  19.  
  20.   (princ)
  21. )
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

jlogan02

  • Bull Frog
  • Posts: 327
Re: ListTileDependencyV1-1.lsp second attempt
« Reply #6 on: June 15, 2022, 12:50:45 PM »
Expanded routine to include a 3rd selection...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Dimcol ( / dim ans )
  2. (if (not AH:Butts)(load "Multi Radio buttons.lsp"))
  3. (setq ans (ah:butts 1 "v"  '("Choose Dim " "DimLinear"  "DimOrdinate" "DimAligned")) but1 but )
  4. ((= ans "DimLinear")(setq ans2 (ah:butts 2 "v"  '("Choose Dim style" "BLDG_" "BLDG_001" "BLDG_015" "BLDG_150" "PANEL_BOX" "PANEL_BOX_001" "PANEL_BOX_015" "PANEL_BOX_150"))))
  5. ((= ans "DimOrdinate")(setq ans2 (ah:butts 2 "v"  '("Choose Dim style" "MODD" "PANEL_BOX" "PANEL_BOX_001" "PANEL_BOX_015" "PANEL_BOX_150"))))
  6. ((= ans "DimAligned")(setq ans2 (ah:butts 2 "v"  '("Choose Dim style" "BLDG_" "BLDG_001" "BLDG_015" "BLDG_150" "PANEL_BOX" "PANEL_BOX_001" "PANEL_BOX_015" "PANEL_BOX_150"))))
  7. )
  8.   (setvar "Clayer" "DIMEN")
  9.   (setq dim (getvar 'dimscale))
  10.   (command "-dimstyle" "R" ans2)
  11.   (command "dimscale" dim)
  12.   (cond
  13.     ((= ans "DimLinear")
  14.      (command ans)
  15.   )
  16.  
  17.   ((= ans "DimOrdinate")
  18.      (command ans)
  19.   )
  20.  
  21.   ((= ans "DimAligned")
  22.      (command ans)
  23.   )
  24.   )
  25.      
  26.   (while (< 0 (getvar 'cmdactive)) ;; While the command is active, pause
  27.          (command "\\") ;; Pause for user input
  28.      ) ;; end WHILE |;
  29.  
  30.   (princ)
  31. )
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: ListTileDependencyV1-1.lsp second attempt
« Reply #7 on: June 15, 2022, 07:42:39 PM »
Glad to see you can use it, that was the idea have only a few lines of code calling a saved lisp file, just change your list to suit. Its only limited to the screen size I think its in this version it will compress the line spacing when you have lots of choices.

There is MULTI GETVALS, MULTI TOGGLES and MULTI RADIO 2 cols, Multi getvals with image these are available also.

I am looking at replacing Multi radio buttons with a version that just makes the columns to suit how many lists you need. 1-?

PS do you need cond all answers use (command ans)

Code: [Select]
  (command "-dimstyle" "R" ans2)
  (command "dimscale" dim)
  (command "dimscale" (getvar 'dimscale))
  (command ans)
« Last Edit: June 15, 2022, 07:47:30 PM by BIGAL »
A man who never made a mistake never made anything

jlogan02

  • Bull Frog
  • Posts: 327
Re: ListTileDependencyV1-1.lsp second attempt
« Reply #8 on: June 17, 2022, 12:15:47 PM »
Glad to see you can use it, that was the idea have only a few lines of code calling a saved lisp file, just change your list to suit. Its only limited to the screen size I think its in this version it will compress the line spacing when you have lots of choices.

There is MULTI GETVALS, MULTI TOGGLES and MULTI RADIO 2 cols, Multi getvals with image these are available also.

I am looking at replacing Multi radio buttons with a version that just makes the columns to suit how many lists you need. 1-?

PS do you need cond all answers use (command ans)

Code: [Select]
  (command "-dimstyle" "R" ans2)
  (command "dimscale" dim)
  (command "dimscale" (getvar 'dimscale))
  (command ans)

I hadn't considered that I didn't need Cond. I must be misunderstanding it's use. I'll give it a look, thanks.

I came to the conclusion that I needed from here...
http://www.theswamp.org/index.php?topic=13046.msg158557#msg158557
I omitted the case for ( T
Overthinking it maybe.

Code - Auto/Visual Lisp: [Select]
  1.   ((= 1 0)
  2.     none of this will get executed
  3.     because the conditions is false
  4.   ) ; end cond 1
  5.  
  6.   ((= 1 1)
  7.      do all of this because it is true
  8.      and this
  9.      and this
  10.    ) ; end cond 2
  11.  
  12.    ((= 2 2)
  13.      none of this will get
  14.      executed even if it is true
  15.      because the prior stmt was true
  16.    ) ; end cond 3
  17.  
  18.    (T
  19.      This is often placed at the last position
  20.      in a condition statement and will be executed
  21.      if all the prior conditions are false
  22.      if any one of the above conditions are true
  23.       this will not be executed
  24.    ) ; end cond 4
  25. ) ; end cond stmt

The other day you had me change this...

Code - Auto/Visual Lisp: [Select]
  1. ; (set_tile "Rb1" "1")
  2. (set_tile (strcat "Rb"  (rtos ahdef 2 0) ) "1")
  3.  

in the Multi Radios Button.lsp
Is that a permanent change to that file or is it specific to use with my code?
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: ListTileDependencyV1-1.lsp second attempt
« Reply #9 on: June 17, 2022, 09:59:57 PM »
The change will work ok in future use. I have changed my version to this.

(ah:butts 1 "V"   '("A B C D " "A" "B" "C" "D" ))) the 1 will force the 1st radio button to be selected.
(ah:butts ahdef "V"   '("A B C D " "A" "B" "C" "D" ))) this will select the last selected button used where (setq ahdef but) the but value is returned as picked button.

NOTE if using ahdef you need the (if (= ahdef nil)(setq ahdef 1)) in the multi radio as well.

Same can use "V" or "H" vertical, horizontal. A horizontal would be like Yes No.

A man who never made a mistake never made anything

jlogan02

  • Bull Frog
  • Posts: 327
Re: ListTileDependencyV1-1.lsp second attempt
« Reply #10 on: June 21, 2022, 11:53:51 AM »
Thanks BigAl. Much appreciated
J. Logan
ACAD 2018

I am one with the Force and the Force is with me.
AutoCAD Map 2018 Windows 10