Author Topic: DCL/LISP to insert block from list  (Read 3284 times)

0 Members and 1 Guest are viewing this topic.

sln8458

  • Mosquito
  • Posts: 18
DCL/LISP to insert block from list
« on: October 25, 2019, 10:40:18 AM »
Hi All,

I'm trying to create a dcl dialogue where I can select a button which then displays a list of block available to insert into the current drawing.
In this instance the blocks are 3d cable tray components.

I have created a DCL dialogue, a bit rough and ready, which has 4 columns of buttons + a 5th column for the list.
progress so far:


I am a complete novice here with many questions, but first off-
Is it possible to create a list to display in the final column such that when I select an item in the list and then select OK the item is inserted into the drawing?

Steve

dgorsman

  • Water Moccasin
  • Posts: 2422
Re: DCL/LISP to insert block from list
« Reply #1 on: October 25, 2019, 02:18:16 PM »
So you click a button, the list shows specific components, user picks one, and clicking OK prompts the user for an insert point, orientation, etc?  Yes, entirely possible.  Not quite click-click-done, plan it out first before writing any code, but doable.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Lee Mac

  • Seagull
  • Posts: 12379
  • London, England
Re: DCL/LISP to insert block from list
« Reply #2 on: October 25, 2019, 02:52:45 PM »
Rather than having four columns of identical buttons, you could have a single column of buttons and a separate set of radio buttons to determine the 'duty' of cable required.

BIGAL

  • Bull Frog
  • Posts: 457
  • 30 + years of using Autocad
Re: DCL/LISP to insert block from list
« Reply #3 on: October 25, 2019, 07:46:27 PM »
For me the old fashioned way a picture pick, this is using a menu very simple and slide images of your blocks, autocad does the coding for you, have a look at the image. Want more info just ask.



A man who never made a mistake never made anything

sln8458

  • Mosquito
  • Posts: 18
Re: DCL/LISP to insert block from list
« Reply #4 on: October 26, 2019, 02:38:16 AM »
Hi Guys,

I forgot to mention I use Intellicad.

dgorsman, thanks for that, didn't want to be chasing a lost cause.

LeeMac, I did consider that option, but felt that keeping it simple would allow me to copy/edit the code for the first column accross.

Bigal, yes I have done imagemenus before, also pop menus and toolbars, like this one


and this one



So to my first problem,
Can the righthand column be populated from a text file?
Can you point me to some reading matter where I can learn what I need to know?

Steve

BIGAL

  • Bull Frog
  • Posts: 457
  • 30 + years of using Autocad
Re: DCL/LISP to insert block from list
« Reply #5 on: October 26, 2019, 08:57:51 PM »
What I would look at is a dcl can have sub dcl like your menu so start with Type then it has the 6 types and the LIST box. yes can populate a list box from a file.
A man who never made a mistake never made anything

dgorsman

  • Water Moccasin
  • Posts: 2422
Re: DCL/LISP to insert block from list
« Reply #6 on: October 26, 2019, 11:04:52 PM »
Have a look at LISP functions for working with text files i.e. (open ...) and (read-line ...).  And of course (close ...).
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

sln8458

  • Mosquito
  • Posts: 18
Re: DCL/LISP to insert block from list
« Reply #7 on: October 27, 2019, 04:00:10 AM »
Thanks Guys.

As them man said 'I'll be back'  :-)

Steve

sln8458

  • Mosquito
  • Posts: 18
Re: DCL/LISP to insert block from list
« Reply #8 on: October 28, 2019, 12:34:27 PM »
Hi Guys,

I've searched the net and found heaps of info, thanks.
I have created both files in the first reply from 7o7 in this thread:
https://www.cadtutor.net/forum/topic/53921-list-box-generated-from-text-file/

---------------------------------------------------------
My Lisp file: listbox.lsp
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ()
  2.  (if (setq fname (findfile "test.txt"))
  3.    (progn
  4.      (setq file (open fname "r")
  5.     l nil)
  6.      (while (setq line (read-line file))
  7.        (setq l (append l (list line)))               ////I think this is not required for me as I am NOT adding to the txt file!! sln8458
  8.      )
  9.      (close file)
  10.      (setq i (load_dialog "listbox.dcl"))
  11.      (if (not (new_dialog "Example" i)) (exit))
  12.      (start_list "select")
  13.      (mapcar 'add_list l)
  14.      (end_list)
  15.    )
  16.  )
  17. )
---------------------------------------------------------
My DCL file: List box.dcl.
Code - DCL: [Select]
  1. Example : dialog {label = "Test Dialog ";
  2.   : list_box { label = "&Choose Section :";
  3.                         width = 30;
  4.                         height = 10;
  5.                         key = "select";
  6.                         multiple_select = true; }
  7.     ok_cancel;
  8.   }
--------------------------------------------------------

Typing 'test' at the command prompt gives me:


Steve


EDIT (John): Added code tags
« Last Edit: October 29, 2019, 09:49:48 AM by John Kaul (Se7en) »

sln8458

  • Mosquito
  • Posts: 18
Re: DCL/LISP to insert block from list
« Reply #9 on: October 28, 2019, 01:01:15 PM »
So now to integrate into my existing dcl/lsp files.

I've saved my dcl/lsp files to a pair of new files and reduced the dcl to one button and the list col:


