Help me find WINFORM Examples!

Help me find WINFORM Examples!

Anonymous
Not applicable
706 Views
3 Replies
Message 1 of 4

Help me find WINFORM Examples!

Anonymous
Not applicable

Hey guys, I really need help to search for materials regarding this. There are not many resources that I was able to find that clearly explains how to reuse a list formed by code from  c# project, to winform as a useroption. I have already created a list based on all the worksets being used inside the revit project in a separate cs project and hope to use this list as part of the listbox tool inside winforms. Are there any examples that you could give me to tackle this problem?

 

This is what winforms provide:

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Organize
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}


private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{

 

}
The code 

IList<Workset> worksetList = new FilteredWorksetCollector(doc).OfKind(WorksetKind.UserWorkset).ToWorksets();

string test = "";
foreach (Workset Workset in worksetList)
{
test += Workset.Name + ": " + Workset.Id + "\n" ;

}

 

The picture below is what I would like to show when user select the plugin on revit.

If it is still not clear maybe this might help give a clearer view of the situation i am in.

1. User Selects plugin on revit

2. Winforms is shown.

3. User selects the workset to move elements that are in the wrong workset to this selected workset. User also selects the elements to be filtered and moved to this workset accordingly.

4. User selects okay/continue.

5. Code runs based on user options and organize the elements accordingly.

6. Taskdialog shows elements that were moved.

 

I already have the code to run the filter for one element to one workset. However, I would like to create a winform to expand this capability for all worksets and elements available in the project however, I do not know how to use it. 

707 Views
3 Replies
Replies (3)
Message 2 of 4

Sean_Page
Collaborator
Collaborator
for each(Workset workset in WorksetList)
{
//This sets the text value seen in the ListView and creates an Item to use for other properties.
    ListViewItem ws = ListView1.Items.Add(workset.Name);

//The tag property is similar to Value property of combobox and can be any object storage type. Just cast it back to what you need.
    ws.Tag = workset.Id;
}
Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
Message 3 of 4

Anonymous
Not applicable

I have done what you have said but somehow the form does not come out when I execute the code. What am I missing?

//Declare Winform
Form1 form = new Form1();

form.worksetsetting(worksetList);
form.Show();

0 Likes
Message 4 of 4

Sean_Page
Collaborator
Collaborator

You need to pass the variable when you intialize the form to begin with.

 

using(Form1 form = new Form1(WorksetList))
{
    if(form.Show == DiaglogResult.OK)
    {
        return Result.Succeded;
    }
}

Then you just have to get the variable being sent in the Form Initialization and use it.

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes