TheSwamp

Code Red => .NET => Topic started by: dugk on March 23, 2010, 05:15:19 PM

Title: Are there equivalents in .NET to some of what is offered in DosLib?
Post by: dugk on March 23, 2010, 05:15:19 PM
I'd like to find a match for (dos_listbox title prompt list [default]) without having to create another form myself.

Thanks!
doug
Title: Re: Are there equivalents in .NET to some of what is offered in DosLib?
Post by: Glenn R on March 23, 2010, 06:08:22 PM
Having never used doslib myself, but knowing a thing or two about .NET, you will have to give more of an explanation than that to get more help from some of us, me in particular.

With more background, it could be easy....
Title: Re: Are there equivalents in .NET to some of what is offered in DosLib?
Post by: Kerry on March 23, 2010, 06:11:00 PM
I'd like to find a match for (dos_listbox title prompt list [default]) without having to create another form myself.

Thanks!
doug

Do you want to know if it can be done or do you want someone to build it for you ?

Yes it can be done.
Title: Re: Are there equivalents in .NET to some of what is offered in DosLib?
Post by: David Hall on March 23, 2010, 06:17:44 PM
I don't use dosLib, so I have no clue what your after.  Whats it do, and maybe I can help you
Title: Re: Are there equivalents in .NET to some of what is offered in DosLib?
Post by: David Hall on March 23, 2010, 06:18:11 PM
Man, you both beat me to it
Title: Re: Are there equivalents in .NET to some of what is offered in DosLib?
Post by: Kerry on March 23, 2010, 06:24:15 PM
I don't use dosLib, so I have no clue what your after.  Whats it do, and maybe I can help you

piccy from help.


I have a .NET library under development at home, but can't make the source public.
Title: Re: Are there equivalents in .NET to some of what is offered in DosLib?
Post by: gile on March 24, 2010, 02:21:03 AM
Why using .NET or an ARX to define a LISP function which can be defined in plain LISP ?

Code: [Select]
;; 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
)

Example:
(gc:listbox "Separator" "Specify the separator" '(("," . "Comma") (";" . "Semicolon") ("\t" . "Tabulation")) 1)
returns: "\t"
Title: Re: Are there equivalents in .NET to some of what is offered in DosLib?
Post by: sinc on March 24, 2010, 08:21:19 AM
Because Lisp is so painful compared to .NET...?   :-)
Title: Re: Are there equivalents in .NET to some of what is offered in DosLib?
Post by: Bobby C. Jones on March 24, 2010, 02:08:55 PM
I'd like to find a match for (dos_listbox title prompt list [default]) without having to create another form myself.

Thanks!
doug


Not going to happen without creating your own, but it's certainly not difficult to do.  This example only took a few minutes.

xaml
Code: [Select]
<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>

Code behind
Code: [Select]
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;
      }
    }
  }
}


Usage
Code: [Select]
  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
  }
Title: Re: Are there equivalents in .NET to some of what is offered in DosLib?
Post by: gile on March 24, 2010, 04:49:55 PM
Because Lisp is so painful compared to .NET...?   :-)

It's a joke  :?

I thaught dugk wanted a .NET defined LISP function...
Title: Re: Are there equivalents in .NET to some of what is offered in DosLib?
Post by: Kerry on March 24, 2010, 06:05:29 PM

I thought dugk wanted a .NET defined LISP function...

I thought he did too.
Title: Re: Are there equivalents in .NET to some of what is offered in DosLib?
Post by: Bobby C. Jones on March 25, 2010, 01:14:09 PM

I thought dugk wanted a .NET defined LISP function...

I thought he did too.

Hmmm...you're probably correct.  Something along this line should get it.  This is competely untested and I'm not sure if the indices are correct, sorry lunch is never long enough.

EDIT: Indices corrected. Lunch STILL isn't long enough.

Code: [Select]
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;
    }
  }
}