VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Running a script (scr) file in a VBA program

6 REPLIES 6
Reply
Message 1 of 7
timbar
4083 Views, 6 Replies

Running a script (scr) file in a VBA program

I'd like to include a script command in an AutoCAD VBA program. The program opens a new drawing file, runs a script file, and then saves the drawing. The script file, in this case, is a 3dmesh script file (3dmesh command with M & N values and xyz coordinate triplets in a scr text file).

I'd like to "run" the script file as a step in the VBA program, but I don't know the right syntax. I've tried a number of different command syntax formats.

If the script file name is "3dmesh.scr" what is the right VBA code/command to include in the VBA program to run the script file?

Thanks in advance for the feedback.

Tim Barbour
timbar@att.net
6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: timbar

Hi Tim,

There will be a way of using Sendcommand to run the script, but as by
default VBA will continue to run while the script program runs, you will
need to take steps to ensure that no VBA code runs while the script is
running (ie in the simplest case, calling the script is the last thing a
calling function does).

--


Laurie Comerford
CADApps
www.cadapps.com.au


"timbar" wrote in message
news:f1967a6.-1@WebX.maYIadrTaRb...
> I'd like to include a script command in an AutoCAD VBA program. The
program opens a new drawing file, runs a script file, and then saves the
drawing. The script file, in this case, is a 3dmesh script file (3dmesh
command with M & N values and xyz coordinate triplets in a scr text file).
> I'd like to "run" the script file as a step in the VBA program, but I
don't know the right syntax. I've tried a number of different command syntax
formats.
>
> If the script file name is "3dmesh.scr" what is the right VBA code/command
to include in the VBA program to run the script file?
>
> Thanks in advance for the feedback.
>
> Tim Barbour
> timbar@att.net
>
Message 3 of 7
timbar
in reply to: timbar

Hi Laurie,

Your advise is right on. I'm just learning AutoCAD VBA. It's similar to other VB scripting languages I've used. I don't know all the syntax, but learn what I need, as I go.

Now that I understand how the SendCommand can be used to execute a _script command (or other command-line commands), I think I can implement it, and place the script run within the broader VBA run (as you advised), so it'll work the way I want.

As mentioned previously, my task is to write a VBA program to open a new drawing, run a script (now with the VBA SendCommand "script" command), and then save and close the drawing. The script I'm trying to run is a "3dmesh command" script.

Since I'm not totally up to speed with VBA, I'm still running into some syntax problems. What I need to know (hopefully you can help), is:

How can I replace the "Select Script File" dialog I get when I type in "script" on the AutoCad command line with an appropriate VBA command line. The VBA command line I'm using is:

ThisDrawing.SendCommand "_script" & vbCr & filenameSCR & vbCr

where the variable filenameSCR is

filenameSCR = path15 + foldername + "\" + fileName + ".scr"

and where the path, foldername and filename variables are pointers to the script file location on my computer hard drive.

My folder and file names have "spaces" in the name string, so the script command (when executed from the command line) rejects the names because of the spaces. The script command reads the folder and file names incorrectly in pieces.

The "Select Script File" dialog doesn't have this problem. Using this dialog, and highlighting the desired (scr) file, and opening the selected file works OK (even with the spaces included in the name). It's this type of functionality that I'd like to replicate with VBA.

I've come across some AutoCAD Help info on VBA file selection for opening files (in my particular case, using the Select Script File dialog), but I've lost the "help" for the moment.

This may be a new forum question, but since you were right on the first time, I thought I'd ask you about -

how to select files to open (in this case a script file) in VBA using the "select file dialog" approach.

I hope I've presented my question clearly. Thanks for your previous help, and any additional advise you may have.

Tim Barbour
Message 4 of 7
Anonymous
in reply to: timbar

Hi Tim,

I don't know any specific answers, but things to experiment with include:

-script instead of _script

ThisDrawing.SetVariable "FileDia", 0

When assembling the string for the path you need to include the inverted
commas as part of the string

Use & to join strings, not +

Use \\ rather than \ as dividers for the directories.


--


Laurie Comerford
CADApps
www.cadapps.com.au

"timbar" wrote in message
news:f1967a6.1@WebX.maYIadrTaRb...
> Hi Laurie,
> Your advise is right on. I'm just learning AutoCAD VBA. It's similar to
other VB scripting languages I've used. I don't know all the syntax, but
learn what I need, as I go.
>
> Now that I understand how the SendCommand can be used to execute a _script
command (or other command-line commands), I think I can implement it, and
place the script run within the broader VBA run (as you advised), so it'll
work the way I want.
>
> As mentioned previously, my task is to write a VBA program to open a new
drawing, run a script (now with the VBA SendCommand "script" command), and
then save and close the drawing. The script I'm trying to run is a "3dmesh
command" script.
>
> Since I'm not totally up to speed with VBA, I'm still running into some
syntax problems. What I need to know (hopefully you can help), is:
>
> How can I replace the "Select Script File" dialog I get when I type in
"script" on the AutoCad command line with an appropriate VBA command line.
The VBA command line I'm using is:
>
> ThisDrawing.SendCommand "_script" & vbCr & filenameSCR & vbCr
>
> where the variable filenameSCR is
>
> filenameSCR = path15 + foldername + "\" + fileName + ".scr"
>
> and where the path, foldername and filename variables are pointers to the
script file location on my computer hard drive.
>
> My folder and file names have "spaces" in the name string, so the script
command (when executed from the command line) rejects the names because of
the spaces. The script command reads the folder and file names incorrectly
in pieces.
>
> The "Select Script File" dialog doesn't have this problem. Using this
dialog, and highlighting the desired (scr) file, and opening the selected
file works OK (even with the spaces included in the name). It's this type of
functionality that I'd like to replicate with VBA.
>
> I've come across some AutoCAD Help info on VBA file selection for opening
files (in my particular case, using the Select Script File dialog), but I've
lost the "help" for the moment.
>
> This may be a new forum question, but since you were right on the first
time, I thought I'd ask you about -
>
> how to select files to open (in this case a script file) in VBA using the
"select file dialog" approach.
>
> I hope I've presented my question clearly. Thanks for your previous help,
and any additional advise you may have.
>
> Tim Barbour
>
Message 5 of 7
Anonymous
in reply to: timbar

