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

Navisworks Crashes after i build my addin

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
jattardian
370 Views, 2 Replies

Navisworks Crashes after i build my addin

Hi, 

i am trying to create a addin that takes all parameters in a file and saves them to a CSV.
I build the project and it goes well but navisworks does not start after. 

This is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;


using Autodesk.Navisworks.Api;
using Autodesk.Navisworks.Api.Plugins;


namespace NavisworksDB
{
[PluginAttribute("NavisworksDB", "One", DisplayName = "NavisworksDB", ToolTip = "BIM Model Validator")]
public class MainClass : AddInPlugin
{
// Step 1 : implement execute method
public override int Execute(params string[] parameters)
{
// Step 2: current document
Document doc = Autodesk.Navisworks.Api.Application.ActiveDocument;
// Step 3: display message
StringBuilder message = new StringBuilder();

// Step 4: select all elements in the project
ModelItemCollection items = doc.CurrentSelection.SelectedItems;

// Step 5: Create a DataTable that has all the possible parameters as columns
DataTable dataTable = new DataTable("ElementsData");

foreach (ModelItem item in items)
{
PropertyCategoryCollection elementCategories = item.PropertyCategories;

foreach (PropertyCategory elementCategory in elementCategories)
{
string categoryName = elementCategory.DisplayName;

foreach (DataProperty dataProperty in elementCategory.Properties)
{
string columnName = categoryName + "." + dataProperty.DisplayName;
if (!dataTable.Columns.Contains(columnName))
{
dataTable.Columns.Add(columnName, typeof(string));
}
}
}
}

// Step 6: Iterate through each element in the project and append the values to the DataTable
foreach (ModelItem item in items)
{
DataRow row = dataTable.NewRow();
PropertyCategoryCollection elementCategories = item.PropertyCategories;

foreach (PropertyCategory elementCategory in elementCategories)
{
string categoryName = elementCategory.DisplayName;

foreach (DataProperty dataProperty in elementCategory.Properties)
{
string columnName = categoryName + "." + dataProperty.DisplayName;
row[columnName] = dataProperty.Value.ToString();
}
}

dataTable.Rows.Add(row);
}

// Step 7: Save DataTable to CSV
StringBuilder csvContent = new StringBuilder();
IEnumerable<string> columnNames = dataTable.Columns.Cast<DataColumn>().Select(column => column.ColumnName);
csvContent.AppendLine(string.Join(",", columnNames));

foreach (DataRow row in dataTable.Rows)
{
IEnumerable<string> fields = row.ItemArray.Select(field => field.ToString());
csvContent.AppendLine(string.Join(",", fields));
}

System.IO.File.WriteAllText("ElementsData.csv", csvContent.ToString());

return 0;
}
}
}

 

Labels (2)
2 REPLIES 2
Message 2 of 3
alexisDVJML
in reply to: jattardian

Interesting feature.
No bandwith now to try to replicate your issue, so just telling the obvious: run it in debug mode and step?

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
Message 3 of 3
jattardian
in reply to: alexisDVJML

I figured it out. I wasn't using the right framework....

next step is to upload the info to a database instead of printing a csv

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report