Hyperlink with model object change

Hyperlink with model object change

d.fedulov
Participant Participant
817 Views
7 Replies
Message 1 of 8

Hyperlink with model object change

d.fedulov
Participant
Participant

Dear Colleagues

I am looking for a possibility to change hyperlink to  individual object in Navisworks. I know that through right clicking any object, i can assign / change / load any web link. I need to change a lot of hyperlink.

Please help correct the code.

// get current selected items

        ModelItemCollection modelItemCollectionIn =

           new ModelItemCollection(

                Autodesk.Navisworks.Api.Application.ActiveDocument.

                    CurrentSelection.SelectedItems);

        //convert to InwOpSelection of COM API

        ComApi.InwOpSelection comSelectionOut =

        ComApiBridge.ComApiBridge.ToInwOpSelection(modelItemCollectionIn);

        // set the hyplerlink of the model items

        state.SetOverrideURL(comSelectionOut, oMyURLOoverride);

        // enable to the hyperlinks visible

        state.URLsEnabled = true;

0 Likes
Accepted solutions (1)
818 Views
7 Replies
Replies (7)
Message 2 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support

HI @d.fedulov ,

 

The below sample code works fine for me

string urlLink1 = "https://www.youtube.com/";
string urlName1 = "URL A";
ModelItemCollection collection1;
MyCode(doc,urlName1,urlLink1,collection1);

string urlLink2 = "https://www.google.com/";
string urlName2 = "URL B";
ModelItemCollection collection2;
MyCode(doc, urlName2, urlLink2, collection2);
private void MyCode(Document doc,string urlName,string urlLink,ModelItemCollection collection)
        {
            InwOpState10 state = ComApiBridge.State;
            // create the hyperlink collection
            InwURLOverride oMyURLOoverride =(InwURLOverride)state.ObjectFactory(nwEObjectType.eObjectType_nwURLOverride, null, null);
            InwURL2 oMyURL =(InwURL2)state.ObjectFactory(nwEObjectType.eObjectType_nwURL, null, null);
            oMyURL.name = urlName;
            oMyURL.URL = urlLink;
            int i = 0;
            if (i == 0)
            {
                oMyURL.SetCategory("Hyperlink", "LcOaURLCategoryHyperlink");
            }
            else
            {
                oMyURL.SetCategory("Label", "LcOaURLCategoryTag");
            }
            InwURLColl oURLColl = oMyURLOoverride.URLs();
            oURLColl.Add(oMyURL);
           
            InwOpSelection comSelectionOut =ComApiBridge.ToInwOpSelection(collection);
            state.SetOverrideURL(comSelectionOut, oMyURLOoverride);
            state.URLsEnabled = true;
        }

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 8

d.fedulov
Participant
Participant

I found this code, i don't know how to change only one Hyperlink. Can't find documentation for Autodesk.Navisworks.Api.Interop.ComApi.InwURL2

 

https://forums.autodesk.com/t5/navisworks-api/add-multiple-urls-to-element/td-p/7786919

 

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);
}

0 Likes
Message 4 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @d.fedulov ,

 

As far as I understand, your model item already has a hyperlink.

Your sample code is adding one more hyperlink to the model items instead of modifying the already existing hyperlink.

If you want to modify only one model item's hyperlink, just add only the required model item to the ModelItemCollection.

ModelItemCollection modelItemCollection = new ModelItemCollection();
modelItemCollection.Add(modelItem);

Could you please try this below link to modify the already existing hyperlink in model item?

        private void Code(Document doc,ModelItem modelItem,string urlName,string urlLink)
        {
            ModelItemCollection modelItemCollection = new ModelItemCollection();
            modelItemCollection.Add(modelItem);
            Autodesk.Navisworks.Api.Interop.ComApi.InwOpSelection opSelection = Autodesk.Navisworks.Api.ComApi.ComApiBridge.ToInwOpSelection(modelItemCollection);
            Autodesk.Navisworks.Api.Interop.ComApi.InwOpState10 state = Autodesk.Navisworks.Api.ComApi.ComApiBridge.State;
            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,true);
            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);
            foreach(InwURL url in oURLOverride.URLs())
            {
                url.name = urlName;
                url.URL = urlLink;
            }
            state.SetOverrideURL(opSelection, oURLOverride);
        }

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 8

d.fedulov
Participant
Participant

Hi naveen.kumar.t

I tried your code, it changes all hyperlinks of one model item in selection

I need to find only one hyperlink in selected model items and change it, other hyperlinks should remain unchanged.

where i can see the description  oURLOverride.URLs() ?  does it have get and set method ?

Items has Multiple URL I need to find one hyperlink and change it.

 

 

0 Likes
Message 6 of 8

d.fedulov
Participant
Participant

.

0 Likes
Message 7 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @d.fedulov ,

 

I think the simplest way is to check the name property by using a simple If-else.

foreach(InwURL url in oURLOverride.URLs())
            {
                //only change the values of the URL having a specific URL name
                if(url.name.Contains("your urlName"))
                {
                    url.name = urlName;
                    url.URL = urlLink;
                }               
            }

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 8 of 8

d.fedulov
Participant
Participant

naveen.kumar.t thank you very much, I understand.

0 Likes