VB'er making the leap!

VB'er making the leap!

RonnieWilkins
Advocate Advocate
457 Views
9 Replies
Message 1 of 10

VB'er making the leap!

RonnieWilkins
Advocate
Advocate
First off let me thank you a head of time, THANKS!

Okay as the header says I'm a VB programmer making the leap to C++/ARX programming. In other words NEWBIE.

Basically all I really want to do is create an ARX file that registers commands in AutoCAD that run VBA macros. I currently have a working version using acedCommand function.


//-----------------------------------------------------------------------------
// This is command 'CHECKDIMS, by [3/27/2003], ,
void AMSIMiscellaneousUtilitiesCheckDims()
{
#ifdef OARXWIZDEBUG
acutPrintf ("\nOARXWIZDEBUG - AMSIMiscellaneousUtilitiesCheckDims() called.");
#endif // OARXWIZDEBUG

// TODO: Implement the command
char modulePath[512];
char statement[] = "The full path of the executing program is: ";
::GetModuleFileName(_hdllInstance, modulePath, 512);
acutPrintf (strcat(statement,modulePath));
acedCommand (RTSTR, "_-vbarun", RTSTR, "D:\\AMS\\Development\\Clients\\PS&S\\Utilities\\AmsUtilities.dvb!Module1.CheckForOverRiddenDimensions", 0);
}


I want to take the variable modulePath and get just the folder name that the ARX module is currently located in so that I can concatenate the folder path with the .DVB file. I've tried using #include , #include and any other variations without success, VC keeps stating that string is undefined.

I know that I could use a LISP file, but I am trying to package a program for distro. that can be added to registry and will work in all profiles...ARX!

Thanks Again for any info!
Ronnie Wilkins, Jr.
0 Likes
458 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable
Here's one way

 

// To load the VBA project