Here are my current files:
---------------------------------------------------------
My fredsingle.dcl
Code - DCL: [Select]
  1. //
  2. // Revision:
  3. //  25 Oct  2019 - SLN
  4.  
  5. fredsingle : dialog {
  6.         label = "Steve's Cable Tray menu - LEGRAND";
  7.         : text {
  8.           label = "Revision A : October 2019";
  9.         }
  10.  
  11.         : row {
  12.                 children_alignment = top;
  13.                 :column {
  14.                 : boxed_column {
  15.                         label = "Light Duty Cable Tray";
  16.                         : button {
  17.                         key = "ld_tray_run";
  18.                         label = "Straight Tray Runs";
  19.                         }
  20.                         }
  21.                         }
  22.  
  23.                 :column {
  24.                         : list_box {
  25.                         label = "Choose Width Sizes (mm)";
  26.                         width = 25;
  27.                         height = 10;
  28.                         key = "select";
  29.                         }
  30.                         }
  31.                         }
  32.  
  33.         :row {
  34.                 fixed_width = true;
  35.                 alignment = centered;
  36.                 ok_cancel;
  37.                 }
  38.         }
-----------------------------------------------------
My fredsingle.lsp
Code - Auto/Visual Lisp: [Select]
  1. ; Revision: A
  2. ; 17 October 2017 SLN
  3. ;       sln - www.stylemarkdesigns.co.uk
  4. ;      
  5. (prompt "\nType FREDSINGLE to run...")
  6.  
  7. (defun C:fredsingle ()
  8. (setq dcl_id (load_dialog "fredsingle.dcl"))
  9.      (if (not (new_dialog "fredsingle" dcl_id))
  10.          (exit )
  11.      );if
  12.  (action_tile "accept"
  13.     "(done_dialog)"
  14. );action_tile
  15.  
  16. (unload_dialog dcl_id)
  17. );defun
  18.  
  19. ;;;; load *.txt files
  20.  
  21. (defun c:ld_tray_run ()                                                            /// "ld_tray_run.txt" matches the 'key' in the dcl button above
  22.  (if (setq fname (findfile "ld_tray_run.txt"))                             /// "ld_tray_run.txt" matches the 'key' in the dcl button above
  23.    (progn
  24.      (setq file (open fname "r")
  25.     l nil)
  26.      (while (setq line (read-line file))
  27.        (setq l (append l (list line)))
  28.      )
  29.      (close file)
  30.      (setq i (load_dialog "listbox.dcl"))                                   /// this is refering to the listbox dcl file where as my dcl file
  31.      (if (not (new_dialog "Example" i)) (exit))                        /// is called earlier in the lsp file
  32.      (start_list "select")                                                         ///
  33.      (mapcar 'add_list l)                                                        ///
  34.      (end_list)                                                                       ///
  35.    )
  36.  )
  37. )

----------------------------------------------------------

So I'm confused, and I'm also sure you guys are not surprised at this, however
How do I call my '.txt. file (ld_tray_run.txt) to fill the righthand column?

Again, I'm happy to read if you have any suggested reading
.

Steve



EDIT (John): Added code tags.
« Last Edit: October 29, 2019, 09:48:29 AM by John Kaul (Se7en) »

roy_043

  • Water Moccasin
  • Posts: 1783
  • BricsCAD 18
Re: DCL/LISP to insert block from list
« Reply #10 on: October 28, 2019, 02:42:39 PM »
Accuracy is very important when writing a program.
In your ld_tray_run function the DCL filename and the name of the dialog seem incorrect.

3 other things:
"//" is not used to indicate comments in LSP.
Indent your code properly. It will improve the readability of your code for yourself and others.
Please use code tags in your posts (the # button above the text field).

Dlanor

  • Bull Frog
  • Posts: 230
Re: DCL/LISP to insert block from list
« Reply #11 on: October 28, 2019, 03:42:41 PM »
You have no action tile for your button. This should reference the code to create the list that will populate the list box (if you are going to have more than one button). You are also not collecting anything that you choose from your dcl so you will also need an action tile for the list tile.

Just type dcl into the search box top right of the home page.

BIGAL

  • Bull Frog
  • Posts: 457
  • 30 + years of using Autocad
Re: DCL/LISP to insert block from list
« Reply #12 on: October 29, 2019, 03:12:07 AM »
This my attempt this is full code required. You can have the choice horizontal or vertical. When you pick the dcl closes so no actual need for Ok. It remembers last pick so can do a ok next time.

Code: [Select]
(if (not AH:Butts)(load "Multi Radio buttons.lsp"))
(if (not AHlstbox)(load "Listbox-AH.lsp"))
(if (= but nil)(setq but 1))
(setq ans (ah:butts but "v"  '("Steves cable tray" "Ligth duty " "Medium duty" "heavy duty" "Extra heavy")))
(setq ans2 (ah:butts but "V"  '("Steves cable tray" "Straight Run" "Flat elbow 90" "Equal Tee" "reducing tee" "Straight reducer")))
(setq ans3 (ahlstbox "Pick size" (list "size1"  "size 2"  "size 3" "size 4") 20 10))

« Last Edit: October 29, 2019, 03:15:11 AM by BIGAL »
A man who never made a mistake never made anything

sln8458

  • Mosquito
  • Posts: 18
Re: DCL/LISP to insert block from list
« Reply #13 on: October 30, 2019, 07:36:06 AM »
Thanks Guys for your help and comments, all are appreciated.

Unfortunately I will have to put this on hold for a little while as new work has come in, and as that pays the bills this project will have to go on hold for a little while.

SteveN

anhquang1989

  • Newt
  • Posts: 69
Re: DCL/LISP to insert block from list
« Reply #14 on: October 31, 2019, 03:24:07 PM »
Something similar if you don't have time with it

https://www.facebook.com/331540167279943/posts/793062771127678?sfns=mo