Author Topic: AcadApplication.Visible = False  (Read 8371 times)

0 Members and 1 Guest are viewing this topic.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16723
  • Superior Stupidity at its best
AcadApplication.Visible = False
« on: October 06, 2004, 12:00:22 AM »
Ok.... here is my dilemna....

I am busy putting together an application in VB that will access the AutoCAD object model and perform a series of tasks with AutoCAD...

IF AutoCAD is running I will leave the AcadApplication visible, but if the application is not already running I would like to have the application invisible therefore hidden from the users view.

I need to know what hoops I need to jump through (and if it is indeed possible) to manipulate a drawing while the application is hidden.

For example... Does anyone know how I can do this:
Code: [Select]

AcadApplication.Visible = False
AcadApplication.ActiveDocument.ModelSpace.AddLine PT1, PT2
AcadApplication.ActiveDocument.Close True
AcadApplication.Quit
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Ron Heigh

  • Guest
AcadApplication.Visible = False
« Reply #1 on: October 06, 2004, 09:51:41 AM »
I added an OLE ACAD object to my form called "oleDWG"

Then I did this:

Code: [Select]
Private Sub Form_Load()
 
  'initialize dummy AutoCAD session
    oleDwg.DoVerb 0
    oleDwg.DoVerb -3
   
    'display the main form
    frmMain.Show
   
    'set the autocad object
    Set Acad = GetObject(, "AutoCAD.Application.15")

etc....


Using this route, I can edit the drawing as you want, but I haven't tried to add lines and such, just purge.

HTH

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16723
  • Superior Stupidity at its best
AcadApplication.Visible = False
« Reply #2 on: October 06, 2004, 10:45:56 AM »
Ron, this is what I use to grab the Acad session, if it exists, if not it creates it. The cool thing about using this code without the .15 versioning is that it will work with any version of AutoCAD.

Code: [Select]

Function GetAcadObject() As Object
 On Error Resume Next
 Set GetAcadObject = GetObject(, "AutoCAD.Application")
    If Err <> 0 Then
        Err.Clear
        Set GetAcadObject = CreateObject("AutoCAD.Application")
        If Err <> 0 Then
            MsgBox "Could not load or find AutoCAD.", vbExclamation
            End
        End If
    End If
End Function


I'll look into the OLE thing, but I might run into problems with versioning if I have to reference the type libraries at design time.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

hendie

  • Guest
AcadApplication.Visible = False
« Reply #3 on: October 06, 2004, 11:06:45 AM »
I don't know if this has any relevance but I just tried it using an excel workbook.
I could create the application, manipulate cells by sending info from autocad and printout a worksheet all while keeping it invisible

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16723
  • Superior Stupidity at its best
AcadApplication.Visible = False
« Reply #4 on: October 06, 2004, 12:12:14 PM »
I know you can do it in Excel, because it uses a different mthod of accessing it's data. AutoCAD uses graphical coordinates to manipulate its database. The main reason I am asing is because I have yet to be able to manipulate the AutoCAD model from outside AutoCAD with the AutoCAD window not being the topmost and active window.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Jeff_M

  • King Gator
  • Posts: 3945
  • C3D user & customizer
AcadApplication.Visible = False
« Reply #5 on: October 06, 2004, 04:34:27 PM »
Keith, If you access a document from the documents collection, instead of using the active document, AND make sure not to do anything to the screen (regen, redraw, zoom) it should work. For example, this works:
Code: [Select]

Sub test()
Dim AcadApp As AcadApplication 'Object
Dim acadDoc As AcadDocument
Dim dblPt1(2) As Double
Dim dblPt2(2) As Double
Dim dblpt3(2) As Double

dblPt2(1) = 100
dblpt3(0) = 100: dblpt3(1) = 100

Set AcadApp = GetAcadObject
Set acadDoc = AcadApp.Documents.Add("acad.dwt")
AcadApp.Visible = False
acadDoc.SaveAs ("c:\test")
acadDoc.ModelSpace.AddLine dblPt1, dblPt2
acadDoc.ModelSpace.AddLine dblPt2, dblpt3
acadDoc.ModelSpace.AddLine dblpt3, dblPt1
acadDoc.Save
AcadApp.Quit
Set AcadApp = Nothing
End Sub