ads_command(RTSTR, "-vbaload", RTSTR, "your project
path", RTNONE);

// To run the macro
ads_command(RTSTR,
"-vbarun", RTSTR, "your macro name", RTNONE);


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
First
off let me thank you a head of time, THANKS!

Okay as the header says I'm a VB programmer making the leap to C++/ARX
programming. In other words NEWBIE.

Basically all I really want to do is create an ARX file that registers
commands in AutoCAD that run VBA macros. I currently have a working version
using acedCommand function.

 
//-----------------------------------------------------------------------------
// This is command 'CHECKDIMS, by [3/27/2003], ,
void AMSIMiscellaneousUtilitiesCheckDims()
{
#ifdef OARXWIZDEBUG
acutPrintf ("\nOARXWIZDEBUG - AMSIMiscellaneousUtilitiesCheckDims() called.");
#endif // OARXWIZDEBUG

// TODO: Implement the command
char modulePath[512];
char statement[] = "The full path of the executing program is: ";
::GetModuleFileName(_hdllInstance, modulePath, 512);
acutPrintf (strcat(statement,modulePath));
acedCommand (RTSTR, "_-vbarun", RTSTR, "D:\\AMS\\Development\\Clients\\PS&S\\Utilities\\AmsUtilities.dvb!Module1.CheckForOverRiddenDimensions", 0);
}


I want to take the variable modulePath and get just the folder name that
the ARX module is currently located in so that I can concatenate the folder
path with the .DVB file. I've tried using #include <string>, #include
<cstring> and any other variations without success, VC keeps stating
that string is undefined.

I know that I could use a LISP file, but I am trying to package a program
for distro. that can be added to registry and will work in all profiles...ARX!

Thanks Again for any info!

0 Likes
Message 3 of 10

RonnieWilkins
Advocate
Advocate

Gary,

Thanks for the info, but what I am trying to do is take the value from 'modulePath' variable that will contains the path including file name of the current ARX file. What I can't seem to grasp is how to get a substring from this variable that will be only the folder 'C:\Test\', not 'C:\Test\file.ARX'. What I really need is a function that will reverse find in the modulPath variable '\'. In VB I could do this instinctively, but C++ is driving me crazy.

In a console application I can say #include and have the functionality I need through the string object. But for some reason if I try to use a string object VC keeps saying "'string' : undeclared identifier"

Here is an updated code snippet with a closer idea of what I'm trying to do:

//Begin code
//
// ObjectARX defined commands, created by [3/27/2003], ,
#include "StdAfx.h"
#include "StdArx.h"
#include

char GetFolder(char *path);

//-----------------------------------------------------------------------------
// This is command 'CHECKDIMS, by [3/27/2003], ,
void AMSIMiscellaneousUtilitiesCheckDims()
{
#ifdef OARXWIZDEBUG
acutPrintf ("\nOARXWIZDEBUG - AMSIMiscellaneousUtilitiesCheckDims() called.");
#endif // OARXWIZDEBUG

// TODO: Implement the command
char modulePath[512];
char statement[] = "The full path of the executing program is: ";
::GetModuleFileName(_hdllInstance, modulePath, 512);
acutPrintf (strcat(statement,modulePath));

/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The following line works great as is, but is hard coded. I need this to be flexible thus a strcat with a variable
acedCommand (RTSTR, "_-vbarun", RTSTR, "D:\\AMS\\Development\\Clients\\PS&S\\Utilities\\AmsUtilities.dvb!Module1.CheckForOverRiddenDimensions", 0);
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

//string t; //If I try to compile this line states that 'string' is undeclared.


//The following two lines are what I am wanting to work...just doesn't, yet!
char FolderLocation = GetFolder(modulePath);
acedCommand (RTSTR, "_-vbarun", RTSTR, strcat(FolderLocation , "AmsUtilities.dvb!Module1.CheckForOverRiddenDimensions"), 0);
}

char GetFolder(char *path)
{
char *pdest;
int result;
int ch = '\\';
pdest = strrchr(path,ch);

result = pdest - path + 1; //Now that I have the location of the last "\", I'm dumb founded.

char temp;
new temp[result];
//char newpath = path[0,pdest];
//return newpath;
return temp;
}
//End Code


Ronnie Wilkins, Jr.
0 Likes
Message 4 of 10

Anonymous
Not applicable
I'm not sure I follow, but it sounds like you want to use a variable of type
"string" in your program. If this is the case, then #include is
correct. However you need to declare your variable like this:

std::string strVar;

This is because the "string" type resides in the "std" namespace.
Alternatively, you could put the following after your #includes:

using namespace std;

Then you don't to prefix types from the "std" namespace with std::

Am I even close to understanding what you are after?

Chuck


"rwilkins" wrote in message
news:f153d73.-1@WebX.maYIadrTaRb...
> First off let me thank you a head of time, THANKS!
> Okay as the header says I'm a VB programmer making the leap to C++/ARX
programming. In other words NEWBIE.
>
> Basically all I really want to do is create an ARX file that registers
commands in AutoCAD that run VBA macros. I currently have a working version
using acedCommand function.
>
>
>
>
//-----------------------------------------------------------------------------
> // This is command 'CHECKDIMS, by [3/27/2003], ,
> void AMSIMiscellaneousUtilitiesCheckDims()
> {
> #ifdef OARXWIZDEBUG
> acutPrintf ("\nOARXWIZDEBUG - AMSIMiscellaneousUtilitiesCheckDims() called.");
> #endif // OARXWIZDEBUG // TODO: Implement the command
> char modulePath[512];
> char statement[] = "The full path of the executing program is: ";
> ::GetModuleFileName(_hdllInstance, modulePath, 512);
> acutPrintf (strcat(statement,modulePath));
> acedCommand (RTSTR, "_-vbarun", RTSTR,
"D:\\AMS\\Development\\Clients\\PS&S\\Utilities\\AmsUtilities.dvb!Module1.CheckF
orOverRiddenDimensions", 0);
> }
> I want to take the variable modulePath and get just the folder name that the
ARX module is currently located in so that I can concatenate the folder path
with the .DVB file. I've tried using #include , #include and
any other variations without success, VC keeps stating that string is undefined.
>
> I know that I could use a LISP file, but I am trying to package a program for
distro. that can be added to registry and will work in all profiles...ARX!
>
> Thanks Again for any info!
>
0 Likes
Message 5 of 10

RonnieWilkins
Advocate
Advocate
Chuck,

You have the idea, but for some reason when I try and compile even with the statement "std::string" VC says that string is not in namespace std.

I'm currently just using c-style strings (char variables) due to the VC spitting back at me with the string variable non-sense.

If I try and do this in a console application I have no problems but something inside this arx workspace is throwing things offs...atleast I guess.

Thanks,

Ron
Ronnie Wilkins, Jr.
0 Likes
Message 6 of 10

Anonymous
Not applicable

I use MFC, so I would use CString, also this is a
better way of getting the path of your ARX

 

// This gives you the full path of you ARX

char* pPath = acedGetAppName();

 

F.Y.I. You can E-mail me directly if you
like


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
 
Gary,

Thanks for the info, but what I am trying to do is take the value from 'modulePath' variable that will contains the path including file name of the current ARX file. What I can't seem to grasp is how to get a substring from this variable that will be only the folder 'C:\Test\', not 'C:\Test\file.ARX'. What I really need is a function that will reverse find in the modulPath variable '\'. In VB I could do this instinctively, but C++ is driving me crazy.

In a console application I can say #include <string> and have the functionality I need through the string object. But for some reason if I try to use a string object VC keeps saying "'string' : undeclared identifier"

Here is an updated code snippet with a closer idea of what I'm trying to do:

//Begin code
//
// ObjectARX defined commands, created by [3/27/2003], ,
#include "StdAfx.h"
#include "StdArx.h"
#include <string>

char GetFolder(char *path);

//-----------------------------------------------------------------------------
// This is command 'CHECKDIMS, by [3/27/2003], ,
void AMSIMiscellaneousUtilitiesCheckDims()
{
#ifdef OARXWIZDEBUG
acutPrintf ("\nOARXWIZDEBUG - AMSIMiscellaneousUtilitiesCheckDims() called.");
#endif // OARXWIZDEBUG

// TODO: Implement the command
char modulePath[512];
char statement[] = "The full path of the executing program is: ";
::GetModuleFileName(_hdllInstance, modulePath, 512);
acutPrintf (strcat(statement,modulePath));

/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The following line works great as is, but is hard coded. I need this to be flexible thus a strcat with a variable
acedCommand (RTSTR, "_-vbarun", RTSTR, "D:\\AMS\\Development\\Clients\\PS&S\\Utilities\\AmsUtilities.dvb!Module1.CheckForOverRiddenDimensions", 0);
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

//string t; //If I try to compile this line states that 'string' is undeclared.

//The following two lines are what I am wanting to work...just doesn't, yet!
char FolderLocation = GetFolder(modulePath);
acedCommand (RTSTR, "_-vbarun", RTSTR, strcat(FolderLocation , "AmsUtilities.dvb!Module1.CheckForOverRiddenDimensions"), 0);
}

char GetFolder(char *path)
{
char *pdest;
int result;
int ch = '\\';
pdest = strrchr(path,ch);

result = pdest - path + 1; //Now that I have the location of the last "\", I'm dumb founded.

char temp;
new temp[result];
//char newpath = path[0,pdest];
//return newpath;
return temp;
}
//End Code

0 Likes
Message 7 of 10

RonnieWilkins
Advocate
Advocate

Ok guys, got a working version that does what I need. If
you would please take a look and see if I have anything
that could cause issues. Again I'm new to the C++ side and
am very greatful for all your help.

//
// ObjectARX defined commands, created by [3/27/2003], ,
#include "StdAfx.h"
#include "StdArx.h"

void GetFolder(char *path);

//-----------------------------------------------------------------------------
// This is command 'CHECKDIMS, by [3/27/2003], ,
void AMSIMiscellaneousUtilitiesCheckDims()
{
#ifdef OARXWIZDEBUG
acutPrintf ("\nOARXWIZDEBUG - AMSIMiscellaneousUtilitiesCheckDims() called.");
#endif // OARXWIZDEBUG

// TODO: Implement the command
char modulePath[512];
char vbastatement[1000];
GetModuleFileName(_hdllInstance, modulePath, 512);

GetFolder(modulePath);
vbastatement[0]='\"';

strcat(modulePath , "AmsUtilities.dvb!Module1.CheckForOverRiddenDimensions");

int MAX = strlen(modulePath);

for (int i = 0; i <= MAX; i++)
{
vbastatement[i+1] = modulePath;
}

MAX = strlen(vbastatement)-1;

vbastatement[MAX+1] = '\"';
vbastatement[MAX+2]=0;

//acutPrintf (vbastatement);
acedCommand (RTSTR, "_-vbarun", RTSTR, vbastatement, 0);


}

void GetFolder(char *path)
{
char *pdest;
int result;
int ch = '\\';
pdest = strrchr(path,ch);

result = pdest - path + 1;

path[result]=0;
}

Ronnie Wilkins, Jr.
0 Likes
Message 8 of 10

Anonymous
Not applicable
"rwilkins" wrote in message news:f153d73.5@WebX.maYIadrTaRb...
>
> Ok guys, got a working version that does what I need. If
> you would please take a look and see if I have anything
> that could cause issues. Again I'm new to the C++ side and
> am very greatful for all your help. //

Sure thing. My guess is that you're in for a few surprises.

First, the VBARUN command executes VBA macros in the
application context.

If you try to display a dialog, I think you'll find that
there will be problems. You could register the ARX command
to run in the Application context as well, but that would
prevent you from using acedCommand().

In short, how you're doing this is amounts to a kludge
that will probably create more problems than it solves,
and that may only become apparent once you try doing
other things in VBA code that's run from this thing.

The correct way to do this is to implement a COM server in
ARX, which can fire an event at a connected VBA client, when
the commands it registers are issued. If you do that, the
command executes in the document context, and the VBA event
handler also does. So, you can use acedCommand() and so
can the VBA macro (provided you expose a method allowing
acedCommand() to be called from VBA).

You can see that exact menthod in the AcadXEditorCommand
class in AcadX.arx (http://www.caddzone.com/acadx).

> // ObjectARX defined commands, created by [3/27/2003], ,
> #include "StdAfx.h"
> #include "StdArx.h" void GetFolder(char *path);
//-----------------------------------------------------------------------------
> // This is command 'CHECKDIMS, by [3/27/2003], ,
> void AMSIMiscellaneousUtilitiesCheckDims()
> {
> #ifdef OARXWIZDEBUG
> acutPrintf ("\nOARXWIZDEBUG - AMSIMiscellaneousUtilitiesCheckDims() called.");
> #endif // OARXWIZDEBUG // TODO: Implement the command
> char modulePath[512];
> char vbastatement[1000];
> GetModuleFileName(_hdllInstance, modulePath, 512); GetFolder(modulePath);
> vbastatement[0]='\"'; strcat(modulePath , "AmsUtilities.dvb!Module1.CheckForOverRiddenDimensions"); int MAX =
strlen(modulePath); for (int i = 0; i <= MAX; i++)
> {
> vbastatement[i+1] = modulePath;
> } MAX = strlen(vbastatement)-1; vbastatement[MAX+1] = '\"';
> vbastatement[MAX+2]=0; //acutPrintf (vbastatement);
> acedCommand (RTSTR, "_-vbarun", RTSTR, vbastatement, 0); } void GetFolder(char *path)
> {
> char *pdest;
> int result;
> int ch = '\\';
> pdest = strrchr(path,ch); result = pdest - path + 1; path[result]=0;
> }
0 Likes
Message 9 of 10

Anonymous
Not applicable
This is what I do in Acad Map5 with VC++. I create an ActiveX toolbar and register a command for each button. In the void that the command calls I have almost exactly what "rwilkins" does. It works great. I have all kinds of DVB and Lisp files in a single folder out on our network the .arx is there also. The users include my .arx in their startup suite and I only have to manage that one .arx and all my tools get managed with no distribution issues. My unload events take the commands a toolbar away so I don't leave garbage behind if they unload it. Basically the .arx ends up acting as a server to manage the .dvb's and Lisp routines. I'm not sure if that is what Tony is talking about or not, but I haven't run into any issues this way and I use a lot of dialogs on the VB side.
0 Likes
Message 10 of 10

Anonymous
Not applicable


Oops I take that back I just realized you are doing a VBARUN
I do a VBA load and then the buttons have the -_vbarun statement in them as there command. This is probably why I haven't run into problems doing it this way.

0 Likes