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

0 Members and 1 Guest are viewing this topic.

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
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
There is no such  thing as a 'silly question' to those who do not know!

dgorsman

  • Water Moccasin
  • Posts: 2437
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: 12905
  • 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

  • Swamp Rat
  • Posts: 1396
  • 40 + 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

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
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
There is no such  thing as a 'silly question' to those who do not know!

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + 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: 2437
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

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
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
There is no such  thing as a 'silly question' to those who do not know!

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
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) »
There is no such  thing as a 'silly question' to those who do not know!

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
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) »
There is no such  thing as a 'silly question' to those who do not know!

roy_043

  • Water Moccasin
  • Posts: 1895
  • 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: 263
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

  • Swamp Rat
  • Posts: 1396
  • 40 + 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

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
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
There is no such  thing as a 'silly question' to those who do not know!

anhquang1989

  • Newt
  • Posts: 74
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

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: DCL/LISP to insert block from list
« Reply #15 on: October 31, 2019, 07:31:33 PM »
Just post the sizes as text here and what the matching block names look like as final result, just a couple per selection is ok.

Its almost there should be easy to finish off as a insert.
A man who never made a mistake never made anything

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: DCL/LISP to insert block from list
« Reply #16 on: June 12, 2020, 06:26:39 AM »
Hi All,

Well I'm back :uglystupid2:

It's been a while, but I had quite a bit of work come in, I'm self employed, so this project had to take a back seat.
Unfortunately, due to the virus outbreak, work has dried up! but that does mean I can get back to this. Sorry guys.

@Bigal, I tried to send you a pm, not sure if it arrived?

Back to this (recap):



Code - Auto/Visual Lisp: [Select]
  1. label = "Light Duty Cable Tray";
  2.                         : button {
  3.                         key = "ldct1";
  4.                         label = "Straight Tray Runs";

I have a txt file that I want to display in the list box above when the 'straight tray runs' button is selected. Then when a selection is made from the list an associated block is inserted.



In the above the txt file is loaded automatically via the lsp file
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)))
  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. )

For now I have 2 questions
1/ How do I call the list? (all the search results I have found have the list contained within the lsp file not a separate txt file)
2/ Can/should the txt file contain the filename of the block to insert?

SteveN
There is no such  thing as a 'silly question' to those who do not know!

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: DCL/LISP to insert block from list
« Reply #17 on: June 12, 2020, 10:10:18 PM »
The list can be a file or a list in code.

The easy way around this is to make a list with two answers per item
((Displayname Actualname)(Displayname Actualname)(Displayname Actualname)(Displayname Actualname))

Using a repeat you make the dcl "l" by (nth 0 (nth (setq x (- x 1)) lst)) this makes a list of display names.

When the dcl finishes it will return possibly a number = the position in the dcl list so say it returns 2, then (nth 1 (nth 2 lst)) will be block name. Not checked may need num - 1.

I would make the file a csv file displayname, actualname this can be read easy and make you the list. Something like this.

Code: [Select]
(defun _csv->lst ( str / pos )
(if (setq pos (vl-string-position 44 str))
(cons (substr str 1 pos) (_csv->lst (substr str (+ pos 2))))
(list str)
    )
)


