listview

listview

Anonymous
Not applicable
505 Views
1 Reply
Message 1 of 2

listview

Anonymous
Not applicable

Dear all,

 

How to load all the imported cad instances in listview.

 

Regards

Mass R

0 Likes
Accepted solutions (1)
506 Views
1 Reply
Reply (1)
Message 2 of 2

Moustafa_K
Collaborator
Collaborator
Accepted solution

Hi

try this code:

 

this code simply do the following:

1- graps all Cad Instances in your Project

2- create a new ListViewItem and assign an item text "Visible to user" the name of the instance.

3- give the item name the Id of the element so we can use it as a reference later.

4- now if you checked any element it will give a text message to showing the id name.

5- last statment is how you can get the element from you projecty from the ID.

 

I hope that helps.

 

        public Frm_Importins()
        {
            InitializeComponent();
listView1.CheckBoxes = true;
FilteredElementCollector filcol = new FilteredElementCollector(m_doc).OfClass(typeof(ImportInstance)); foreach (ImportInstance imps in filcol) { ListViewItem listit = new ListViewItem(imps.get_Parameter(BuiltInParameter.IMPORT_SYMBOL_NAME).AsString()); listit.Name = imps.Id.ToString(); listView1.Items.Add(listit); } } private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e) { if (e.Item.Checked) { MessageBox.Show("You selected Element of ID " + e.Item.Name);
//get a handle of Revit Element Element ele = m_doc.GetElement(new ElementId(int.Parse(e.Item.Name))); } }

Capture.PNGCapture1.PNG

 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1