Add Multiple URLs to element

Add Multiple URLs to element

JasonKunkel
Collaborator Collaborator
1,377 Views
8 Replies
Message 1 of 9

Add Multiple URLs to element

JasonKunkel
Collaborator
Collaborator

I've read through what I think are all the pertinent posts, and they all point to this blog:

 

http://adndevblog.typepad.com/aec/2012/05/create-hyperlinks-for-model-objects-using-net-api.html

 

Which was a great start point, but I am trying to add multiple hyperlinks to the same element. This code, and my failed attempts at updating it, simply overwrite the previous hyperlink.

 

Someone in the comments of the blog said they figured it out but never shared the solution. Anyone have a fix or tweak to the blog's code they can share that can point me in the right direction?

 

 

Here's more details:

I am using Data Tools to read in an Excel file. That file links via GUID to elements in my Navisworks model. That Excel file has 3 different URLs. My code reads those data properties and sends each one to the AddURL function (modified from the blog post above).  But each time, only the last URL ends up being added as a link. It is clearly overwriting the prior hyperlink. I've tried a lot of different things here (my COM knowledge is poor, and frankly, my .NET knowledge isn't awesome) and was hoping someone could help me out.

 

Thanks!


Jason Kunkel
Senior Practice Manager, Architecture and Engineering
CADD Microsystems Blog
RVIT Blog | Twitter | LinkedIn
0 Likes
1,378 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable

Hi Jason,

 

I suppose you are using the override method, which in return fails to deliver what you are looking for.

    ComApi.InwURLOverride oMyURLOoverride =

 

        (ComApi.InwURLOverride)state.ObjectFactory(

 

        ComApi.nwEObjectType.eObjectType_nwURLOverride, nullnull);

 

I might be able to help if I see your full code.

0 Likes
Message 3 of 9

Anonymous
Not applicable

Hi Jason

 

This is sample code

 

 

Autodesk.Navisworks.Api.Interop.ComApi.InwOpState10 state = Autodesk.Navisworks.Api.ComApi.ComApiBridge.State;
ModelItem modelItem = Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.SelectedItems.First;
ModelItemCollection modelItemCollection = new ModelItemCollection();
modelItemCollection.Add(modelItem);
Autodesk.Navisworks.Api.Interop.ComApi.InwOpSelection opSelection = Autodesk.Navisworks.Api.ComApi.ComApiBridge.ToInwOpSelection(modelItemCollection);
if (modelItem.PropertyCategories.FindCategoryByName("LcOaExURLAttribute")==null)
{
Autodesk.Navisworks.Api.Interop.ComApi.InwURLOverride oMyURLOoverride =
(Autodesk.Navisworks.Api.Interop.ComApi.InwURLOverride)state.ObjectFactory
(Autodesk.Navisworks.Api.Interop.ComApi.nwEObjectType.eObjectType_nwURLOverride, null, null);
Autodesk.Navisworks.Api.Interop.ComApi.InwURL2 newURL = (Autodesk.Navisworks.Api.Interop.ComApi.InwURL2)state.ObjectFactory(Autodesk.Navisworks.Api.Interop.ComApi.nwEObjectType.eObjectType_nwURL, null, null);
newURL.name = "NewLink";
newURL.URL = "NewLinkURL";
newURL.SetCategory("Hyperlink", "LcOaURLCategoryHyperlink");
oMyURLOoverride.URLs().Add(newURL);
state.SetOverrideURL(opSelection, oMyURLOoverride);
}
else
{
Autodesk.Navisworks.Api.Interop.ComApi.InwOaPath3 oPath3 =
Autodesk.Navisworks.Api.ComApi.ComApiBridge.ToInwOaPath(modelItem) as
Autodesk.Navisworks.Api.Interop.ComApi.InwOaPath3;
Autodesk.Navisworks.Api.Interop.ComApi.InwURLOverride oURLOverride = state.GetOverrideURL(oPath3);
Autodesk.Navisworks.Api.Interop.ComApi.InwURL2 newURL =
(Autodesk.Navisworks.Api.Interop.ComApi.InwURL2)state.ObjectFactory
(Autodesk.Navisworks.Api.Interop.ComApi.nwEObjectType.eObjectType_nwURL, null, null);
newURL.name = "URLName";
newURL.URL = "URL";
newURL.SetCategory("Hyperlink", "LcOaURLCategoryHyperlink");
oURLOverride.URLs().Add(newURL);
state.SetOverrideURL(opSelection, oURLOverride);
}

 