Use double quote before and after
folder+filename


--
Saludos,  Ing. Jorge Jimenez, SICAD S.A., Costa Rica


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

Your advise is right on. I'm just learning AutoCAD VBA. It's similar to
other VB scripting languages I've used. I don't know all the syntax, but learn
what I need, as I go.

Now that I understand how the SendCommand can be used to execute a _script
command (or other command-line commands), I think I can implement it, and
place the script run within the broader VBA run (as you advised), so it'll
work the way I want.

As mentioned previously, my task is to write a VBA program to open a new
drawing, run a script (now with the VBA SendCommand "script" command), and
then save and close the drawing. The script I'm trying to run is a "3dmesh
command" script.

Since I'm not totally up to speed with VBA, I'm still running into some
syntax problems. What I need to know (hopefully you can help), is:

How can I replace the "Select Script File" dialog I get when I type in
"script" on the AutoCad command line with an appropriate VBA command line. The
VBA command line I'm using is:

ThisDrawing.SendCommand "_script" & vbCr & filenameSCR & vbCr

where the variable filenameSCR is

filenameSCR = path15 + foldername + "\" + fileName + ".scr"

and where the path, foldername and filename variables are pointers to the
script file location on my computer hard drive.

My folder and file names have "spaces" in the name string, so the script
command (when executed from the command line) rejects the names because of the
spaces. The script command reads the folder and file names incorrectly in
pieces.

The "Select Script File" dialog doesn't have this problem. Using this
dialog, and highlighting the desired (scr) file, and opening the selected file
works OK (even with the spaces included in the name). It's this type of
functionality that I'd like to replicate with VBA.

I've come across some AutoCAD Help info on VBA file selection for opening
files (in my particular case, using the Select Script File dialog), but I've
lost the "help" for the moment.

This may be a new forum question, but since you were right on the first
time, I thought I'd ask you about -

how to select files to open (in this case a script file) in VBA using the
"select file dialog" approach.

I hope I've presented my question clearly. Thanks for your previous help,
and any additional advise you may have.

Tim Barbour

Message 6 of 7
Anonymous
in reply to: timbar

Thisdrawing.SendCommand 'script filenameSCR &
vbCrLf

 

filenameSCR  = chr(34) & path15 &
foldername & chr(92) & fileName & ".scr" & chr(34)

 

Tim Riley


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

Your advise is right on. I'm just learning AutoCAD VBA. It's similar to
other VB scripting languages I've used. I don't know all the syntax, but learn
what I need, as I go.

Now that I understand how the SendCommand can be used to execute a _script
command (or other command-line commands), I think I can implement it, and
place the script run within the broader VBA run (as you advised), so it'll
work the way I want.

As mentioned previously, my task is to write a VBA program to open a new
drawing, run a script (now with the VBA SendCommand "script" command), and
then save and close the drawing. The script I'm trying to run is a "3dmesh
command" script.

Since I'm not totally up to speed with VBA, I'm still running into some
syntax problems. What I need to know (hopefully you can help), is:

How can I replace the "Select Script File" dialog I get when I type in
"script" on the AutoCad command line with an appropriate VBA command line. The
VBA command line I'm using is:

ThisDrawing.SendCommand "_script" & vbCr & filenameSCR & vbCr

where the variable filenameSCR is

filenameSCR = path15 + foldername + "\" + fileName + ".scr"

and where the path, foldername and filename variables are pointers to the
script file location on my computer hard drive.

My folder and file names have "spaces" in the name string, so the script
command (when executed from the command line) rejects the names because of the
spaces. The script command reads the folder and file names incorrectly in
pieces.

The "Select Script File" dialog doesn't have this problem. Using this
dialog, and highlighting the desired (scr) file, and opening the selected file
works OK (even with the spaces included in the name). It's this type of
functionality that I'd like to replicate with VBA.

I've come across some AutoCAD Help info on VBA file selection for opening
files (in my particular case, using the Select Script File dialog), but I've
lost the "help" for the moment.

This may be a new forum question, but since you were right on the first
time, I thought I'd ask you about -

how to select files to open (in this case a script file) in VBA using the
"select file dialog" approach.

I hope I've presented my question clearly. Thanks for your previous help,
and any additional advise you may have.

Tim Barbour

Message 7 of 7
inventordeepan
in reply to: Anonymous

Hi laurie

 

 

i dono vba .

i want to open autocad from the excell  using vba  and run the scr file i like in autocad how can i accomplish it i need exact code to do so,

 

 

my scr file is test.scr and file location :d\   so can anyone plse tell exact code to load this scr file and i need run some other vba code at the end of this code how can i control that tooo some one explain plse .

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost