Results 1 to 9 of 9

Thread: early binding

  1. #1

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Post

    I have autocad open with a drawing loaded. I want my program to get the path of the drawing. This code starts a new session of autocad. I am guessing it has to do with the set statement and the use of the new keyword. Is there a different key word. Every text I have uses the new key word.

    Option Explicit

    Private Sub Command1_Click()
    Dim x, y
    Dim AC As AutoCAD.AcadApplication
    Set AC = New AutoCAD.AcadApplication
    x = AC.ActiveDocument.Path
    MsgBox (x)
    End Sub
    Thank you for your time and have a good day

    ------------------
    I am so skeptacle, I can hardly believe it!

  2. #2

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Post

    here is my problem.
    if I use the line
    Set AC = AutoCAD.AcadApplication
    I have two problems
    1. intellisense wont even give me the .AcadApplication I have to copy/paste
    2 when it runs I get an error. method not found.
    is this an example of why not to use early binding?
    It seems that if I use early binding I have to create a NEW instance of AutoCAD.

    I am trying to replace the following code which is late binding(but it works fine). This is not a major problem, I am just trying to use a higher performance method.
    Dim AC, acadDoc As Object
    Dim path as String
    Set AC = GetObject(, "autoCad.application") 'get the current autocad session
    Set acadDoc = AC.ActiveDocument
    Path = acadDoc.Path 'get the autocad path


    thank you for your time and have a good day



    [This message has been edited by badgers (edited 12-30-1999).]

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    If you're not adding a reference to ACAD library, then you won't see tbe intellisence dropdowns, also you would have to use CreateObject to get it working.
    Code:
    Dim objACAD As Object
    
    Set objACAD = CreateObject("AutoCAD.AcadApplication")
    This will give you the ability to work with AutoCAD.ACADApplication object.

    But if you add a reference to AutoCAD library, then you can see all properties and methods by using object browser (or intellisence will show you them in a dropdown list)

    ------------------

    Serge

    Software Developer
    Access8484@aol.com
    ICQ#: 51055819


  4. #4
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    Badgers:

    Instead of declaring AC as object (actually, you have it declared as a variant), declare it as AutoCad.AcadApplication with the Autocad library referenced.

    You should then be able to return an instance of the active autocad session back to your AC object using the GETOBJECT function. You will then have early binding on your object when you invoke the properties and methods.

    NOTE: do not use the NEW keyword, because you are returning an existing instance of autocad and you do not want to create a new instance.

  5. #5

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Post

    thank you for your replies.
    Here is my problem.
    Serge. What you have is not, to my understanding, early binding. declaring it as an object is late binding.
    Clunietp
    Instead of declaring AC as object (actually, you have it declared as a variant), declare it as AutoCad.AcadApplication with the Autocad library referenced.
    this is what I have done. The autocad library is referenced. The intellisence gives me the .AcadApplication only If I use the NEW keyword.
    how is the
    Dim AC As AutoCAD.AcadApplication
    declaring it as a variant? I can't see how that is true.
    Does anyone have autocad? Maybe this is a bug with autocad and early binding
    thank you for your time and have a good day


    ------------------
    I am so skeptacle, I can hardly believe it!

  6. #6

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Post

    both of the following do not work.
    Private Sub Command1_Click()
    Dim AC As AutoCAD.AcadApplication
    Set AC = GetObject(, "AutoCAD.AcadApplication")
    End Sub

    Private Sub Command2_Click()
    Dim ACC As AutoCAD.AcadApplication
    Set ACC = AutoCAD.AcadApplication
    End Sub
    first one give an ActiveX error
    the second gives an error, method not found.
    THE AUTOCAD LIBRARY IS REFERENCED!!
    this works but is late binding(as I understand Late binding)
    Private Sub Command3_Click()
    Dim Auto As Object
    Set Auto = GetObject(, "AutoCAD.application")
    MsgBox Auto.Path
    End Sub


    ------------------
    I am so skeptacle, I can hardly believe it!

  7. #7

    Thread Starter
    Hyperactive Member badgers's Avatar
    Join Date
    Sep 1999
    Location
    Madison, WI USA
    Posts
    444

    Post

    thank you all for your input and time.
    I have found that AutoCAD R14.0 has a bug
    which does not allow early binding.
    sorry to have bothered you all.

    ------------------
    I am so skeptacle, I can hardly believe it!

  8. #8
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386

    Post

    AFAIK, early binding is declaring an object as the real type,
    Dim c As ADODB.Recordset
    Late binding is
    Dim c As Object
    c = CreateObject/GetObject....

    The New keyword you use when you want a new object (huh.. hmmm.. i dont know how else to explain), to set a reference it shouldbe enough to declare something as the object you want.
    I don't know why early binding doesn't work, maybe you can find something on the Autodesk site about it, I've never worked with Autocad (neither with GetObject...) but if Command3 is the only way it works, it looks to me like early binding is not possible.

  9. #9
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    Sorry, badgers, I was referring to your second post, where you had put: Dim AC, acadDoc As Object

    when you use DIM X, Y as long
    X is a variant
    Y is a long

    But that does not matter now....

    I guess you'll just have to use late binding..

    Anyone else?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width