(setq lst '())
(while (setq newline (read-line fname))
(setq newlst ( _csv->lst newline))
(setq lst (cons newlst lst))
)

Just keep asking for help its good to see your having a go. Start with the csv file.

Rlx over at Cadtutor is very good at dcl's so may ask for help. Should be able to click as a toggle populate correct list, you need more options but only 1 list box in dcl.

« Last Edit: June 12, 2020, 10:16:32 PM by BIGAL »
A man who never made a mistake never made anything

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: DCL/LISP to insert block from list
« Reply #18 on: June 14, 2020, 04:22:59 AM »
Thanks Bigal,

The csv should be simple enough, though I do have one question relating to format.
That is do I use 2 columns:
LD-75mm  3mtr   LD-75mm-tray-run-3000.dwg
LD-100mm 3mtr   LD-100mm-tray-run-3000.dwg
LD-150mm 3mtr   LD-150mm-tray-run-3000.dwg
LD-200mm 3mtr   LD-200mm-tray-run-3000.dwg

OR

One row:
LD-75mm  3mtr   LD-75mm-tray-run-3000.dwg   LD-100mm 3mtr   LD-100mm-tray-run-3000.dwg  LD-150mm 3mtr   LD-150mm-tray-run-3000.dwg  LD-200mm 3mtr   LD-200mm-tray-run-3000.dwg

SteveN

There is no such  thing as a 'silly question' to those who do not know!

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: DCL/LISP to insert block from list
« Reply #19 on: June 16, 2020, 09:36:27 PM »
You don't need the 2 items as you are using the short version to pick from dcl list but read the 2nd item after closing the dcl for the block name from the master list.

Will try to find some time to do an example. I use a list select method by Alan Thompson it returns the value picked as a list. So I picked "200" the dwgname returned "200xd"

Code: [Select]
(setq alst (list (list "100" "100xd") (list "200" "200xd")(list "300" "300xd")))
(setq lst2 '())
(foreach item alst
(setq lst2 (cons (car item) lst2))
)
(setq lst2 (reverse lst2))

(setq ans (AT:ListSelect "title" "label" 25 30 "false" lst2))
(setq x 0)
(foreach item alst
(if (= (car ans)(car item))
(setq dwgname (cadr (nth x alst)))
(setq x (+ x 1))
)
)

« Last Edit: June 16, 2020, 10:04:41 PM by BIGAL »
A man who never made a mistake never made anything

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: DCL/LISP to insert block from list
« Reply #20 on: June 19, 2020, 10:41:41 AM »
Hi Bigal,

My preference is to keep the list as a list, as I want to keep the list in a file that I feel more comfortable editing.

I have managed to get the list displayed into the DCL listbox:


The text file for the list is formatted:
("LD-75mm     Straight Run  3mtr" LD-75mm-tray-run-3000).
where  LD-75mm-tray-run-3000 is the name of the dwg to insert.

I have been 'loosely' following the 'wisey steel shapes' files, apologies if that offends anyone :opps:

So now to capturing the dwg name and pass this over to the insert command.
(command "-insert" "name" pt 1 1 0) ?

There is no such  thing as a 'silly question' to those who do not know!

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: DCL/LISP to insert block from list
« Reply #21 on: June 25, 2020, 04:16:49 AM »
Morning Guys,

This is my attempt at capturing the filename from the list and then inserting the block.
But it doesn't work.

Any pointers please.

Code: [Select]
(defun
   INSERT_BLOCK ()
   (setq
    DGN  (nth 1 SIZE_DIMS)
  ) ;end setq
    (command "._-insert" DGN pt 1 1 0
 ) ;_ end of command
There is no such  thing as a 'silly question' to those who do not know!

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: DCL/LISP to insert block from list
« Reply #22 on: June 25, 2020, 05:52:55 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.
Is this DCl yours or what?

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: DCL/LISP to insert block from list
« Reply #23 on: June 26, 2020, 02:39:54 AM »
Quote
Is this DCl yours or what?

This one?

Yes
There is no such  thing as a 'silly question' to those who do not know!

HasanCAD

  • Swamp Rat
  • Posts: 1420
Re: DCL/LISP to insert block from list
« Reply #24 on: June 26, 2020, 03:28:18 AM »
Quote
Is this DCl yours or what?

This one?

Yes

This one


sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: DCL/LISP to insert block from list
« Reply #25 on: June 26, 2020, 03:36:17 AM »
That one is by BIGAL in post#3
My one in post #4 is similar.
There is no such  thing as a 'silly question' to those who do not know!

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: DCL/LISP to insert block from list
« Reply #26 on: June 27, 2020, 06:08:15 AM »
Hi
So I've worked on this some more and made some progress.
I've set "ldct1" to inset a specific block that exists in the search path.
This works as expected.
I've tried to set "ldct2" to insert the block from the list, but get an error message that drawing "D" cannot be found!

Can you offer any pointers please?

Code: [Select]
  (if (= NEWTILE "ldct1")
    (INSERT_BLOCK1) ;GOTO INSERT BLOCK 1
  ) ;_ end of if
  (if (= NEWTILE "ldct2")
    (SET_BLOCK2) ;GOTO SET BLOCK 2
  ) ;_ end of if
 ) ;end INSERT_BLOCK_VIEW
;-----------------------------------------------------------------------;
 (defun
   SET_BLOCK ()
  (setq
    D  (nth 1 SIZE_DIMS)
  ) ;end setq
 ) ;End SET_BLOCK
 (defun
   SET_BLOCK2 ()
  (setq
    D  (nth 1 SIZE_DIMS)
  ) ;end setq
  (INSERT_BLOCK2) ;GOTO INSERT BLOCK 2
 ) ;End SET_BLOCK2
  ;-----------------------------------------------------------------------;
(defun
   INSERT_BLOCK1 ()
  (command
"._-insert" "nut_ac" pause 1 1 0
   ) ;_ end of command
) ;end INSERT_BLOCK1
(defun
   INSERT_BLOCK2 ()
  (command
"._-insert" "D" pause 1 1 0
   ) ;_ end of command
) ;end INSERT_BLOCK2
There is no such  thing as a 'silly question' to those who do not know!

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: DCL/LISP to insert block from list
« Reply #27 on: June 28, 2020, 12:20:34 AM »
If referring to mine that's a menu file method it uses slides for the images, can be very long as Autocad auto adds next page etc. You make slides of your dwg, then just make a menu Image section.

Code: [Select]
***MENUGROUP= ZZZZ

***POP20
**CADLIB
             [LIBRARY]
             [->Stddwgs]
             [TRENCH]$I= ZZZZ.TRENCH $I=*
             [PIPES]$I= ZZZZ.PIPES $I=*
             [PITS]$I= ZZZZ.PITS $I=*
             [KERBS]$I= ZZZZ.KERBS $I=*
             [SHEETS]$I= ZZZZ.SURVEY $I=*


***image
**SURVEY
[SURVEY]
[A0,A0]^C^C^P(SETQ FNAME "A0")(LOAD "NEWSURVLAYOUT")
[A1,A1]^C^C^P(SETQ FNAME "A1")(LOAD "NEWSURVLAYOUT")
[A3 Srv 1,A3 Srv 1]^C^C^P(SETQ FNAME "A3 Survey Sheet 1")(LOAD "NEWSURVLAYOUT")
[A3 Srv 2,A3 Srv 2]^C^C^P(SETQ FNAME "A3 Survey Sheet 2")(LOAD "NEWSURVLAYOUT")
[A3 ex 1,A3 ex 1]^C^C^P(SETQ FNAME "A3 Survey Sheet ex 1)(LOAD "NEWSURVLAYOUT")
A man who never made a mistake never made anything

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: DCL/LISP to insert block from list
« Reply #28 on: June 28, 2020, 03:44:40 AM »
Morning All,

I'm getting the impression that I am no longer welcome here?
Support has dried up, have I done something wrong? no one has said.

Am I too much of a novice? :uglystupid2:

For anyone following this thread, my inspiration came from 'wisey steel shapes' (as mentioned).
This utility can be found here:
https://blog.draftsperson.net/wiseys-steel-shapes-lisp-program/
My contribution, though small, can be found at the bottom of the page.

stay safe everyone.
SteveN
There is no such  thing as a 'silly question' to those who do not know!

JohnK

  • Administrator
  • Seagull
  • Posts: 10603
Re: DCL/LISP to insert block from list
« Reply #29 on: June 28, 2020, 03:14:01 PM »
No, the participation has been dropping slowly over the years. It is not a reflection on you. Just keep trying there are still active members and I am still paying the bills and pruning the spammers to keep this place online.
 
Morning All,

I'm getting the impression that I am no longer welcome here?
Support has dried up, have I done something wrong? no one has said.

Am I too much of a novice? :uglystupid2:

For anyone following this thread, my inspiration came from 'wisey steel shapes' (as mentioned).
This utility can be found here:
https://blog.draftsperson.net/wiseys-steel-shapes-lisp-program/
My contribution, though small, can be found at the bottom of the page.

stay safe everyone.
SteveN
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: DCL/LISP to insert block from list
« Reply #30 on: June 28, 2020, 04:20:41 PM »
And with things the way they are, many are trimming 'non-essential activities' during their work day.  So less time spent here and elsewhere helping others.
If you are going to fly by the seat of your pants, expect friction burns.

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

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: DCL/LISP to insert block from list
« Reply #31 on: June 28, 2020, 05:31:32 PM »
June-August typically vacation time for many as well..
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: DCL/LISP to insert block from list
« Reply #32 on: June 30, 2020, 03:43:40 AM »
drawing "D" cannot be found!

The issue is that you are passing a string "D" instead of a variable D.

Before going on with your work you should read up on variables and their scope. This is an often neglected topic in the AutoLisp world. Sadly this also applies to much of the educational material that is out there, including the examples in the official AutoCAD documentation.

Lee Mac has a nice explanation on his website:
http://www.lee-mac.com/localising.html

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: DCL/LISP to insert block from list
« Reply #33 on: June 30, 2020, 07:11:11 AM »
Hi Roy,

Thanks for the info, though I had found that.


Code: [Select]
(defun
   INSERT_BLOCK2 ()
  (princ D) ; print the content of D variable to the command line.
  (command
"._-insert" D pause 1 1 0 ;INSERT BLOCK 2
   ) ;_ end of command

Here is the command history with the above implemented:

Command:
Command:
Rendering support loaded.
Raster image support loaded.
Command:
Command: fredsingle2LD-200MM-TRAY-RUN-3000
<Select insert point>/Reference: LD-200MM-TRAY-RUN-3000
Command: '_PMTHIST

I can see what variable D is, but this is still not getting to the "insert" command.



S
There is no such  thing as a 'silly question' to those who do not know!

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: DCL/LISP to insert block from list
« Reply #34 on: June 30, 2020, 09:48:49 AM »
Apart from the missing final closing parenthesis, and the quaint indentation, the code should work. Maybe the block has attributes? Or maybe you are calling this function when the dialog is still displayed?

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: DCL/LISP to insert block from list
« Reply #35 on: June 30, 2020, 11:49:42 AM »
Hi Roy,

The closing parenthesis is there, just my hasty copying.

Code: [Select]
(defun
   SET_BLOCK ()
  (setq
    D  (nth 1 SIZE_DIMS)
  ) ;end setq
  (INSERT_BLOCK2) ;GOTO INSERT BLOCK2
 ) ;End SET_BLOCK
  ;-----------------------------------------------------------------------;
  ;-----------------------------------------------------------------------;
  ;-----------------------------------------------------------------------;
  ;-----------------------------------------------------------------------;
  ;-----------------------------------------------------------------------;
(defun
   INSERT_BLOCK1 ()
  (command
"._-insert" "RT" pause 1 1 0 ;INSERT BLOCK 1
   ) ;_ end of command
) ;end INSERT_BLOCK1
(defun
   INSERT_BLOCK2 ()
  (princ D) ; print the content of D variable to the command line.
  (command
        "._-insert" D pause 1 1 0 ;INSERT BLOCK2
   ) ;_ end of command
) ;end INSERT_BLOCK2

FYI I added a named block to insert which works, this block does have attributes and does not appear to cause any issues.

The (princ D) does display the block (dwg) name ie LD-200MM-TRAY-RUN-3000
which makes me think that the INSERT_BLOCK2 has initiated but for some reason the (command "._-insert" .......) is not?

But then I am thick!  :uglystupid2:

S
There is no such  thing as a 'silly question' to those who do not know!

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: DCL/LISP to insert block from list
« Reply #36 on: June 30, 2020, 03:40:05 PM »
Post the LD-200MM-TRAY-RUN-3000 file. Maybe there is a recursion issue?

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: DCL/LISP to insert block from list
« Reply #37 on: July 01, 2020, 03:58:11 AM »
Hi Roy,

Do you want the 'dwg' file or the 'lsp' file?

S
There is no such  thing as a 'silly question' to those who do not know!

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: DCL/LISP to insert block from list
« Reply #38 on: July 02, 2020, 03:13:32 AM »
I meant the DWG, but you can post both files if you like.

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: DCL/LISP to insert block from list
« Reply #39 on: July 02, 2020, 03:21:58 AM »
Thanks for the offer, but I have found the issue.

The issue was in the formatting of the txt file

I had:
("LD-75mm     Straight Run  3mtr" LD-75mm-tray-run-3000)

But I needed:
("LD-75mm     Straight Run  3mtr" "LD-75mm-tray-run-3000")

S
There is no such  thing as a 'silly question' to those who do not know!

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: DCL/LISP to insert block from list
« Reply #40 on: July 15, 2020, 05:15:18 AM »
Just a final update on this project.

I managed to get it all working and have now added a 'preview' image.



Steve
There is no such  thing as a 'silly question' to those who do not know!

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: DCL/LISP to insert block from list
« Reply #41 on: July 15, 2020, 10:37:44 PM »
Looks very impressive.
A man who never made a mistake never made anything

sln8458

  • Newt
  • Posts: 91
  • CMS Intellicad 9.0/10.0
Re: DCL/LISP to insert block from list
« Reply #42 on: July 19, 2020, 05:44:13 AM »
Thank you BIGAL.

I'm pleased with the results, although I am still 'polishing'
I managed to achieve having all of the drawing numbers/names and the slides in the text file:
("LD-200mm RH Reducer" "LD-200mm-tray-Reducer-3000" "ldct5-r.sld")
where
"LD-200mm RH Reducer" is the text displayed in the list box
"LD-200mm-tray-Reducer-3000" is the drawing number/name
"ldct5-r.sld" is the slide displayed in the 'preview' image

And whilst this is probably food & drink to most of the posters here, it was more difficult for me.
This means that I can add new blocks to the lists without having to modify the lsp file. I still do not have the full set of blocks.
Or change the slides to individual rather than 'generic' ones.

The next project will include radio buttons and possibly 'concatenated' drawing numbers, and slides with generic dimension (ie 'A'  'B'   'C'...) and then a display of the actual dimensions, a bit like a catalogue. Again I hope to include the dimensions in the txt file so they will be n3, n4, n5........

.
There is no such  thing as a 'silly question' to those who do not know!

BIGAL

  • Swamp Rat
  • Posts: 1396
  • 40 + years of using Autocad
Re: DCL/LISP to insert block from list
« Reply #43 on: July 19, 2020, 07:50:15 PM »
You can have sub dcl in a dcl so you dont need to close the parent dcl use this for entering sizes etc. If you need help let me know.

Also making slides can be scripted so open dwg mslide save close, I suggest Zoom E then 0.8XP it just zooms out a little bit, again I do it old fashioned DOS/CMD and Word very fast when you know what your doing.

The attached is a library getvals can have as many a syou like subject to screen size this version has image option. Look at screenshot.

« Last Edit: July 19, 2020, 08:11:24 PM by BIGAL »
A man who never made a mistake never made anything