Author Topic: Using Lee Macs block synchronization - Insert a block  (Read 1861 times)

0 Members and 1 Guest are viewing this topic.

jlogan02

  • Bull Frog
  • Posts: 327
Using Lee Macs block synchronization - Insert a block
« on: January 31, 2022, 12:49:24 PM »
I hate it when I go away for a while, it's like learning all over again. I'm looking at using Lee's List box synchronization example to insert blocks.

I'd have two list of blocks...

lst1: the insertion point is 0,0.
lst2: the other set user specified.

Code - Auto/Visual Lisp: [Select]
  1. ;; Note that $value is a string containing the index of the item
  2. ;; that the user has selected.
  3.  
  4.       (action_tile "lst2" "(setq *Insert* $value)")

My problem is understanding how to use $value while differentiating between insertion points.

Initially I thought it would be a simple

Code - Auto/Visual Lisp: [Select]
  1. (if....this lst...do this...
  2. (otherwise do this...

Mind you, that was before I came across this example.
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: Using Lee Macs block synchronization - Insert a block
« Reply #1 on: January 31, 2022, 12:53:07 PM »
Sorry forgot to include the second list image
J. Logan
ACAD 2018

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

Lee Mac

  • Seagull
  • Posts: 12920
  • London, England
Re: Using Lee Macs block synchronization - Insert a block
« Reply #2 on: January 31, 2022, 06:46:06 PM »
I've since developed a general purpose DCL List Tile Dependency function, which will allow you to control any number of inter-dependent DCL list tiles (e.g. list_boxes or popup_lists).

For your particular task, consider the following example program:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / *error* dch dcl des lst rtn )
  2.  
  3.     (defun *error* ( msg )
  4.         (if (= 'file (type des))
  5.             (close des)
  6.         )
  7.         (if (< 0 dch)
  8.             (unload_dialog dch)
  9.         )
  10.         (if (and (= 'str (type dcl)) (findfile dcl))
  11.             (vl-file-delete dcl)
  12.         )
  13.         (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
  14.             (princ (strcat "\nError: " msg))
  15.         )
  16.         (princ)
  17.     )
  18.  
  19.     (setq lst
  20.        '(
  21.             (
  22.                 "Static"
  23.                 (
  24.                     "Approval-NA-SL"
  25.                     "Approval-Schem-ACDC"
  26.                     "Approval-NA-PLO"
  27.                     "Approval-NA-ND"
  28.                     "Note_RemRet"
  29.                     "Note_RemOnly"
  30.                     "Note_RefOnly"
  31.                     "Note_RefDwgNum"
  32.                 )
  33.             )
  34.             (
  35.                 "User"
  36.                 (
  37.                     "Note_Rev_NewDwg"
  38.                     "Note_Rev_ExistDwg"
  39.                     "Note_Delta_Revision"
  40.                 )
  41.             )
  42.         )
  43.     )
  44.  
  45.     (if
  46.         (and
  47.             (setq dcl (vl-filename-mktemp "tmp.dcl"))
  48.             (setq des (open dcl "w"))
  49.             (foreach str
  50.                '(
  51.                     "lbx : list_box"
  52.                     "{"
  53.                     "    alignment = centered;"
  54.                     "    fixed_width = true;"
  55.                     "    fixed_height = true;"
  56.                     "    width = 30;"
  57.                     "    height = 15;"
  58.                     "}"
  59.                     "test : dialog"
  60.                     "{"
  61.                     "    label = \"Annotation\";"
  62.                     "    spacer;"
  63.                     "    : row"
  64.                     "    {"
  65.                     "        : lbx { key = \"lb0\"; label = \"Insert\"; }"
  66.                     "        : lbx { key = \"lb1\"; label = \"Annotation\"; }"
  67.                     "    }"
  68.                     "    spacer;"
  69.                     "    ok_cancel;"
  70.                     "}"
  71.                 )
  72.                 (write-line str des)
  73.             )
  74.             (not (setq des (close des)))
  75.             (< 0 (setq dch (load_dialog dcl)))
  76.             (new_dialog "test" dch)
  77.         )
  78.         (progn          
  79.             (setq rtn '(0 0))
  80.             (LM:dcld:action '("lb0" "lb1") 'lst 'rtn)
  81.             (if (= 1 (start_dialog))
  82.                 (princ
  83.                     (strcat "\nThe user selected:"
  84.                         (substr
  85.                             (apply 'strcat
  86.                                 (mapcar '(lambda ( x ) (strcat ", " x))
  87.                                     (LM:dcld:getitems rtn lst)
  88.                                 )
  89.                             )
  90.                             2
  91.                         )
  92.                     )
  93.                 )
  94.                 (princ "\n*Cancel*")
  95.             )
  96.         )
  97.     )
  98.     (*error* nil)
  99.     (princ)
  100. )

jlogan02

  • Bull Frog
  • Posts: 327
Re: Using Lee Macs block synchronization - Insert a block
« Reply #3 on: February 01, 2022, 07:39:00 PM »
Thanks Lee,

I think I understand this. Am I correct that I would place the ListTileDependencyV1-1.lsp in my support file and there it would stay unchanged? The code in this thread calls that lisp here...

Code - Auto/Visual Lisp: [Select]
  1.  (progn          
  2.             (setq rtn '(0 0))
  3.             (LM:dcld:action '("lb0" "lb1") 'lst 'rtn)...
....

then starts the dialog box and gets the users selection for "do stuff"?

Two questions?
What is the purpose of the "2" all by itself in the code.

Code - Auto/Visual Lisp: [Select]
  1. (progn          
  2.             (setq rtn '(0 0))
  3.             (LM:dcld:action '("lb0" "lb1") 'lst 'rtn)
  4.             (if (= 1 (start_dialog))
  5.                 (princ
  6.                     (strcat "\nThe user selected:"
  7.                         (substr
  8.                             (apply 'strcat
  9.                                 (mapcar '(lambda ( x ) (strcat ", " x))
  10.                                     (LM:dcld:getitems rtn lst)
  11.                                 )
  12.                             )
  13.                             2  ;;;????
  14.                         )
  15.                     )
  16.                 )
  17.                 (princ "\n*Cancel*")
  18.             )
  19.         )
  20.     )
  21.     (*error* nil)
  22.     (princ)
  23. )

Can I place my "insert code" in this file as a defun: below this code ?
 
J. Logan
ACAD 2018

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

Lee Mac

  • Seagull
  • Posts: 12920
  • London, England
Re: Using Lee Macs block synchronization - Insert a block
« Reply #4 on: February 02, 2022, 06:56:36 PM »
You're welcome  :-)

Am I correct that I would place the ListTileDependencyV1-1.lsp in my support file and there it would stay unchanged?

Yes, exactly this: the content of ListTileDependencyV1-1.lsp would remain unchanged throughout, you'll just need to ensure that the file is loaded in your active drawing session (such that the various functions are defined prior to calling them from your program).

What is the purpose of the "2" all by itself in the code.

Code - Auto/Visual Lisp: [Select]
  1. (progn          
  2.             (setq rtn '(0 0))
  3.             (LM:dcld:action '("lb0" "lb1") 'lst 'rtn)
  4.             (if (= 1 (start_dialog))
  5.                 (princ
  6.                     (strcat "\nThe user selected:"
  7.                         (substr
  8.                             (apply 'strcat
  9.                                 (mapcar '(lambda ( x ) (strcat ", " x))
  10.                                     (LM:dcld:getitems rtn lst)
  11.                                 )
  12.                             )
  13.                             2  ;;;????
  14.                         )
  15.                     )
  16.                 )
  17.                 (princ "\n*Cancel*")
  18.             )
  19.         )
  20.     )
  21.     (*error* nil)
  22.     (princ)
  23. )

The 2 is the starting character argument to the substr function, to remove the leading comma from the output printed to the command line. Though, depending on how you intend to use the user's selection from the dialog, you may wish to retain the selection in list format rather than converting it to a comma-delimited string and printing it to the command line (mine is purely an example to demonstrate the concept).

To use the selection as a list, consider changing this:
Code - Auto/Visual Lisp: [Select]
  1.             (if (= 1 (start_dialog))
  2.                 (princ
  3.                     (strcat "\nThe user selected:"
  4.                         (substr
  5.                             (apply 'strcat
  6.                                 (mapcar '(lambda ( x ) (strcat ", " x))
  7.                                     (LM:dcld:getitems rtn lst)
  8.                                 )
  9.                             )
  10.                             2
  11.                         )
  12.                     )
  13.                 )
  14.                 (princ "\n*Cancel*")
  15.             )

To something like:
Code - Auto/Visual Lisp: [Select]
  1.             (if (= 1 (start_dialog))
  2.                 (progn
  3.                     (setq rtn (LM:dcld:getitems rtn lst))
  4.                     ;;
  5.                     ;; do something
  6.                     ;;
  7.                 )
  8.                 (princ "\n*Cancel*")
  9.             )

Can I place my "insert code" in this file as a defun: below this code ?

You could potentially place your program within the same file, but it may be cleaner (and easier to maintain) if your program were to reside in a separate file - that's entirely dependent on how you wish to organise & maintain your AutoLISP library - there are pros and cons to each approach.

jlogan02

  • Bull Frog
  • Posts: 327
Re: Using Lee Macs block synchronization - Insert a block
« Reply #5 on: February 03, 2022, 11:52:55 AM »
Crystal clear as usual, Lee. Glad to see I understood the ListTileDependencyV1-1.lsp. I'll put this in startup so it's loaded automatically and ready to go.

I kept running up against your...

Code - Auto/Visual Lisp: [Select]
  1. (if (= 1 start dialog...

and saying to myself that's no different than what I'm used to doing...guess I should have actually tried rather than thinking I was wrong. We'll see how it goes from here.

Code - Auto/Visual Lisp: [Select]
  1. (if (= 1 (start_dialog))
  2.                 (progn
  3.                     (setq rtn (LM:dcld:getitems rtn lst))
  4.                     ;;
  5.                     ;; do something
  6.                     ;;
  7.                 )
  8.                 (princ "\n*Cancel*")
  9.             )

I wouldn't have gotten the setq statement, I would have never included the...

Code - Auto/Visual Lisp: [Select]
  1. LM:dcld:getitems

Thanks again.

J. Logan
ACAD 2018

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

Lee Mac

  • Seagull
  • Posts: 12920
  • London, England
Re: Using Lee Macs block synchronization - Insert a block
« Reply #6 on: February 03, 2022, 06:05:43 PM »
Excellent - good luck with the rest of the program, let me know if you need any more guidance.

jlogan02

  • Bull Frog
  • Posts: 327
Re: Using Lee Macs block synchronization - Insert a block
« Reply #7 on: February 04, 2022, 12:16:12 AM »
I can't seem to figure out how to differentiate between the two lists.

I can get all blocks to insert at 0,0 or there static position...I know I've written it wrong because the second setq is no different than the 1st setq, so I'm basically grabbing the same block in the list twice and running both commands on that selection.

I'm hung up on whether the first mouse pick in the box on the Insert side is the first pick and then the second pick on the annotation side is indeed the second pick...so

Code - Auto/Visual Lisp: [Select]
  1. car cdr ???


or is it

Code - Auto/Visual Lisp: [Select]

Code - Auto/Visual Lisp: [Select]
  1. (progn          
  2.             (setq rtn '(0 0))
  3.             (LM:dcld:action '("lb0" "lb1") 'lst 'rtn)
  4.             (if (= 1 (start_dialog))
  5.                 (progn
  6.                   (setq rtn (LM:dcld:getitems rtn lst))
  7.                   (setq dim (getvar 'dimscale))
  8.                   (setq ins (nth 1 rtn))                                               ;;missing something...need to differentiate between the Static & User lists
  9.                   (setq ins1 (nth 1 rtn))                                             ;;this is no different than "setq ins"
  10.                     (command "._insert" ins "0,0" dim dim "0")                 ;; Static insertion
  11.                     (command "._insert" ins1 pause dim dim "0")         ;; User insertion.
  12.                 ) ;;progn
  13.                 (princ "\n*Cancel*")
  14.             )
  15.           )
  16.         )
  17.    (*error* nil)
  18.     (princ)
  19. )
J. Logan
ACAD 2018

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

Lee Mac

  • Seagull
  • Posts: 12920
  • London, England
Re: Using Lee Macs block synchronization - Insert a block
« Reply #8 on: February 04, 2022, 01:28:09 PM »
You would use the first element of the list returned by the dialog, i.e. something like:
Code - Auto/Visual Lisp: [Select]
  1.                 (if (= 1 (start_dialog))
  2.                     (progn
  3.                         (setq rtn (LM:dcld:getitems rtn lst))
  4.                         (command "_.-insert" (cadr rtn) "_S" (getvar 'dimscale) "_R" 0.0)
  5.                         (if (= "Static" (car rtn))
  6.                             (command "_non" '(0 0))
  7.                             (command "\\")
  8.                         )
  9.                     )
  10.                     (princ "\n*Cancel*")
  11.                 )

glfiedler

  • Mosquito
  • Posts: 7
Re: Using Lee Macs block synchronization - Insert a block
« Reply #9 on: February 05, 2022, 02:59:44 PM »
Lee,
Once again you have provided an excellent mini-tutorial with your answers to the OP. I plan to use your "test" routine as a template for list DCL's.  Thank you also for providing the ListTileDependencyV1-1. Your work to help the community is greatly appreciated.

After looking at your "test" routine I have a question about the *error* routine.  It is a general question so I will start a new thread to keep this one clean.

Lee Mac

  • Seagull
  • Posts: 12920
  • London, England
Re: Using Lee Macs block synchronization - Insert a block
« Reply #10 on: February 06, 2022, 08:48:50 AM »
Thank you for your words of gratitude glfiedler, I'm delighted that the example also proved useful to others aside from the OP.

jlogan02

  • Bull Frog
  • Posts: 327
Re: Using Lee Macs block synchronization - Insert a block
« Reply #11 on: February 11, 2022, 11:24:20 AM »
Back to this. Thanks Lee for all your help.

Works as I envisioned.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:StampIns ( / *error* dch dcl des lst rtn ss )
  2.  
  3.     (defun *error* ( msg )
  4.         (if (= 'file (type des))
  5.             (close des)
  6.         )
  7.         (if (< 0 dch)
  8.             (unload_dialog dch)
  9.         )
  10.         (if (and (= 'str (type dcl)) (findfile dcl))
  11.             (vl-file-delete dcl)
  12.         )
  13.         (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
  14.             (princ (strcat "\nError: " msg))
  15.         )
  16.         (princ)
  17.     )
  18.  
  19.     (setq lst
  20.        '(
  21.             (
  22.                 "Static"
  23.                 (
  24.                     "Approval-NA-SL"
  25.                     "Approval-Schem-ACDC"
  26.                     "Approval-NA-PLO"
  27.                     "Approval-NA-ND"
  28.                     "Note_RemRet"
  29.                     "Note_RemOnly"
  30.                     "Note_RefOnly"
  31.                     "Note_RefDwgNum"
  32.                 )
  33.             )
  34.             (
  35.                 "User"
  36.                 (
  37.                     "Note_Rev_NewDwg"
  38.                     "Note_Rev_ExistDwg"
  39.                     "Note_Delta_Revision"
  40.                 )
  41.             )
  42.         )
  43.     )
  44.  
  45.     (if
  46.         (and
  47.             (setq dcl (vl-filename-mktemp "tmp.dcl"))
  48.             (setq des (open dcl "w"))
  49.             (foreach str
  50.                '(
  51.                     "lbx : list_box"
  52.                     "{"
  53.                     "    alignment = centered;"
  54.                     "    fixed_width = true;"
  55.                     "    fixed_height = true;"
  56.                     "    width = 30;"
  57.                     "    height = 15;"
  58.                     "}"
  59.                     "test : dialog"
  60.                     "{"
  61.                     "    label = \"Annotation\";"
  62.                     "    spacer;"
  63.                     "    : row"
  64.                     "    {"
  65.                     "        : lbx { key = \"lb0\"; label = \"Insert\"; }"
  66.                     "        : lbx { key = \"lb1\"; label = \"Annotation\"; }"
  67.                     "    }"
  68.                     "    spacer;"
  69.                     "    ok_cancel;"
  70.                     "}"
  71.                 )
  72.                 (write-line str des)
  73.             )
  74.             (not (setq des (close des)))
  75.             (< 0 (setq dch (load_dialog dcl)))
  76.             (new_dialog "test" dch)
  77.         )
  78.         (progn          
  79.             (setq rtn '(0 0))
  80.             (LM:dcld:action '("lb0" "lb1") 'lst 'rtn)
  81.             (setq Osm (getvar 'osmode))
  82.             (if (= 1 (start_dialog))
  83.                 (progn
  84.                   (setq rtn (LM:dcld:getitems rtn lst))
  85.                         (command "osmode" 1)
  86.                         (command "_.-insert" (cadr rtn) "_S" (getvar 'dimscale) "_R" 0.0)
  87.                         (if (= "Static" (car rtn))
  88.                             (command "_non" '(0 0))
  89.                             (command "\\")
  90.                         )
  91.                         (if (= "User" (car rtn))
  92.                             (command pause '(0 0))                                                        
  93.                             (command "\\")                    
  94.                         )
  95.                             (command "._explode" "l")
  96.                             (command "_textedit")
  97.                    )
  98.                )
  99.             (princ "\n*Cancel*")
  100.           )
  101.         )
  102.    (setvar 'osmode Osm)    
  103.    (*error* nil)
  104.     (princ)
  105. )

It's requiring an enter before running the textedit command, but that's small potatoes.

Thanks again for this. I can see other applications already with this your 2 routines as a starting point.

J.
J. Logan
ACAD 2018

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

Lee Mac

  • Seagull
  • Posts: 12920
  • London, England
Re: Using Lee Macs block synchronization - Insert a block
« Reply #12 on: February 12, 2022, 01:39:35 PM »
This expression shouldn't be required, as this is already catered by the else argument of the preceding if statement -
Code - Auto/Visual Lisp: [Select]
  1.                         (if (= "User" (car rtn))
  2.                             (command pause '(0 0))                                                        
  3.                             (command "\\")                    
  4.                         )

jlogan02

  • Bull Frog
  • Posts: 327
Re: Using Lee Macs block synchronization - Insert a block
« Reply #13 on: February 14, 2022, 01:47:21 PM »
That's weird, I'm almost sure I ran it without the if statement and it didn't work. Must have imagined that.

Thanks again, Lee.
J. Logan
ACAD 2018

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

Lee Mac

  • Seagull
  • Posts: 12920
  • London, England
Re: Using Lee Macs block synchronization - Insert a block
« Reply #14 on: February 16, 2022, 07:01:27 AM »
You're most welcome  :-)