you must be select modelitem

0 Likes
Message 4 of 9

JasonKunkel
Collaborator
Collaborator

Yes, it looks like I am using the override. I am not sure what else to be using. Below is the method I am using. It is taken from the examples found elsewhere, as you can. The SetOverrideURL code is identical since I found it on the other pages. Don't know what to use instead. The coordinate related commands are not necessary now, but I left everything intact. Thanks for the help.

 

 

private void AddURL(String URLstring, String URLtype, int i)
{
ComApi.InwOpState10 state;
state = ComApiBridge.ComApiBridge.State;

ComApi.InwURLOverride oMyURLOoverride = (ComApi.InwURLOverride)state.ObjectFactory(Autodesk.Navisworks.Api.Interop.ComApi.nwEObjectType.eObjectType_nwURLOverride, null, null);

double[] coordinate = { 10, 10, 0, 20, 20, 0, 30, 30, 0 };

 

ComApi.InwURL2 oMyURL = (ComApi.InwURL2)state.ObjectFactory(Autodesk.Navisworks.Api.Interop.ComApi.nwEObjectType.eObjectType_nwURL, null, null);
oMyURL.name = URLtype;
oMyURL.URL = URLstring;

oMyURL.SetCategory("Hyperlink", "LcOaURLCategoryHyperlink");

ComApi.InwLPos3f oNewP = (ComApi.InwLPos3f)state.ObjectFactory(Autodesk.Navisworks.Api.Interop.ComApi.nwEObjectType.eObjectType_nwLPos3f, null, null);

oNewP.data1 = coordinate[i];
oNewP.data2 = coordinate[i + 1];
oNewP.data3 = coordinate[i + 2];

//oMyURL.AttachmentPoints().Add(oNewP);


ComApi.InwURLColl oURLColl = oMyURLOoverride.URLs();
oURLColl.Add(oMyURL);

ModelItemCollection modelItemCollectionIn = new ModelItemCollection(Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.SelectedItems);

//convert to InwOpSelection of COM API
ComApi.InwOpSelection comSelectionOut =
ComApiBridge.ComApiBridge.ToInwOpSelection(modelItemCollectionIn);


state.SetOverrideURL(comSelectionOut, oMyURLOoverride);
state.URLsEnabled = false;

return;
}


Jason Kunkel
Senior Practice Manager, Architecture and Engineering
CADD Microsystems Blog
RVIT Blog | Twitter | LinkedIn
0 Likes
Message 5 of 9

Anonymous
Not applicable

This is the same code in the blog. I suppose you might be running into trouble in the part where you modified the code. Within an override method/addURL.

0 Likes
Message 6 of 9

JasonKunkel
Collaborator
Collaborator

Yup. This is the same as the blog. And on the blog it also mentions that the URL is getting overridden. I need to know how to avoid overwriting the URL and simply add links. Sorry if I wasn't clear. Also in the comments on the blog post, others said that they had the same problem and that they fixed it, but never explained how they fixed it. This is all i need. I need to know how to modify that code to allow for multiple links.


Jason Kunkel
Senior Practice Manager, Architecture and Engineering
CADD Microsystems Blog
RVIT Blog | Twitter | LinkedIn
0 Likes
Message 7 of 9

Anonymous
Not applicable

Well, would like to see the full project, send me at bebolwin@gmail.com

0 Likes
Message 8 of 9

Anonymous
Not applicable

Was any of you were able to solve this issue? I am in the same boat. Please help. Thanks.

0 Likes
Message 9 of 9

ngombault
Enthusiast
Enthusiast

May help someone else, the issue for me was that I needed to call the GetOverrideURL function with the optional parameter like this:

state.GetOverrideURL(path, true)

 

The post method:

 

state.GetOverrideURL(path)

fails when the existing urls are from the design software (e.g. Revit) and only returns a result if the existing urls have been added in Navisworks (manually or by your script).

 

0 Likes