Author Topic: Storing and reading lists from a file to use in a script  (Read 1059 times)

0 Members and 1 Guest are viewing this topic.

Charpzy

  • Mosquito
  • Posts: 7
Storing and reading lists from a file to use in a script
« on: December 17, 2022, 10:07:24 AM »
I need to store multiple lines of data (50+) which will be used for info in a dialog box read by a script, currently im using a .ini file which i don't know if its correct

.ini file:
(("SINGLE CARRIAGEWAY" "30" "TWO WAY TRAFFIC" "TWO WAY APPROACH") (("DATUM" "0.0") ("517L" "15.0") ("518" "15.0") ("7001" "30.0")))


- the first list in the list is info to help categorise the info in a dialog box of 4 lists: (Carriageway > Speed > System > Description)
- the second list is list of lists: (.sld file name, meter marker)


I'm unsure what the best way to store this info is and what type of document is the best to store in it?

VovKa

  • Water Moccasin
  • Posts: 1636
  • Ukraine
Re: Storing and reading lists from a file to use in a script
« Reply #1 on: December 17, 2022, 10:32:25 AM »
data.ini
Code: [Select]
'(
(("SINGLE CARRIAGEWAY" "30" "TWO WAY TRAFFIC" "TWO WAY APPROACH") (("DATUM" "0.0") ("517L" "15.0") ("518" "15.0") ("7001" "30.0")))
(("DOUBLE CARRIAGEWAY" "30" "TWO WAY TRAFFIC" "TWO WAY APPROACH") (("DATUM" "0.0") ("517L" "15.0") ("518" "15.0") ("7001" "30.0")))
(("TRIPLE CARRIAGEWAY" "30" "TWO WAY TRAFFIC" "TWO WAY APPROACH") (("DATUM" "0.0") ("517L" "15.0") ("518" "15.0") ("7001" "30.0")))
)

Code: [Select]
(setq Data (load "data.ini"))

VovKa

  • Water Moccasin
  • Posts: 1636
  • Ukraine
Re: Storing and reading lists from a file to use in a script
« Reply #2 on: December 17, 2022, 10:33:22 AM »
welcome to theswamp, Charpzy

Charpzy

  • Mosquito
  • Posts: 7
Re: Storing and reading lists from a file to use in a script
« Reply #3 on: December 17, 2022, 12:23:45 PM »
Thank you!

currently my data.ini file looks like this
Code: [Select]
'(
(("SINGLE CARRIAGEWAY" "30" "TRAFFIC SIGNALS" "2-WAY TRAFFIC SIGNAL APPROACH") (("TRAFFICLIGHT" "0.0") ("7011A" "15.0") ("517L" "30.0") ("518" "30.0") ("543" "45.0") ("7001" "60.0")))
(("SINGLE CARRIAGEWAY" "30" "STOP AND GO" "STOP AND GO APPROACH") (("STOP_GO" "0.0") ("7011B" "15.0") ("517L" "30.0") ("518" "30.0") ("7010F" "45.0") ("7001" "60.0")))
(("SINGLE CARRIAGEWAY" "30" "PRIORITY" "L PRIORITY APPROACH") (("DATUM" "0.0") ("516" "15.0") ("516-1" "15.0") ("517L" "30.0") ("518" "30.0") ("7001" "45.0")))
(("SINGLE CARRIAGEWAY" "30" "PRIORITY" "R PRIORITY APPROACH") (("DATUM" "0.0") ("811" "15.0") ("811-1" "15.0") ("517R" "30.0") ("518" "30.0") ("7001" "45.0")))
(("SINGLE CARRIAGEWAY" "30" "TWO WAY TRAFFIC" "TWO WAY APPROACH") (("DATUM" "0.0") ("517L" "15.0") ("518" "15.0") ("7001" "30.0")))
)

I'm able to get the specific element from each list, but I'm really puzzled how to then put each of these into there specific categories/lists so I can call a list within the dialog. I've been at it a while trying to rack my brains around it, it just seem like I'm trying to crack the matrix going in and out of lists/ categories to me now haha.

