Thursday, May 10, 2007

DWG TrueView used as ActiveX Control

You can use Visual Studio to automate the free Autodesk DWG TrueView application.

Select Choose Items in the Toolbox and add the COM Component "C:\Program Files\DWG TrueView 2008\AcCtrl.dll".

Now it can be added to a form. Here is how the most simple code can look like with VB.NET to open and view a DWG file using TrueView.

Public Class Form1 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load AxAcCtrl1.PutSourcePath("C:\Program Files\AutoCAD 2008\Sample\colorwh.dwg") End Sub End Class

12 comments:

  1. Restored comment
    by JTB World
    Using a code like below and it works to use DWG TrueView in for example Access 2007 or any other application that supports VBA. Make sure to insert the ActiveX Control Autodesk AcCtrl.

    Private Sub Form_Load()
    AcCtrl0.PutSourcePath "C:\Program Files\AutoCAD 2008\Sample\colorwh.dwg"
    End Sub

    ReplyDelete
  2. Restored comment
    by Anonymous
    Hi there,

    I am trying to use the SilentPublish method of the control. But it accepts ref object pArraybstrDWGFileFullPath; I want to know what is equivalent for it in C#.

    Thank in advance.

    ~ Yogi

    ReplyDelete
  3. Restored comment
    by JTB World
    pArraybstrDWGFileFullPath is just an array of strings like this in C#:

    string[] pArray = new string[0] {"C:\\Program Files\\AutoCAD 2008\\Sample\\Tablet.dwg"};
    AxAcCtrl1.SilentPublish(pArray);

    ReplyDelete
  4. Restored comment
    by Anonymous
    I have the AcCtrl control in a VB 6 app. I load the DWG file with the .PutSource command. How can I automatically plot a DWG file? If I use the .Plot function, the Plot dialog displays. I want to bypass the dialog. Can you provide an example of how to send keystrokes to this plot dialog or any other example that will allow me to directly plot a DWG file? Thank you

    ReplyDelete
  5. Restored comment
    by JTB World
    You should use pArraybstrDWGFileFullPath to plot in silent mode as showed in previous comments.

    ReplyDelete
  6. Restored comment
    by Anonymous
    JTB World, thank you for the suggestion. SilentPublish does appear that it would work for me, the problem I am having now is that Publishing is not working as desired. For example, if I open up a DWG drawing in DWG TrueView 2008, click on File->Page Setup Manager, set what plotter to use and then click on File->Publish, select the Page Setup dropdown, the Plot device in the Details section is not the same plotter that I set with Page Setup Manager. How can I set the Plot Device (in File Publish) to be the same as from my File->Page Setup Manager? Is that device embedded in the DWG file? Do I need AutoCAD to set this in the DWG file and then import the new setup? Thank you

    ReplyDelete
  7. Restored comment
    by JTB World
    I don't know off hand how it works.

    ReplyDelete
  8. Restored comment
    by Anonymous
    OK, thank you.

    ReplyDelete
  9. Restored comment
    by Anonymous
    Hello JTB,

    Thanks for great post.

    My rquirement is something like I need to publish/plot the DWG file as DWFx.

    Please suggest, what is the best way to do it.

    Thanking you in advance.

    ReplyDelete
  10. Restored comment
    by JTB World
    "publish/plot the DWG file as DWFx"
    I don't have a solution for that.

    ReplyDelete
  11. Restored comment
    by Anonymous
    Use
    axAcCtrl1.SetPc3File("DWF6 ePlot.pc3"); C# users

    ReplyDelete
  12. I've made a simple drawing viewer in VB6 using this control so users can just punch in a drawing number instead of browsing, but it is too slow on startup - especially on the initial launch. Yes, I know it's zombified AutoCAD and a large program, but unless there are some tricks to speed up loading the form due to this control being present, my users will not use my app, making the whole excersize effing pointless. The fact Autodesk refuses to create a lightweight viewer that will open the majority of the files created by their own programs is maddening. Yes, I know about Design Review and it is a kitchen-sink, pig-slow program to promote yet another proprietary file format (dwf)!

    ReplyDelete