Another way would be to use ObjectDBX through the AcadObject since it never opens a drawing for editing anyway.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16723
  • Superior Stupidity at its best
AcadApplication.Visible = False
« Reply #6 on: October 07, 2004, 12:15:19 AM »
Cool... I'll try that...since I am working on existing drawings, I suppose I could open the drawing, grab the drawin object and manipulate it there rather than through the documents collection entirely.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Jeff_M

  • King Gator
  • Posts: 3945
  • C3D user & customizer
AcadApplication.Visible = False
« Reply #7 on: October 07, 2004, 10:02:33 PM »
Keith,
Just for fun I tried this in Excel VBA and it worked better than I expected....  :D

Code: [Select]

'A reference to: ObjectDBX 1.0 Type Library
'must be set

Sub testme()
Dim oAcad As Object
Dim oDBX As AxDbDocument
Dim strFname As String
Dim dblPt1(2) As Double
Dim dblPt2(2) As Double
Dim dblpt3(2) As Double
Dim oEnt As AcadEntity

dblPt2(1) = 1000
dblpt3(0) = 1000: dblpt3(1) = 1000

Set oAcad = GetAcadObject 'use Keith's function
oAcad.Visible = False
Set oDBX = oAcad.getinterfaceobject("ObjectDBX.AxDbDocument")
strFname = "C:\test.dwg" 'Must use a real path & name
oDBX.Open (strFname)
'Do some stuff for test purposes
oDBX.ModelSpace.AddLine dblPt1, dblPt2
oDBX.ModelSpace.AddLine dblPt2, dblpt3
oDBX.ModelSpace.AddLine dblpt3, dblPt1
For Each oEnt In oDBX.ModelSpace
    oEnt.Color = acGreen
Next
oDBX.SaveAs strFname
Set oDBX = Nothing
oAcad.Quit
Set oAcad = Nothing

End Sub

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16723
  • Superior Stupidity at its best
AcadApplication.Visible = False
« Reply #8 on: October 07, 2004, 11:02:52 PM »
I think my problems are going to come into play when I want to execute specific commands on the drawing, rather than attempt to draw an object, I will likely be sending a series of commands, such as plotting, lisp commands, BOM proggies and the such... We'll see how it works out.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

TR

  • Guest
AcadApplication.Visible = False
« Reply #9 on: October 09, 2004, 08:46:53 AM »
Quote from: Keith
The cool thing about using this code without the .15 versioning is that it will work with any version of AutoCAD.


Be careful doing it that way if you have multiple versions of AutoCAD installed. It will launch the last version of AutoCAD opened, which may not always be the desired result.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16723
  • Superior Stupidity at its best
AcadApplication.Visible = False
« Reply #10 on: October 09, 2004, 11:38:01 PM »
I know that, but it also will allow the same exact code to be used for ANY version of AutoCAD.
Keep in mind that the problem with the Current Version opening (i.e the last version used) can be easily fixed by checking the registry for multiple versions and if there is, request which version the user would like to use.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

TR

  • Guest
AcadApplication.Visible = False
« Reply #11 on: October 10, 2004, 02:18:28 PM »
I figured you probably already new this but I figured I should bring it up anyhow. If not for you, for anyone else trying to use that code.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16723
  • Superior Stupidity at its best
AcadApplication.Visible = False
« Reply #12 on: October 10, 2004, 06:49:30 PM »
Fair enough.... I usually try to load the object models at runtime since if the user has any version, it will typically work.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Ron Heigh

  • Guest
AcadApplication.Visible = False
« Reply #13 on: October 14, 2004, 04:36:14 PM »
With my ole method, how can I adjust to suit the version of the drawing being opened?
What if I need to iterate through multiple versions of Autocad in the same session.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16723
  • Superior Stupidity at its best
AcadApplication.Visible = False
« Reply #14 on: October 14, 2004, 06:43:27 PM »
You would have to have each version set to an object... i.e.  AutoCAD.Application.15 AutoCAD.Application.16 ... etc...

I am not sure how this would work since there can only be one named reference library at a time. It might mean that you would have to destroy the AC.15 object before you implemented the AC.16 object... I have not tried it so I cannot say for sure... all I can suggest is to try it...

Also remember that once you insert an ole object it becomes referenced by that type library and when you try to move drawings between versions, the ole object may chuck a wobbly....essentially giving an error because of the version.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal