Navisworks API

Reply
Contributor
Posts: 15
Registered: ‎09-23-2008
Message 1 of 11 (3,003 Views)
Accepted Solution

Add Link to object via .net

3003 Views, 10 Replies
08-25-2011 01:41 PM

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!

ADN Support Specialist
xiaodong.liang
Posts: 1,190
Registered: ‎06-12-2011
Message 2 of 11 (2,976 Views)

Re: Add Link to object via .net

08-29-2011 11:39 PM in reply to: timbot

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



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Active Contributor
Posts: 49
Registered: ‎02-13-2009
Message 3 of 11 (2,872 Views)

Re: Add Link to object via .net

11-01-2011 11:32 AM in reply to: timbot

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

New Member
Posts: 2
Registered: ‎08-10-2012
Message 4 of 11 (1,770 Views)

Re: Add Link to object via .net

08-10-2012 07:47 AM in reply to: xiaodong.liang

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

Member
Posts: 5
Registered: ‎10-08-2012
Message 5 of 11 (1,501 Views)

Re: Add Link to object via .net

10-08-2012 05:41 AM in reply to: xiaodong.liang

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

 

Active Contributor
Posts: 29
Registered: ‎03-12-2013
Message 6 of 11 (712 Views)

Re: Add Link to object via .net

07-22-2013 06:38 PM in reply to: xiaodong.liang

Hi all,

 

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

 

Thanks,

John

ADN Support Specialist
xiaodong.liang
Posts: 1,190
Registered: ‎06-12-2011
Message 7 of 11 (703 Views)

Re: Add Link to object via .net

07-25-2013 10:23 PM in reply to: JohnHon

Hi John,

 

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



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Valued Contributor
Posts: 66
Registered: ‎03-25-2012
Message 8 of 11 (324 Views)

Re: Add Link to object via .net

02-24-2014 07:51 AM in reply to: xiaodong.liang

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)?

Valued Contributor
Posts: 66
Registered: ‎03-25-2012
Message 9 of 11 (291 Views)

Re: Add Link to object via .net

03-03-2014 09:23 AM in reply to: GeomGym

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

ADN Support Specialist
xiaodong.liang
Posts: 1,190
Registered: ‎06-12-2011
Message 10 of 11 (262 Views)

Re: Add Link to object via .net

03-05-2014 05:32 PM in reply to: GeomGym

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



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community