programs to work with 04 & 03

Discussion in 'AutoCAD' started by Andrew Elmore, Jul 30, 2003.

  1. How can I add references in my projects to work with ADT 3.3 and 04. I use
    04 but some people are still useing 3.3 so I need both refs.

    Thanks,
    Andy
     
    Andrew Elmore, Jul 30, 2003
    #1
  2. Andrew Elmore

    Danny P. Guest

    Andrew,

    I would venture a guess that you can't do this. This was an issue with 3.0
    & 3.3, and it required us to maintain 2 versions, one for 3.0 and one for
    3.3. Although I haven't tested it, I would say that this is still true.

    You might also try posting this in the
    autodesk.aec.arch-desktop.customization newsgroup. Some of the ADT API
    developers lurk there and will probably post back.

    Hope that helps,
    -Danny Polkinhorn
    Perkins & Will
    Atlanta
     
    Danny P., Jul 30, 2003
    #2
  3. Thanks I'll give it a try.
    Andy

     
    Andrew Elmore, Jul 30, 2003
    #3
  4. Hi Andrew,

    I have been trying to resolve this issue in a desultary fashion for some
    time.

    The information below comes from the AUGI VBA Guild. It start with Richard
    Binning providing information which I tried and I succeeded in loading the
    ALD libraries based on Richard's suggestions.

    However, I could not get my code to recognise that the libraries were
    loaded.

    The top message posted today by Ed Jobe in the AUGI VBA guild is my next
    port of call.

    I haven't had time to try Ed's suggestions yet, but the more of us that try,
    the more likely we will be to get a working answer.

    Lastly, I have some information from Autodesk, that the process may be
    affected by a bug in the AutoCAD API's and for the moment it may not work
    anyhow with R2004.
    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au


    ----- Original Message -----
    From: Ed Jobe
    To:
    Sent: Thursday, July 31, 2003 4:03 AM
    Subject: [VBA] Setting references programmatically


    A while back, someone asked how to set references programmatically, as
    in when you have different versions of a program you need to reference.
    The requestor was having trouble with the vbaide prompting to save the
    project after the reference was set. I just now had time to check into
    it. If you clean up after yourself, deleting the reference, you won't
    have this problem. I modified my functions to allow for this. I also
    added one to set the ref by GUID. That way you don't have to worry about
    checking for a valid file path. You can get the necessary GUID info
    using the sample sub below.


    Sub testref1()
    'Sample to demonstrate working with references
    'Set reference for ADO.
    '"Microsoft AcitveX Data Objects library 2.7"
    Dim objRef As vbide.Reference
    Set objRef = SetReferenceByFile("C:\Program Files\Common
    Files\system\ado\msado15.dll")
    ' Set objRef =
    SetReferenceByGUID("{EF53050B-882E-4776-B643-EDA472E8E3F2}", 2, 7)
    If objRef Is Nothing Then
    MsgBox Err.Number & ", " & Err.Description, vbExclamation,
    "Error setting reference."
    Else
    Debug.Print objRef.Guid & ", " & objRef.Major & ", " &
    objRef.Minor
    End If
    DeleteReference objRef

    End Sub


    Public Function DeleteReference(ref As vbide.Reference)
    On Error GoTo ErrorHandler
    Dim objVB As VBE
    Dim objRef As Reference

    Set objVB = Application.VBE
    objVB.ActiveVBProject.References.Remove ref
    GoTo Finish:
    ErrorHandler:
    MsgBox Err.Number & ", " & Err.Description, vbExclamation,
    "Error deleting reference."
    Finish:
    Set objVB = Nothing
    End Function

    Public Function SetReferenceByFile(filepath As String, Optional
    DisplayErrors As Boolean) As vbide.Reference
    'Returns a Reference object if successful in setting a reference in
    the current dvb,
    'given the FilePath of a tlb, olb, dll. The DisplayErrors option
    determines
    'whether or not an error message will be displayed upon erroring.
    On Error GoTo ErrorHandler
    Dim objVB As VBE
    Dim objRef As vbide.Reference
    Dim objRefs As vbide.References
    Dim strPath As String

    Set objVB = Application.VBE
    Set objRef =
    objVB.ActiveVBProject.References.AddFromFile(filepath)
    Set SetReferenceByFile = objRef
    GoTo Finish:
    ErrorHandler:
    If Err.Number = 32813 Then
    'reference was already set, just return True
    Set objRefs = objVB.ActiveVBProject.References
    For Each objRef In objRefs
    If objRef.FullPath = filepath Then
    Set SetReferenceByFile = objRef
    End If
    Next objRef
    Else
    If DisplayErrors = True Then
    MsgBox Err.Number & ", " & Err.Description, vbExclamation,
    "Error setting reference."
    Else

    End If
    Set SetReferenceByFile = Nothing
    End If
    Finish:
    Set objVB = Nothing
    Set objRef = Nothing
    End Function

    Public Function SetReferenceByGUID(strGUID As String, maj As Long, min
    As Long) As vbide.Reference
    'Returns a Reference object if successful in setting a reference in
    the current dvb,
    'given the GUID of a tlb, olb, dll. Using a GUID avoids having to
    test
    'for a valid filepath.
    On Error GoTo ErrorHandler
    Dim objVB As VBE
    Dim objRef As vbide.Reference
    Dim strPath As String

    Set objVB = Application.VBE
    Set objRef = objVB.ActiveVBProject.References.AddFromGuid(strGUID,
    1, 1)
    Set SetReferenceByGUID = objRef
    GoTo Finish:
    ErrorHandler:
    If Err.Number = 32813 Then
    'reference was already set, just return True
    Set SetReferenceByGUID = objRef
    Else
    Set SetReferenceByGUID = Nothing
    End If
    Finish:
    Set objVB = Nothing
    Set objRef = Nothing
    End Function

    Ed Jobe



    ---footer---
    You are receiving this message because you are subscribed to
    . If you wish to unsubscribe from this list, please send
    an email to mailto:?Subject=unsubscribe with the
    word "unsubscribe" (without the quotes) in the subject of the email and
    follow any instructions that follow. If you require any help with
    subscription matters or general Guild information then please send an email
    to mailto:.

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

    ----- Original Message -----
    From: Binning, Richard L.
    To: '' ; VBA Guild ()
    Sent: Wednesday, July 23, 2003 10:44 PM
    Subject: Re: [VBA] FW: Loading References when ALD but not Vanilla ACAD


    You can check the registry for the application that is running the macro.
    Check the "default" value of this key:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App
    Paths\acad.exe

    From the path to the executable, you should be able to detect what flavor
    the application
    is.

    You could also check the current profile with a function like that shown
    below:

    Function Get_ActiveProfile() As String
    ' This function returns the current setting of
    ' ActiveProfile.
    On Error Goto Err_Relief
    Dim preferences As AcadPreferences
    Dim currActiveProfile As String
    Set preferences = ThisDrawing.Application.preferences
    ' Retrieve the current ActiveProfile value
    currActiveProfile = preferences.Profiles.ActiveProfile
    Err_Relief:
    If Len(currActiveProfile) < 1 then
    msgbox "Error detected, profile unknown!"
    Else
    Get_ActiveProfile = currActiveProfile
    End if
    Set preferences = Nothing
    End Function

    To set a reference to a particular library, you will have to add a reference
    to the microsoft vba extensibility 5.3 library.
    You can then declare some objects to hold the reference values such as:

    Dim oVBE As VBIDE.VBE
    Dim oVBP As VBIDE.VBProject
    Dim oVBPs as VBIDE.VBProjects
    Dim oVBR As VBIDE.Reference
    Dim oVBRs As VBIDE.References

    Now populate your objects...

    Set oVBE = Application.VBE
    Set oVBPs = oVBE.VBProjects
    Set oVBP = oVBPs("Your project title")
    Set oVBRs = oVBP.References

    You should be able to try attaching your desired ref here and do some
    trapping.

    On Error Resume Next
    Set oVBR = oVBRs("Your Type Library")
    If Err then
    'clean it up
    else
    'restore proper error handling here
    endif


    Does that give you enough to get started?

    P.S. I wrote that on the fly not in the VBA editor so I might have some
    error of exclusion or spelling.




    Richard Binning

    AUGI Guild Moderator

    AUGI Exchange Approvals Manager

    Member # 15067

    Win2k SP2

    Acad 2002

    Architectural Desktop 3.3 SP2

    Land Development Desktop 3.0

    Building Systems 3.0

    PIV 1.3 GHZ

    512 RAM

    OXYGEN GVX1 32mb AGP

    Mailto:






    ---footer---
    You are receiving this message because you are subscribed to
    . If you wish to unsubscribe from this list, please send
    an email to mailto:?Subject=unsubscribe with the
    word "unsubscribe" (without the quotes) in the subject of the email and
    follow any instructions that follow. If you require any help with
    subscription matters or general Guild information then please send an email
    to mailto:.

    -------------------------------------
     
    Laurie Comerford, Jul 31, 2003
    #4
  5. Andrew Elmore

    Andy Elmore Guest

    test

     
    Andy Elmore, Aug 5, 2003
    #5
  6. I have not tried this but.... maybe if I use more class libraries to
    interface with acad then over comeing different version could be easier. So
    if I had to classes 1 for 04 other for 3.3 then I could call into them to
    get what I need.

    imports ADT_class4
    imports ADT_class3
    imports AutoCAD

    try
    Dim Acad_con4 as new ADT_class4
    Dim Acad_app3 as new ADT_class3
    Dim Acad_app as AcadApplication
    Dim Acad_doc as AcadDocument
    try
    Acad_app=Acad_con4.Application
    catch
    try
    Acad_app=Acad_con3.Application
    catch
    msgbox("Did not work!")
    end try
    end try
    Catch
    end try

     
    Andrew Elmore, Aug 6, 2003
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.