0 Members and 1 Guest are viewing this topic.
I'd like to find a match for (dos_listbox title prompt list [default]) without having to create another form myself.Thanks!doug
I don't use dosLib, so I have no clue what your after. Whats it do, and maybe I can help you
;; gc:ListBox (gile);; Dialog box to make one ore more choice in a list (or popup);;;; Arguments;; title : the dialog title (string);; msg ; message (string), "" or nil for none;; keylab : an association list ((key1 . label1) (key2 . label2) ...);; flag : 0 = popup list;; 1 = single choice list;; 2 = multi choices list;;;; Return : the option key (flag = 0 ou 1) or the options keys list (flag = 2);;;; Examples;; (gc:listbox "Layout" "Choose a layout" (mapcar 'cons (layoulist) (layoutlist)) 1);; (gc:listbox "Separator" "Specify the separator" '(("," . "Comma") (";" . "Semicolon") ("\t" . "Tabulation")) 1)(defun gc:ListBox (title msg keylab flag / tmp file dcl_id choice) (setq tmp (vl-filename-mktemp "tmp.dcl") file (open tmp "w") ) (write-line (strcat "ListBox:dialog{label=\"" title "\";") file ) (if (and msg (/= msg "")) (write-line (strcat ":text{label=\"" msg "\";}") file) ) (write-line (cond ((= 0 flag) "spacer;:popup_list{key=\"lst\";") ((= 1 flag) "spacer;:list_box{key=\"lst\";") (T "spacer;:list_box{key=\"lst\";multiple_select=true;") ) file ) (write-line "}spacer;ok_cancel;}" file) (close file) (setq dcl_id (load_dialog tmp)) (if (not (new_dialog "ListBox" dcl_id)) (exit) ) (start_list "lst") (mapcar 'add_list (mapcar 'cdr keylab)) (end_list) (action_tile "accept" "(or (= (get_tile \"lst\") \"\") (if (= 2 flag) (progn (foreach n (str2lst (get_tile \"lst\") \" \") (setq choice (cons (nth (atoi n) (mapcar 'car keylab)) choice))) (setq choice (reverse choice))) (setq choice (nth (atoi (get_tile \"lst\")) (mapcar 'car keylab))))) (done_dialog)" ) (start_dialog) (unload_dialog dcl_id) (vl-file-delete tmp) choice)
<Window x:Class="ListBoxProject.SimpleListbox" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" MinHeight="300" Width="300" MinWidth="300"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <TextBlock Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Margin="5" Text="{Binding Prompt}"/> <ListBox Grid.Column="0" Grid.Row="1" Margin="5" ItemsSource="{Binding Contents}" SelectedItem="{Binding Selection}" /> <StackPanel Grid.Column="1" Grid.Row="1" Orientation="Vertical" Margin="5"> <Button IsDefault="True" Width="50" Margin="5" Click="OnOkClick">OK</Button> <Button IsCancel="True" Width="50" Margin="5">Cancel</Button> </StackPanel> </Grid></Window>
using System;using System.Collections.Generic;using System.Windows;namespace ListBoxProject{ /// <summary> /// Interaction logic for SimpleListbox.xaml /// </summary> public partial class SimpleListbox : Window { public static SimpleListbox CreateSimpleListbox (string title, string prompt, IEnumerable<string> contents) { return new SimpleListbox { Title = title, Prompt = prompt, Contents = contents }; } public SimpleListbox() { InitializeComponent(); DataContext = this; } public string Prompt { get; set; } public IEnumerable<string> Contents { get; set; } public string Selection { get; set; } private void OnOkClick(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(this.Selection)) { DialogResult = false; } else { DialogResult = true; } } }}
string[] layers = {"Layer1", "Layer2", "Layer3"}; SimpleListbox lb = SimpleListbox.CreateSimpleListbox("Set Current Layer", "Select a layer", layers); if (lb.ShowDialog() != true) { //user didn't select anything from the list } else { //lb.Selection contains the result }
Because Lisp is so painful compared to .NET...?
I thought dugk wanted a .NET defined LISP function...
Quote from: gile on March 24, 2010, 04:49:55 PMI thought dugk wanted a .NET defined LISP function...I thought he did too.
using System;using System.Collections.Generic;using ListBoxProject;using Autodesk.AutoCAD.DatabaseServices;using Autodesk.AutoCAD.Runtime;using acadApp = Autodesk.AutoCAD.ApplicationServices.Application;namespace DosLibLikeLibrary{ public class LispCommands { //(listbox "TITLE" "prompt" '("layer1" "layer2" "layer3")) [LispFunction("Listbox")] public string Listbox(ResultBuffer inputList) { TypedValue[] args = inputList.AsArray(); string title = args[0].Value.ToString(); string prompt = args[1].Value.ToString(); List<string> choices = new List<string>(); for (int i = 3; i < args.Length -1; i++) { choices.Add(args[i].Value.ToString()); } SimpleListbox listDialog = SimpleListbox.CreateSimpleListbox(title, prompt, choices); if (acadApp.ShowModalWindow(listDialog) != true) return ""; else return listDialog.Selection; } }}