Monday, August 27, 2007

An online solution for viewing DWF files, with capability to drag into Autocad

On the Autodesk Forums, I recently enquired about a way of replacing WHIP! for autocad, which allowed us to have an intranet with standard details for our cad users to open up, view, and if needed drag and drop into autocad.

When Autodesk discontinued WHIP! they replaced it with DWF Viewer, and more recently have released Autodesk Design Review.

After much playing around I developed the solution you see in the image (I've zoomed out on the drawing).

Our intranet had a javascript function for opening DWF's in a certain sized window, called dwfwin, I edited that to open an ASP.Net page with the address of the drawing in the querystring.

From then, I filled out the code for the Design Review embedded drawing, using the value passed in the querystring.

Here is the code I used:

<% Dim dwf
dwf = Request.QueryString("dwf")

Dim dwfxml

dwfxml = Split(dwf, "/")
Dim arraymax
arraymax = UBound(dwfxml)

dwfxml = Left(dwfxml(arraymax), Len(dwfxml(arraymax)) - 4)
dwfxml = "http://bwonline/dwf/xml/"& dwfxml & ".xml"
'response.write (dwfxml)
%>

CODEBASE=http://www.autodesk.com/global/dwfviewer/installer/DwfViewerSetup.cab#version=7,0,0,928
WIDTH="97%" HEIGHT="94%">

">
That worked fine for viewing drawings, though it was slower than our old WHIP! solution, due to the extra features it has, but it's not a big issue for us. Another problem was though, that it couldn't drag and drop the drawing into Autocad - which was the main point of the exercise. For this, we used I-Drop.

The idea behind I-Drop is that you make a picture of the drawing file, and that picture has an XML file behind it that tells the site where the .DWG file is that Autocad will import when that image is dragged and dropped. However I wasn't going to go through and make images of all our drawings, and we didn't need them wasting extra space so I came up with the idea of making the image a small 'D' (for drag/drop), and as you can see from the image above, that's what happened.

To do this, I needed to generate the XML file, as I wasn't going to go through and make them for each individual one, so I created some code to do it for me, using the System.XML Namespace. There is a certain layout you need to use for the I-Drop XML file, it needs to look like this:

<?xml version="1.0"?>
<package xmlns="x-schema:idrop-schema.xdr">
<proxy defaultsrc="d.jpg" />
<dataset defaultsrc="L:/acad/acad_str/drg-exs/1-9.dwg" />
</package>


The values that change are the d.jpg is the image used, and the .dwg file is the location of the drawing file. This was easy for me to generate automatically as the DWF's and DWG's are kept in the same folder on our network.


To generate this file, I added this code to the Page_Load sub of my aspx page.

'Construct xml file name from dwf input string
Dim dwf
dwf = Request.QueryString("dwf")
Dim dwfxml
Dim dwfdwg
dwfxml = Split(dwf, "/")
Dim arraymax
arraymax = UBound(dwfxml)

dwfxml = Left(dwfxml(arraymax), Len(dwfxml(arraymax)) - 4)

dwfxml = "D:\Inetpub\intranet\bwo2\dwf\xml\" & dwfxml & ".xml"
dwfdwg = Left(dwf, Len(dwf) - 1) & "g"

'check if it has already been written
If Not File.Exists(dwfxml) Then
'Write xml file

Dim xmlNewDocument As XmlDocument = New XmlDocument
Dim sb As StringBuilder = New StringBuilder
sb.Append("")
sb.Append("")
sb.Append("")
sb.Append("")
sb.Append("")

xmlNewDocument.LoadXml(sb.ToString())

xmlNewDocument.Save(dwfxml)

End If


Basically this works out what the name of the .xml file will be from the querystring inputted, in my case I made it the name of the .dwf file, but with the extension changed.

These XML files only need to be made once so I kept them all in the one spot, and made my code check if one was made, if not, it created it, so there would be a slightly longer load the first time - but then that would never happen again.

Then later on, in the body of my page just after the design review object I used:
<object name="idrop" classid="clsid:21E0CB95-1198-4945-A3D2-4BF804295F78" width="15" height="15">
<param name="background" value="background.jpg">
<param name="proxyrect" value="0,0, 15,15">
<param name="griprect" value="0, 0, 15, 15">
<param name="package" value="<% =dwfxml %>"/>
<param name="validate" value="1">
<embed width="15" height="15" background="background.jpg" proxyrect="0,0, 15,15"
griprect="0, 0, 15, 15" package="<% =dwfxml %>" validate="1" src="background.jpg" name="idrop">
</embed>
</object>

With dwfxml variable being the generated name and location of the xml file.

A point to note is that IE7 has security on objects like these, where you will need to click once to turn on the object, and again to use it. But that's not much of a big deal.

So the user simply reviews the drawing, then when they wish to, they click and drag the D character into Autocad. All staff need the I-Drop plugin, and Design Review, so I have linked to those on the page if anything doesn't show up properly. Problem solved! All seems to work well!

2 comments:

Rajesh Excelencia said...

Hi Rod,
Awsome blog.

We are stuck with a similar issue. We need to open a dwf file in asp.net from an original dwg file which is on the server. Then put some markups to the same.
We then need to save the dwf file back to the server as dwg file.
Now some one else should also be able to open this dwf in asp.ent page review the markups, edit/delete the markups and save the dwf whic should inturn save the original dwg on the server.

Is this possible if yes then how can we achieve this.

Rajesh Excelencia said...

Hi Rod,
Awsome blog.

We are stuck with a similar issue. We need to open a dwf file in asp.net from an original dwg file which is on the server. Then put some markups to the same.
We then need to save the dwf file back to the server as dwg file.
Now some one else should also be able to open this dwf in asp.ent page review the markups, edit/delete the markups and save the dwf whic should inturn save the original dwg on the server.

Is this possible if yes then how can we achieve this.