Code Red > VB(A)

Rename & Delete Dwg File

(1/4) > >>

M-dub:
I just want to make sure this is possible...I don't want the code or anything.  I want to use this as a learning project.  It seems like it should be very easy.

- Existing drawing open in acad (filename = LBDE2761.DWG)
- Prefix that needs to be added to filename = BAE
- Save file as BAE-LBDE2761.dwg
- Delete original file

Just let me know that "yes, it's possible" or "you might have some trouble..."

Thanks,
Mike

Keith™:
in VBA it is entirely possible...

M-dub:
Ok, as I've 'proven' before, I'm new to almost all forms of programming.  I'm using Visual Basic 6.0.
How do I add anything from AutoCAD to the components in the Toolbar?
You have to understand where I'm coming from.  I sometimes don't know what to look for help on.  I know what needs to be done and it makes complete sense to me, but I don't know what I have to do in VB to make it happen.
I've looked in the Object Browser and found nothing that will help me (that I know of anyway).
I think what I need to look for is the current file open (and with focus) in AutoCAD.  Am I on the right track?

<M-dub says to himself>(*Man, I hope they don't get too annoyed with my ignorance!*)

Keith™:
Do you need to write it in VB6?
It can be done right from the VBIDE if you want ...

But since you asked ...

IMHO the AC object should NEVER be added to a VB program except at runtime, otherwise you create problems that occur between the object model of different versions of AutoCAD....

So how do you do it???

I know you asked for no code, but in the interest of helping you in your endevour (plus I already use this function alot in VB) I will share it ...


--- Code: ---'Function to find AutoCAD or load it if not found
Function GetAcadObject() As Object
'Get the AutoCAD.Application as defined in the registry
 Set GetAcadObject = GetObject(, "AutoCAD.Application")
 'if we could not get it, then it is not running so...
    If Err <> 0 Then
        Err.Clear
        'lets create it ..i.e. start AutoCAD
        Set GetAcadObject = CreateObject("AutoCAD.Application")
        If Err <> 0 Then
        'if we can't start it then notify the user
            MsgBox "Could not load or find AutoCAD.", vbExclamation
            End
        End If
    End If
End Function

--- End code ---


The function call is used in this scenario:

--- Code: ---
 Dim AC as Object
 Set AC = GetAcadObject

--- End code ---


Now this does not help you in programming the task at hand, because you do not have the object model loaded into VB6, to add it do this ...

In your VB6 program select Project->References
Scroll to the AutoCAD200xType Library and check the box

To be able to access the AutoCAD object model in VB6 define all of your variable types (i.e. Drawing, Line etc.) as the appropriate AutoCAD types. This includes the above example, rather than define AC as an object (which it should be in the final build) define it as AcadApplication. This will improve your ability to write code in the IDE. Once you have completed your coding and the program works properly, go back and put in generic types for the AutoCAD objects (i.e. As Object) and if you use any AutoCAD types for other variable DIMs change them to either a Variant or equivalent VB data type.

Now, there are some other issues that you probably will encounter, but I will let you tell me what they are and I will address them as the need arises.

M-dub:
Thank you so much, Keith.
I'm going to give this a valiant effort and see what I can do.  I've actually switched to the VBIDE already. ;)
Thanks again, and I'll post my progress...
(No laughing!  I'm new to this!  ;) )

Navigation

[0] Message Index

[#] Next page

Go to full version