Help - Converting an App from VBA to VB

Help - Converting an App from VBA to VB

Anonymous
Not applicable
327 Views
5 Replies
Message 1 of 6

Help - Converting an App from VBA to VB

Anonymous
Not applicable
I have developed a small application as an AutoCAD VBA Project and I
want to convert the project to VB. I am having a few conceptual
difficulties in getting started and would appreciate a few pointers in
the right direction. I seem to have had little luck in finding info in
the documentation or other books. The only book I have managed to find
is Andrew Roe's "Using VB with AutoCAD".

Basically the project at present is a single .DVB file. I have about
ten AutoCAD commands which run macros in the DVB and these are set up
in AcadDoc.lsp. I presumed at first that I should set up the project
as a DLL, but I can't see how I would call the macros from AutoCAD. I
successfully created a DLL, registered it, set up the references to
the DLL in a dummy DVB file for testing but it won't seem to see the
Public Functions in the DLL.

I thought maybe I should split the project up into a series of
projects (one for each AutoCAD command) and create them as an .EXE
file. I can get this to work but my global variables no longer have
scope in all the modules and I still have the problem referring to
subs and functions that are common to all the commands.

Finally I have an ObjectModified event in the "ThisDrawing" section of
the DVB. I can't seem to see where this would go in a VB file. I can
see how to use GetObject to get the ActiveDocument, but can't seem to
figure how to set up an ObjectModified event.

I would appreciate a nudge in the right direction.

Ian Thomson
0 Likes
328 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
"Ian Thomson" wrote in message
news:015citktpgg26j5c67cb7cp8qppl8l6g45@4ax.com...
> I have developed a small application as an AutoCAD VBA Project and I
> want to convert the project to VB. I am having a few conceptual
> difficulties in getting started and would appreciate a few pointers in
> the right direction. I seem to have had little luck in finding info in
> the documentation or other books. The only book I have managed to find
> is Andrew Roe's "Using VB with AutoCAD".

declare a var called ThisDrawing, that gives you about the same interface as
within AutoCAD VBA
dim ThisDrawing as AcadDocument

>
> Basically the project at present is a single .DVB file. I have about
> ten AutoCAD commands which run macros in the DVB and these are set up
> in AcadDoc.lsp. I presumed at first that I should set up the project
> as a DLL, but I can't see how I would call the macros from AutoCAD. I
> successfully created a DLL, registered it, set up the references to
> the DLL in a dummy DVB file for testing but it won't seem to see the
> Public Functions in the DLL.
Create an ActiveX Dll
Make sure you set the Instancing property to GlobalMultiUse and declare your
functions in a Class module as Public.
when referencing the dll in VBA you should see your functions (Press F2 for
the Object Browser, this will show you the different Object Models

>
> I thought maybe I should split the project up into a series of
> projects (one for each AutoCAD command) and create them as an .EXE
> file. I can get this to work but my global variables no longer have
> scope in all the modules and I still have the problem referring to
> subs and functions that are common to all the commands.
>
> Finally I have an ObjectModified event in the "ThisDrawing" section of
> the DVB. I can't seem to see where this would go in a VB file. I can
> see how to use GetObject to get the ActiveDocument, but can't seem to
> figure how to set up an ObjectModified event.
>
> I would appreciate a nudge in the right direction.
>
> Ian Thomson
0 Likes
Message 3 of 6

Anonymous
Not applicable
> declare a var called ThisDrawing, that gives you
> about the same interface as within AutoCAD VBA

With one *big* gotcha: when the user switches documents, your variable
will not reflect this. One way around it is to use the
DocumentActivated event of the DocumentMonitor class in vbXtender.arx
(Downloads section of my site).

> Make sure you set the Instancing property to GlobalMultiUse

Good intentions, bad idea. GlobalMultiUse gives you no control over an
object's lifespan. This is especially problematic when an object
manipulates resources such as file handles. MultiUse is good enough as
it provides the ability to create objects but turns the responsibility
of managing an object's lifespan over to the programmer (where it
belongs).

--
http://www.acadx.com
0 Likes
Message 4 of 6

Anonymous
Not applicable
Thanks guys,

Some ideas there for me to think about. I'm rapidly back-pedalling on
what I thought was a relatively simple project.

First I learn lisp and as soon as I'm comfortable with AutoLisp I have
to start learning Visual Lisp, then along comes Visual Basic...(which
disappears again) only to return again as half-baked VBA in R14, then
VBA and VB in 2000. The powers that be tell me I should be working
with ObjectARX and C++, but I'm still struggling with VBA. Now people
are rumbling about C# and XML. Life was so easy with AutoLisp. 🙂

(but I'm glad to see the back of DCL..)

Ian Thomson

PS thanks Frank I shall go and take a look at VbXtender.arx

On Tue, 12 Jun 2001 09:36:18 -0700, "Frank Oquendo"
wrote:

>> declare a var called ThisDrawing, that gives you
>> about the same interface as within AutoCAD VBA
>
>With one *big* gotcha: when the user switches documents, your variable
>will not reflect this. One way around it is to use the
>DocumentActivated event of the DocumentMonitor class in vbXtender.arx
>(Downloads section of my site).
>
>> Make sure you set the Instancing property to GlobalMultiUse
>
>Good intentions, bad idea. GlobalMultiUse gives you no control over an
>object's lifespan. This is especially problematic when an object
>manipulates resources such as file handles. MultiUse is good enough as
>it provides the ability to create objects but turns the responsibility
>of managing an object's lifespan over to the programmer (where it
>belongs).
0 Likes
Message 5 of 6

Anonymous
Not applicable
"Frank Oquendo" wrote in message
news:5FD243C77EF59A89454C5C64AAEF4D57@in.WebX.maYIadrTaRb...
> > declare a var called ThisDrawing, that gives you
> > about the same interface as within AutoCAD VBA
>
> With one *big* gotcha: when the user switches documents, your variable
> will not reflect this. One way around it is to use the
> DocumentActivated event of the DocumentMonitor class in vbXtender.arx

my way arround this is to check the active document:
Dim ThisDrawing As AcadDocument
Dim objAcad As AcadApplication
' check which document is active.
Set ThisDrawing = objAcad.ActiveDocument

> (Downloads section of my site).
>
> > Make sure you set the Instancing property to GlobalMultiUse
>
> Good intentions, bad idea. GlobalMultiUse gives you no control over an
> object's lifespan. This is especially problematic when an object
> manipulates resources such as file handles. MultiUse is good enough as
> it provides the ability to create objects but turns the responsibility
> of managing an object's lifespan over to the programmer (where it
> belongs).
>
> --
> http://www.acadx.com
>
>
0 Likes
Message 6 of 6

Anonymous
Not applicable
> my way arround this is to check the active document:

Unfortunately, that approach is fraught with issues. There will be
plenty of times when attempting to query the ActiveDocument property
will genearate runtime errors.

--
http://www.acadx.com
0 Likes