Add Link to object via .net

Add Link to object via .net

Anonymous
Not applicable
7,847 Views
19 Replies
Message 1 of 20

Add Link to object via .net

Anonymous
Not applicable

is there a way to add a link to an object via .net? wanting to look thru all the mechanical equipment on our models and link them to their documentation automatically. thanks!

0 Likes
Accepted solutions (1)
7,848 Views
19 Replies
Replies (19)
Message 2 of 20

xiaodong_liang
Autodesk Support
Autodesk Support
Accepted solution

Hi,

 

To add hyperlink to the object, COM API is the current way, i.e. use COM interop in the .NET  program. The code below adds some links to one object.

 

 private void AddURL()
  { 
  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 };

  for(int i = 0 ;i < 9; i +=3)
  {
  ComApi.InwURL2 oMyURL = (ComApi.InwURL2)state.ObjectFactory(Autodesk.Navisworks.Api.Interop.ComApi.nwEObjectType.eObjectType_nwURL, null, null);
  oMyURL.name = "MyURL" + i.ToString ();
  oMyURL.URL = "http://www.google.com";

  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 = true; 
  }
  return;
  }

 

Best regards,

 
autodesk_logo_signature.png

Xiaodong Liang

Developer Consultant

Autodesk Developer Technical Services

0 Likes
Message 3 of 20

tim-bot
Advocate
Advocate

awesome! i just noticed this, but that's exactly what i was looking for B) thank you!

0 Likes
Message 4 of 20

Anonymous
Not applicable

Hi,

 

Is there a way to find the coordinate of an element in Navisworks? I tried to find the coordinate of an element to put a label directly on it.  I know that it is possible to find the boundingbox of the element with the API but it seems that the element is not always in the center of the bounding box.

 

Thanks

 

JF Dupuis

0 Likes
Message 5 of 20

Anonymous
Not applicable

Hi Xiaodong,

    I am attemping to create the add links to object programatically using either vbscript or javascript for usage in the Integrated ActiveX control embedded in a HTML page. I have debugged the code and it runs through to the end but the featured selection in my model is not updated with a manual link I have created. Can you point out where I am going wrong. Both code samples are provided below: I believe the area it is falling down relates to the actual state.SetOverrideURL call using InwOpSelection paramter. I cannot recreate the ModelItemCollection in VBScript or Javascript so have tried  a number of approaches to pass CurrentSelection.SelectedItems

 

VBSCRIPT

 

public sub addURL()

 

Dim state

Set state = NWControl01.state

Dim oMyURLOoverride Set oMyURLOoverride = state.ObjectFactory(state.GetEnum ("eObjectType_nwURLOverride"))

 

 // Dim coordinate = "10, 10, 0, 20, 20, 0, 30, 30, 0"

Dim coordinate coordinate = "1"

 

Dim oMyURL    

Set oMyURL = state.ObjectFactory(state.GetEnum("eObjectType_nwURL"))  

oMyURL.name = "MyURL444"  

oMyURL.URL = "http://www.google.co.uk"

 

oMyURL.SetCategory "Hyperlink","LcOaURLCategoryHyperlink"        

 

 oMyURL.SetCategory "Label", "LcOaURLCategoryTag"

 

  Dim oNewP

  Set oNewP = state.ObjectFactory(state.GetEnum("eObjectType_nwLPos3f"))

 

  oNewP.data1 = "10"  

  oNewP.data2 = "10"  

  oNewP.data3 = "0"

    

oMyURL.AttachmentPoints().Add(oNewP)

 

 Dim oURLColl

  Set oURLColl = oMyURLOoverride.URLs   oURLColl.Add(oMyURL)

 

    //convert to InwOpSelection of COM API  

Dim comSelectionOut

 

 Set comSelectionOut = state.CurrentSelection

   

 

state.SetOverrideURL comSelectionOut, oMyURLOoverride  

 

state.URLsEnabled = true

state.ZoomInCurViewOnCurSel

end sub

-->

 

 

 

JAVASCRIPT&colon;

 

function addURL() {

var state = NWControl01.state;

var oMyURLOoverride = state.ObjectFactory( state.GetEnum( "eObjectType_nwURLOverride"),null, null);

 

  var coordinate = "10, 10, 0, 20, 20, 0, 30, 30, 0 ";

 

    var oMyURL = state.ObjectFactory(state.GetEnum("eObjectType_nwURL"),  null, null);  

 

oMyURL.name = "MyURL444";  

oMyURL.URL = "http://www.google.co.uk";

 

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

 oMyURL.SetCategory("Label", "LcOaURLCategoryTag");

 

  var oNewP = state.ObjectFactory(state.GetEnum("eObjectType_nwLPos3f"), null, null);

  oNewP.data1 = "10";  

  oNewP.data2 = "10";  

  oNewP.data3 = "0";

 

    oMyURL.AttachmentPoints().Add(oNewP);

 

    var oURLColl = oMyURLOoverride.URLs();   oURLColl.Add(oMyURL);

 

    //convert to InwOpSelection of COM API  

var comSelectionOut = state.ObjectFactory(state.GetEnum("eObjectType_nwOpSelection"));

 

// state.CurrentSelection.SelectedItems;

 

    state.SetOverrideURL(comSelectionOut, oMyURLOoverride);  

state.URLsEnabled = true;

state.ZoomInCurViewOnCurSel();

}

 

 

 

