Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

listview

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Anonymous
453 Views, 1 Reply

listview

Anonymous
Not applicable

Dear all,

 

How to load all the imported cad instances in listview.

 

Regards

Mass R

0 Likes

listview

Dear all,

 

How to load all the imported cad instances in listview.

 

Regards

Mass R

1 REPLY 1
Message 2 of 2
Moustafa_K
in reply to: Anonymous

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

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report