error when attempting to open Navisworks with the plugin

error when attempting to open Navisworks with the plugin

edufourGCYZK
Contributor Contributor
2,248 Views
12 Replies
Message 1 of 13

error when attempting to open Navisworks with the plugin

edufourGCYZK
Contributor
Contributor

Hello,

 

I compiled the following code and then placed the compiled files into a document within the plugin document.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Navisworks.Api;
using Autodesk.Navisworks.Api.Plugins;

 

namespace ChangeCouleurPlugin
{
[PluginAttribute("ChangeCouleurPlugin", "ADSK", ToolTip = "ChangeCouleurPlugin", DisplayName = "ChangeCouleurPlugin")]
public class ChangeCouleurPlugin : AddInPlugin
{
public override int Execute(params string[] parameters)
{
Search search = new Search();
search.Selection.SelectAll();
search.SearchConditions.Add(SearchCondition.HasPropertyByDisplayName("Entity Handle", "Value").EqualValue(VariantData.FromDisplayString("C0A4")));


ModelItemCollection searchResults = search.FindAll(Autodesk.Navisworks.Api.Application.ActiveDocument, false);

Application.ActiveDocument.CurrentSelection.CopyFrom(searchResults);

return 0;
}
}
}

 

After completing these steps, I attempted to open Navisworks but encountered a pop-up message that refuses to disappear.

 

edufourGCYZK_0-1687204846792.png

Is the problem with my code or is there another issue?

 

Thank you for the response !

 

Edward Dufour

0 Likes
Accepted solutions (1)
2,249 Views
12 Replies
Replies (12)
Message 2 of 13

jabowabo
Mentor
Mentor

Autodesk.Navisworks.Api.Application.ActiveDocument

 

There is no active document on first start up. You should create a trigger, like a button, to start the command after a document is opened.

 

0 Likes
Message 3 of 13

edufourGCYZK
Contributor
Contributor

I don't fully understand what you mean. When I open Navisworks, I directly open a file.

Will creating a trigger solve the problem?

0 Likes
Message 4 of 13

jabowabo
Mentor
Mentor

Comment out the lines below and see if it runs:

// ModelItemCollection searchResults = search.FindAll(Autodesk.Navisworks.Api.Application.ActiveDocument, false);

// Application.ActiveDocument.CurrentSelection.CopyFrom(searchResults);

 

 My guess is that it's trying to access 'ActiveDocument' before your file is fully opened.

0 Likes
Message 5 of 13

edufourGCYZK
Contributor
Contributor

It didn't change anything; the same thing pops up when I try to open Navisworks.

0 Likes
Message 6 of 13

jabowabo
Mentor
Mentor

Will it load if you comment everything in the Execute method?

0 Likes
Message 7 of 13

edufourGCYZK
Contributor
Contributor

No, it will not work. I just tried it and encountered the same problem.

Here is a picture of the code that I loaded.

 

edufourGCYZK_0-1687269660702.png

 

0 Likes
Message 8 of 13

jabowabo
Mentor
Mentor

Are you targeting the correct .NET framework (v 4.8 for Navisworks 2024)?

jabowabo_0-1687270614638.png

 

0 Likes
Message 9 of 13

edufourGCYZK
Contributor
Contributor

I was previously using the .NET 7.0 framework, and now I'm attempting to switch to a different framework in my project. However, the .NET4.8 framework is not appearing in the list of target frameworks in Visual Studio Community, despite being downloaded on my computer. Do you have any ideas why it is not showing up?

 

Screenshot 2023-06-20 125036.png

 

0 Likes
Message 10 of 13

jabowabo
Mentor
Mentor
Accepted solution

You created your project as a .NET Core project. You'll need to re-create it as a .NET Framework project and target version 4.8.

 

https://versionsof.net/

Message 11 of 13

upadhye.vinay
Contributor
Contributor

@edufourGCYZK 

you refer to this link. might help you get started with plugin development

https://twentytwo.space/2020/04/08/creating-navisworks-add-ins/

0 Likes
Message 12 of 13

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @edufourGCYZK ,

 

@jabowabo's suggestion is right and will assist you in resolving the issue.

FYI, Your problem appears to be similar to the one described in the link below.

https://forums.autodesk.com/t5/navisworks-api/navisworks-manage-2023-crashes-when-adding-plugin-to-t... 

 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 13 of 13

burkhard.walger
Contributor
Contributor

Easy approach to find out whats going on:
Do start roamer.exe on command line with a log file argument.

 

 

"C:\Program Files\Autodesk\Navisworks Manage 2024\Roamer.exe" -log c:\temp\roamer-crash.log MyModel.nwd

 

 

After the crash inspect the file c:\temp\roamer-crash.log for clues to the error.

You can find more usefull command line switches here:
https://help.autodesk.com/view/NAV/2024/ENU/?guid=GUID-3891FB9F-7BF1-4510-A1EE-121E975C0ACE

 

HTH

0 Likes