Best Regards

 

0 Likes
Message 6 of 20

Anonymous
Not applicable

Hi all,

 

Is there any undates on adding url tags by Api, says, moving functions to .Net Api?

 

Thanks,

John

0 Likes
Message 7 of 20

xiaodong_liang
Autodesk Support
Autodesk Support

Hi John,

 

Sorry, no any news. You still need to use COM API to work with hyperlink.

0 Likes
Message 8 of 20

GeomGym
Advocate
Advocate

I'm assuming it's still not possible to generate a hyperlink from the .net api.

 

Is there any way to get Navisworks to identify this using IFC property sets (or similar)?

0 Likes
Message 9 of 20

GeomGym
Advocate
Advocate

I got the com code above to work, but it's not quite what I was looking for.

 

I'd like to add a link to an object equivalent to right clicking on the object (as per attached image).

 

Thanks in advance,

 

Jon

 

140303 add link to object.png

0 Likes
Message 10 of 20

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

We still have to use COM API to work with hyperlink now.

 

about your question, I think my code above explains, but I also wrote a more detail blog on it. Could you take a look if it answers your question?

 

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

0 Likes
Message 11 of 20

GeomGym
Advocate
Advocate

Thanks for the reply.

 

I did get the .com code to create a hyperlink label (refer attached .nwd and image). 

But what I would really prefer to do is set a context menu hyperlink from the api

(I have done this  manually for the right panel).

 

140306 manual set context hyperlink.png

 

Can you please advise how to adjust the code to achieve this?

 

Thanks,

 

Jon

0 Likes
Message 12 of 20

Anonymous
Not applicable

Dear Colleagues

 

Is there a possibility with API that hyperlink assigned to any object open by double clicking the object?

 

Regards,

Abdur 

0 Likes
Message 13 of 20

Anonymous
Not applicable

Dear Colleagues

 

You might help me.

I am looking for a possibility to add a 'product manual webpage' by hyperlinking each individual object of a model in Navisworks. I know that through right clicking any object, i can assign / load any web link.

 

I want to generate a Macro/plugin window next to the 3D Model which

- asks to select any individual object and assign a web link to it.
- after selecting any individual object, gives an option of a button button which takes you to the webpage. 

 

Please help me in coding this. I am new to the programming and learning through this forum.

 

Please help me.

 

Regards,

Abdur Nasir

0 Likes
Message 14 of 20

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

I wrote a blog for this requirement: Double click to open the hyperlink. Hope it helps:

 

http://adndevblog.typepad.com/aec/2015/07/double-click-to-open-the-hyperlink.html

0 Likes
Message 15 of 20

Anonymous
Not applicable

Hi Xiaodong,

 

It seems that the function, Double click to open the hyperlink, is only applied to the Plugins applications.

May I confirm that this function is not applied to control-based applications?

 

Best Regards,

John

0 Likes
Message 16 of 20

xiaodong_liang
Autodesk Support
Autodesk Support

Hi John,

yes, as mentioned in the other thread, the interactive events of .NET control has not been exposed.

while the .NET control can load plugin
http://adndevblog.typepad.com/aec/2014/03/call-plugin-within-application-of-net-control.html

my testing shows, even though the InputPlugin can be loaded in the application of control, it does not work very well. you could try to check if you could make it working better, yet it is also not a supported scenario of us.

0 Likes
Message 17 of 20

Anonymous
Not applicable

Hi Xiaodong,

 

Thanks for pointing out we can use Plugin in .Net control.

 

What do you mean "not working very well"?

It cannot import the plugin everytime or it cannot work everytime ot etc?

 

Best Regards,

John

0 Likes
Message 18 of 20

xiaodong_liang
Autodesk Support
Autodesk Support
It can be loaded, but when I played with this idea, sometimes it crashed my application, or no response with the interaction. So I did not even write a blog about it.

it looks somebody else is using such way, e.g.
http://forums.autodesk.com/t5/navisworks-api/capturing-mouse-wheel-events-in-toolplugin-2016-api/td-...

again, since it is not a native way exposed for .NET control, it would have to be at your own risk.
0 Likes
Message 19 of 20

Anonymous
Not applicable

Dear Xiaodong,

 

I see. Thanks for providing your experience on the plugin.

 

I will try myself to see whether it fits our application.

 

Best Regards,

John

0 Likes
Message 20 of 20

btmsoftware
Advocate
Advocate

you code works well, however, it removes the old links. Is it possible to ADD a link, not replace the existing ones ?

0 Likes