private void AddURL(string name, string link, string category, List <stringedLink> exLinks) { ComApi.InwOpState10 state = ComApiBridge.ComApiBridge.State; // create the hyperlink collection ComApi.InwURLOverride oMyURLOoverride = (ComApi.InwURLOverride)state.ObjectFactory(ComApi.nwEObjectType.eObjectType_nwURLOverride, null, null); foreach (var ex in exLinks) { // create one hyperlink ComApi.InwURL2 oMyURL = (ComApi.InwURL2)state.ObjectFactory(ComApi.nwEObjectType.eObjectType_nwURL, null, null); oMyURL.name = ex.Link_Name; oMyURL.URL = ex.Link_URL; oMyURL.SetCategory(ex.Link_Category, "LcOaURL" + ex.Link_Category + "Hyperlink"); // add the new hyperlink to the hyperlink collection ComApi.InwURLColl oURLColl = oMyURLOoverride.URLs(); oURLColl.Add(oMyURL); // get current selected items ModelItemCollection modelItemCollectionIn = new ModelItemCollection(navisApp.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; } // create recent hyperlink { ComApi.InwURL2 oMyURL = (ComApi.InwURL2)state.ObjectFactory(ComApi.nwEObjectType.eObjectType_nwURL, null, null); oMyURL.name = name; oMyURL.URL = link; oMyURL.SetCategory(category, "LcOaURL" + category + "Hyperlink"); // add the new hyperlink to the hyperlink collection ComApi.InwURLColl oURLColl = oMyURLOoverride.URLs(); oURLColl.Add(oMyURL); // get current selected items ModelItemCollection modelItemCollectionIn = new ModelItemCollection(navisApp.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; } }
private void AddURL(ModelItem modelItem, string[] urls, string[] titleUrls) { ComApi.InwOpState10 state; state = ComApiBridge.ComApiBridge.State; // create the hyperlink collection ComApi.InwURLOverride oMyURLOoverride = (ComApi.InwURLOverride)state.ObjectFactory(ComApi.nwEObjectType.eObjectType_nwURLOverride, null, null); // get current selected items ModelItemCollection modelItemCollectionIn = new ModelItemCollection(); modelItemCollectionIn.Add(modelItem); // add the new hyperlink to the hyperlink collection ComApi.InwURLColl oURLColl = oMyURLOoverride.URLs(); for (int i = 0; i < urls.Count(); i++) { // create one hyperlink ComApi.InwURL2 oMyURL = (ComApi.InwURL2)state.ObjectFactory(ComApi.nwEObjectType.eObjectType_nwURL, null, null); // create Hyperlink oMyURL.SetCategory("Hyperlink", "LcOaURLCategoryHyperlink"); // Attachment Point of the hyperlink ComApi.InwLPos3f oNewP = (ComApi.InwLPos3f)state.ObjectFactory(ComApi.nwEObjectType.eObjectType_nwLPos3f, null, null); oNewP.data1 = modelItemCollectionIn.BoundingBox().Center.X; oNewP.data2 = modelItemCollectionIn.BoundingBox().Center.Y; oNewP.data3 = modelItemCollectionIn.BoundingBox().Center.Z; oMyURL.AttachmentPoints().Add(oNewP); // name of the hyperlink oMyURL.name = titleUrls[i]; // site of the hyperlink oMyURL.URL = urls[i]; oURLColl.Add(oMyURL); } //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; modelItemCollectionIn.Remove(modelItem); }