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

0 Members and 1 Guest are viewing this topic.

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 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: 1398
  • 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: 1398
  • 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: 1398
  • 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: 10605
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