I've made a dialog box which will essentially work like:
select carriageway > next list loads all speeds within that
select speed > next list loads all systems within that
select system > next list loads all descriptions within that
select descriptions > will display all slides and the defined meter markings


(I've attached a SS of the dialog box to try help put a image to the idea)

BIGAL

  • Swamp Rat
  • Posts: 1459
  • 40 + years of using Autocad
Re: Storing and reading lists from a file to use in a script
« Reply #4 on: December 17, 2022, 05:23:14 PM »
You have posted at Cadtutor as well see comment there.
A man who never made a mistake never made anything

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8903
  • AKA Daniel
Re: Storing and reading lists from a file to use in a script
« Reply #5 on: December 17, 2022, 07:29:06 PM »
you might try SQLite and make queries to the info https://www.theswamp.org/index.php?topic=28286

you can output in different formats
Code - Auto/Visual Lisp: [Select]
  1. (DEFUN C:TEST123 ( / a db)
  2.   (SETQ DB "E:/chinook/chinook.db")
  3.   (DSQL_OPEN DB)
  4.  
  5.   (setq Q "SELECT
  6.         trackid,
  7.         tracks.name AS Track,
  8.         albums.title AS Album,
  9.         artists.name AS Artist
  10.   FROM
  11.         tracks
  12.   INNER JOIN albums ON albums.albumid = tracks.albumid
  13.   INNER JOIN artists ON artists.artistid = albums.artistid
  14.   WHERE
  15.      artists.artistid = 10;")
  16.        
  17.   (SETQ A (DSQL_QUERY DB  Q ))
  18.  ;(SETQ A (DSQL_ASSOCQUERY DB  Q ))
  19.  
  20.   (DSQL_CLOSE DB)
  21.   A
  22. )
  23.  

DSQL_ASSOCQUERY DB
Quote
((("TrackId" . 123) ("Track" . "Quadrant") ("Album" . "The Best Of Billy Cobham") ("Artist" . "Billy Cobham"))
 (("TrackId" . 124) ("Track" . "Snoopy's search-Red baron") ("Album" . "The Best Of Billy Cobham") ("Artist" . "Billy Cobham"))
 (("TrackId" . 125) ("Track" . "Spanish moss-\"A sound portrait\"-Spanish moss") ("Album" . "The Best Of Billy Cobham") ("Artist" . "Billy Cobham"))
 (("TrackId" . 126) ("Track" . "Moon germs") ("Album" . "The Best Of Billy Cobham") ("Artist" . "Billy Cobham"))
 (("TrackId" . 127) ("Track" . "Stratus") ("Album" . "The Best Of Billy Cobham") ("Artist" . "Billy Cobham"))
 (("TrackId" . 128) ("Track" . "The pleasant pheasant") ("Album" . "The Best Of Billy Cobham") ("Artist" . "Billy Cobham"))
 (("TrackId" . 129) ("Track" . "Solo-Panhandler") ("Album" . "The Best Of Billy Cobham") ("Artist" . "Billy Cobham"))
 (("TrackId" . 130) ("Track" . "Do what cha wanna") ("Album" . "The Best Of Billy Cobham") ("Artist" . "Billy Cobham")))

DSQL_QUERY
Quote
(("TrackId" "Track" "Album" "Artist")
(123 "Quadrant" "The Best Of Billy Cobham" "Billy Cobham")
(124 "Snoopy's search-Red baron" "The Best Of Billy Cobham" "Billy Cobham")
(125 "Spanish moss-\"A sound portrait\"-Spanish moss" "The Best Of Billy Cobham" "Billy Cobham")
(126 "Moon germs" "The Best Of Billy Cobham" "Billy Cobham")
(127 "Stratus" "The Best Of Billy Cobham" "Billy Cobham")
(128 "The pleasant pheasant" "The Best Of Billy Cobham" "Billy Cobham")
(129 "Solo-Panhandler" "The Best Of Billy Cobham" "Billy Cobham")
(130 "Do what cha wanna" "The Best Of Billy Cobham" "Billy Cobham"))
« Last Edit: December 17, 2022, 09:37:12 PM by Nigel Tufnel »

Charpzy

  • Mosquito
  • Posts: 7
Re: Storing and reading lists from a file to use in a script
« Reply #6 on: December 18, 2022, 09:58:12 AM »
If I'm honest I have very little knowledge with SQL

I've made some of the script so far with the odd little issue it, it grabs a list of unique item in the list from each category and lists them into a list_box when clicked.

VovKa

  • Water Moccasin
  • Posts: 1636
  • Ukraine
Re: Storing and reading lists from a file to use in a script
« Reply #7 on: December 18, 2022, 10:26:56 AM »

Charpzy

  • Mosquito
  • Posts: 7
Re: Storing and reading lists from a file to use in a script
« Reply #8 on: December 19, 2022, 05:39:36 PM »
Thank you Vovka, this is exactly what I was looking for!
I've implemented Lee Macs List Tile Dependency when a selection is selected it updates the below slides etc, but i'm struggling to understand/use it in an action_tile

It currently works but only grabs the first item in the list of desc-list, so in the screenshot ive got "30 MPH 3-WAY Traffic..." selected but it returns "30 MPH 2-WAY Traffic..."

it works completely find outside of the action_tile once that line is removed, its only when it gets added into there it only grabs the first element

Code - Auto/Visual Lisp: [Select]
  1. (defun c:SAPPROACH (/ *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 (load (findfile "DATA\\SAPPROACHES.ini")))
  20.  
  21.   (if
  22.     (and
  23.       (setq fn (findfile "DIALOGS\\APPROACH.dcl"))
  24.       (setq dlg_id (load_dialog fn))
  25.       (new_dialog "SARRAY" dlg_id)
  26.     )
  27.     (progn
  28.       (setq rtn '(0 0 0))
  29.       (LM:dcld:action '( "speed-list" "sys-list" "desc-list") 'lst 'rtn)
  30.       (action_tile "desc-list" "(slide-reset)(slide-update (caddr (LM:dcld:getitems rtn lst)))")
  31.       (if (= 1 (start_dialog))
  32.         (princ ((LM:dcld:getitems rtn lst)))
  33.       )
  34.     )
  35.   )
  36.   (*error* nil)
  37.   (princ)
  38. )

(slide-update) take the descript string and searches it through another list to grab the slide info from there "Slide file name" "distance" & "Slide column num"
(slide-reset) rests the slides back to default colour

Lee Mac

  • Seagull
  • Posts: 12937
  • London, England
Re: Storing and reading lists from a file to use in a script
« Reply #9 on: December 20, 2022, 12:04:12 PM »
The function LM:dcld:action is already defining an action_tile expression for the tile desc-list and so your subsequent action_tile expression will redefine the action for this tile.

You might be able to accomplish your goal by changing lines 39-41 of my LM:dcld:action function from:
Code - Auto/Visual Lisp: [Select]
  1.                 (list 'lambda '( val lst )
  2.                     (list 'setq rtn-sym (list 'LM:substnth '(atoi val) lvl rtn-sym))
  3.                 )
To:
Code - Auto/Visual Lisp: [Select]
  1.                 (list 'lambda '( val lst )
  2.                     (list 'setq rtn-sym (list 'LM:substnth '(atoi val) lvl rtn-sym))
  3.                    '(slide-reset)
  4.                     (list 'slide-update (list 'caddr (list 'LM:dcld:getitems rtn-sym lst-sym)))
  5.                 )

But this is entirely untested.

Charpzy

  • Mosquito
  • Posts: 7
Re: Storing and reading lists from a file to use in a script
« Reply #10 on: December 20, 2022, 12:24:58 PM »
Works perfect! Thank you Lee

Still learning AutoLisp and build new things, so trying to understand to code is still a little fresh