Flipado Posted March 16, 2012 Posted March 16, 2012 Hello there! I'm starting to program in VB and i've done all sorts of tutorials in the area, but i came across an error that has been eating me inside! I'm simply trying to open a .dwg drawing for the past 2 days and i can't still do it! I spent a few hours browsing this forum trying to find a answer, and in spite of all the code post here i still cannot do it... Currently i have the simplest thing. A Label to show me the path of the file. A "Open" Button and a close button. When i click on the open it allows me to chose the drawing in question, then it starts to open but then pop's up an error and nothing happens. The acad.exe process is started but i cannot see the drawing... I've added the References files acdbmgd and acmgd... Probably it's a stupid thing but i'm getting a little worried... This is my code... Imports System.IO Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.Geometry Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.Colors Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim results As DialogResult results = OpenFileDialog1.ShowDialog If results = DialogResult.OK Then Label1.Text = OpenFileDialog1.FileName Dim vAcadApp As AutoCAD.Interop.AcadApplication Dim vAcadDoc As AutoCAD.Interop.AcadDocuments vAcadApp = New AutoCAD.Interop.AcadApplication vAcadApp.Visible = True vAcadDoc = vAcadApp.Documents.Open(OpenFileDialog1.FileName, True) End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Close() End Sub End Class Please help me if you please... cheers Quote
Flipado Posted March 20, 2012 Author Posted March 20, 2012 Hello again! Could anyone give me hints off what i might be doing wrong? If i'm not follwing any forum criteria please let me know... I don't want to be rude or abusive... Cheers Quote
MSasu Posted March 21, 2012 Posted March 21, 2012 How about: Dim objAutoCAD As Object Set objAutoCAD = CreateObject("AutoCAD.Application") 'call default version objAutoCAD.WindowState = 3 objAutoCAD.Documents.Open (pathDrawing) Regards, Mircea Quote
Flipado Posted March 21, 2012 Author Posted March 21, 2012 Mircea thanks for the reply. I tried what you suggested and an error occurred : " Could not create an ActiveX Component" This is what i've been fighting with... When i programme in C, i know that for certain type of functions i have to add some libraries, so i went searching for CAD libraries necessary for this application. I found that i needed to add two files from the AutoCad directory and some imports had to be done... Even after this made the program still wont open... At least i'm expecting to see a normal autocad window. If i open the Task Manager, i see a acad.exe running... Even so... Thank you for the reply Cheers Quote
BlackBox Posted April 1, 2012 Posted April 1, 2012 Fwiw - separately, you may at some point want to code in visual studio (express?) an application that checks for an existing instance of autocad to either getobject, or createobject, in which case this post may be of help: ** note - this example uses an excel application object, but can easily be adapted to get/create an autocad application object. sounds like you need to check for an active process, prior to creating a new instance. Here's a vb.net snippet from one of my projects, for you to pull from: imports excel = microsoft.office.interop.excel imports microsoft.office.interop imports system.diagnostics imports system.io module foo sub excel_foo() dim xlapp as excel.application try [color=seagreen]' look for an existing process, if available getobject[/color] if process.getprocessesbyname("excel").length > 0 then xlapp = ctype(getobject(, "excel.application"), excel.application) [color=seagreen]' else createobject[/color] else xlapp = new excel.application end if [color=seagreen] ' <-- do something[/color] catch ex as exception finally xlapp = nothing end sub end module hth Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.