Supporting XRefs

Supporting XRefs

XRefs (external references) are used within CAD documents to reference external documents to be loaded within a main document. WebViewer Server by default does not support these XRefs as it needs to know context information about the location of the XRef files.


We do provide an option TRN_CAD_XREF_CONFIG_URL that will allow you to provide this context information, but there are a few steps that will need to be done in order to use this option.


To use this option, you will need to do the following.


  1. Determine a way to match XRefs to a document.
  2. Create a server which will, given a request with a document, return the correct XRefs.
  3. Add the XRef files to an accessible file location on WebViewer Server.
  4. Set TRN_CAD_XREF_CONFIG_URL to the created server.

Determine a way to match XRefs to a document

The most common way is by providing a header during the load document call, and then matching this header to the correct XRefs.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const options = {
4 customHeaders: { MyDocIdentifier: "12345id" },
5 filename: "Document.pdf"
6 };
7 const url = 'http://<documentserver>/mydocument.pdf'
8 instance.loadDocument(url, options);
9 });
10});

Now the server will see MyDocIdentifier when WebViewer Server requests it, it can then return the XRef paths for this document like so:

JSON

1{
2XRefSearchPaths: ['mypath/mpath/path', 'mypath2/path/path']
3}

WebViewer Server would then look in these paths for XRefs.

Create a server to return the XRefs


In the next step you will need to create a server that will do the following:


  1. Accept a GET request
  2. Read the a header from the request
  3. Return XRefs based on this header in JSON format


Paths returned by the server should have the following traits

  • They should be absolute paths
  • They should point to the folder containing the external files
  • The path should only be a local system path

The code below is a rough example of how you would do this. The specifics of how you implement XRef path selection will be specific to your system.

Python

1from http.server import BaseHTTPRequestHandler,HTTPServer
2import json
3
4xrefPaths = {
5'docId1' : ['/path/path1/path', '/path/path2'],
6'docId2' : ['/path3/path']
7}
8
9class Server(BaseHTTPRequestHandler):
10 def _set_headers(self):
11 self.send_response(200)
12 self.send_header('Content-type', 'application/json')
13 self.end_headers()
14
15 def do_HEAD(self):
16 self._set_headers()
17
18 def do_GET(self):
19 self.send_response(200)
20 self._set_headers()
21 # here you would get each individual XRef path based on the ID
22 # and return them in JSON below
23 myId = self.headers["MyDocIdentifier"]
24 myPaths = xrefPaths[myId]
25 self.wfile.write(json.dumps({'XRefSearchPaths': myPaths }).encode())
26
27def run(server_class=HTTPServer, handler_class=Server, port=8008):
28 server_address = ('', port)
29 httpd = server_class(server_address, handler_class)
30
31 print('Starting httpd on port %d...' % port)
32 httpd.serve_forever()
33
34if __name__ == "__main__":
35 run()

Add the XRefs to the server

Using Docker

In docker you should mount volumes at the specific XRef paths like so:

YAML

1volumes:
2 /myfiledirectory/dir:/usr/local/apache-tomcat/xrefFiles

You would then set XRefs to be looked for inside of this xrefFiles directory.

Using Windows

On windows, you only need to provide the correct paths and your XRefs should be found.

Set TRN_CAD_XREF_CONFIG_URL

A prerequiste to this step would be to setup your server over a local network or the internet to be accessible by WebViewer Server. In this example, the server is hosted on 192.168.1.1 under the path getXrefs:

YAML

1TRN_CAD_XREF_CONFIG_URL: 'http://192.168.1.1/getXrefs'

If everything was done correctly, XRefs should now be appearing in your documents.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales