Visual Basic Customization

Reply
Contributor
sgikas
Posts: 11
Registered: ‎09-27-2007
Message 1 of 7 (1,029 Views)

Loading AutoCad Type Library with VB6

1029 Views, 6 Replies
06-17-2012 09:20 PM

I am not a programer, I am an enginner using Visual Basic 6

 

In my VB6 program I need to check the Loaded AutoCad Version and then Load the associated Type Library

How can I do this

*Expert Elite*
Alfred.NESWADBA
Posts: 8,893
Registered: ‎06-29-2007
Message 2 of 7 (1,007 Views)

Re: Loading AutoCad Type Library with VB6

06-21-2012 01:31 AM in reply to: sgikas

Hi,

 

>> I need to check the Loaded AutoCad Version

Check the sysvar ACADVER, it gives you e.g. this value for AutoCAD 2012-based product:

ACADVER = "18.2s (LMS Tech)" (schreibgeschützt)

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Contributor
sgikas
Posts: 11
Registered: ‎09-27-2007
Message 3 of 7 (1,006 Views)

Re: Loading AutoCad Type Library with VB6

06-21-2012 01:42 AM in reply to: sgikas

 

Thanks for that, ...........but

How do i then load the associated Type Library programably???

 

Thanks in advance

 

Regards

*Expert Elite*
Alfred.NESWADBA
Posts: 8,893
Registered: ‎06-29-2007
Message 4 of 7 (1,004 Views)

Re: Loading AutoCad Type Library with VB6

06-21-2012 01:59 AM in reply to: sgikas

Hi,

 

>> How do i then load the associated Type Library programably???

You have to create different projects (can be the same source-code if signatures are compatible) each having it's version-depending references (as you can't create a project without having any references set).

Then don't decide what reference to load but what project to load.

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Distinguished Contributor
eljobe
Posts: 704
Registered: ‎01-24-2003
Message 5 of 7 (978 Views)

Re: Loading AutoCad Type Library with VB6

06-28-2012 07:43 AM in reply to: Alfred.NESWADBA

If you set a reference to the ide, you can control it programatically. In vba, the reference is "Microsoft Visual Basic for Applications Extensibility 5.3". I don't remember what it is for VB. I wrote the following subs to load references by filename or guid.

Public Function SetReferenceByFile(FilePath As String, Optional DisplayErrors As Boolean) As VBIDE.Reference
    'returns True 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 Object  'VBE
    Dim objRef As VBIDE.Reference
    Dim objRefs As VBIDE.References
    Dim strPath As String
    
    Set objVB = AcadApplication.VBE
    Set objRef = objVB.ActiveVBProject.References.AddFromFile(FilePath)
    SetReferenceByFile = True
    GoTo Finish:
ErrorHandler:
    If Err.Number = 32813 Then
        'reference was already set, just return the reference
         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, "SetReferenceByFile."
        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 objRefs As VBIDE.References
     Dim strPath As String

     Set objVB = Application.VBE
     Set objRef = objVB.ActiveVBProject.References.AddFromGuid(strGUID, maj, min)
     Set SetReferenceByGUID = objRef
     GoTo Finish:
ErrorHandler:
     If Err.Number = 32813 Then
         'reference was already set, just return the reference
         Set objRefs = objVB.ActiveVBProject.References
         For Each objRef In objRefs
             If objRef.GUID = strGUID Then
                 Set SetReferenceByGUID = objRef
             End If
         Next objRef
     Else
         Set SetReferenceByGUID = Nothing
     End If
Finish:
     Set objVB = Nothing
     Set objRef = Nothing
 End Function

 

Contributor
sgikas
Posts: 11
Registered: ‎09-27-2007
Message 6 of 7 (972 Views)

Re: Loading AutoCad Type Library with VB6

06-28-2012 04:21 PM in reply to: sgikas

Thanks

 

I will try it.

 

Hopefully I can make it work with VB6

 

Regards

Active Contributor
cvc-it-mb
Posts: 45
Registered: ‎10-20-2006
Message 7 of 7 (904 Views)

Re: Loading AutoCad Type Library with VB6

08-27-2012 05:28 PM in reply to: eljobe

Can you provide a small snippet on how to use these 2 functions?

 

Thanks!

Jim

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community