Jump to content

Recommended Posts

Posted (edited)

Hello everyone,

 

Please note that I'm trying to run a macro *automatically* each time

Mechanical Desktop is launched. I'm using the following procedure:

 

1. Creating a new macro (Assist | Macro | VisualBasic Editor)

2. I'm typing in the following code in the main Integrated Development

Environment. (I only want to load a script file MechD.scr with startup)

 

Sub AcadStartup()

ThisDrawing.SendCommand "FILEDIA" & vbCr & "0" & vbCr

ThisDrawing.SendCommand "script" & vbCr
ThisDrawing.SendCommand "C:\Documents and 
Settings\user\mXSKetch\ALGORITHMS\MechD.scr" & vbCr

End Sub

 

3. Saving the VBA project acad.dvb in "C:\Program Files\Autodesk\MDT 2004

DX\"

4. Saving the Macro name as ThisDaring.AcadStartup

5. Typing in 'acadvba.arx' in the file acad.rx

6. Creating the lsp files acad.lsp and acaddoc.lsp with the following code:

 

(defun S::STARTUP() (command "_-vbarun" "ThisDrawing.AcadStartup"))

 

For some reason the macro is not launched with startup. Kindly can you tell

me what I'm doing wrong? Is there an easier way than the above?

 

Thanks in advance for your help!!

 

Best Regards,

 

SYLVAN

Edited by SLW210
Add Code Tags!!!
Posted

if all you want to do is run a script at startup then why go to all that bother. Just use the command line switch

 

/b 
The syntax for using command line switches is 

"drive:pathname\acad.exe" ["drawing name"] [/switch "name"] 

When using a switch option, you must follow the switch with a space and then the name of a file, path, or view within quotation marks. For example the following entry starts AutoCAD from a folder named AutoCAD 2002 with the template drawing arch1.dwt, restores a named view PLAN1, and executes a script file startup.scr. 

"d:\AutoCAD 2002\acad.exe"/t "d:\AutoCAD 2002\template\arch1" /v "plan1" /b "startup" 

 

If you *must* do it using vba then I would avoid the use of "sendcommand"

AutoCAD will automatically load at startup any project file with the name acad.dvb.

Posted
if all you want to do is run a script at startup then why go to all that bother. Just use the command line switch

 

That's how I do it:

 

"C:\Program Files\Autodesk Architectural Desktop 2005\acad.exe" /nologo /c "\\d22\Dominic\AutoCAD_Custom\config" /p "ACAD2005-ASE-DominicCesare-BMP-Rockford" /b "C:\Program Files\ASE\Building_Maintanence_Program\Rockford\Scripts\Startup-Rockford.scr"

Posted

Hi there,

 

First of all thank you for your post. Please do bear with me. I'm relatively new to ACAD customisation. In which folder shall the code that you provided be saved (e.g. C:\Program Files\Acad 2004\)? In which format?

 

Thanks in advance for your reply

 

if all you want to do is run a script at startup then why go to all that bother. Just use the command line switch

 

That's how I do it:

 

"C:\Program Files\Autodesk Architectural Desktop 2005\acad.exe" /nologo /c "\\d22\Dominic\AutoCAD_Custom\config" /p "ACAD2005-ASE-DominicCesare-BMP-Rockford" /b "C:\Program Files\ASE\Building_Maintanence_Program\Rockford\Scripts\Startup-Rockford.scr"

Posted

AutoCAD shortcut target line. Command line switches.

 

Switch Name

/b Script name

/t Template file

/v View name

/s Support directories

/c Configuration

/d Driver directory

/m Memory management

/p Profile (registry profile)

/r Reconfigure on startup

/nologo Startup without displaying the logo

 

(path to acad.exe)
"C:\Program Files\Autodesk Architectural Desktop 2005\acad.exe"

(switch for no spalsh screen)
/nologo

(switch to set the config folder and the path to the one I want to use)
/c "\\d22\Dominic\AutoCAD_Custom\config"

(switch for which profile to use and the path to the one I want to use)
/p "ACAD2005-ASE-DominicCesare-BMP-Rockford"

(switch for which script to run at startup and path to the one I wan to use)
/b "C:\Program Files\ASE\Building_Maintanence_Program\Rockford\Scripts\Startup-Rockford.scr"

 

Then just put 'em all together and put that in the Target line of your AutoCAD shortcut (right click on the shortcut->properties). I URGE you to make a copy of the shortcut to modify and name it accordingly.

Posted

Hi there,

 

Many thanks for your explanation and help. The code worked out fine. I'm indeed finding this forum very helpful!

 

Regards,

 

Sylvan

  • 5 years later...
Posted

This post seems most relevant to what I am trying to achieve - I’m having some difficulty with finding out how to run some commands every time I open a drawing. For example, I want to open up a drawing and without having to do anything I want ACAD to immediately set ortho on, plinewid to 0, layer to 0, etc etc. I see this is possible when opening ACAD via shortcut icons (command line switches?) as mentioned above, but found by doing this it will only ever work if you open ACAD via that shortcut only? I want ACAD to run the commands automatically regardless of how I have opened the drawing. Does anyone know a way aound this? Thanks!

Posted

When you open a drawing, AutoCAD will automatically search the working directory and support paths for a file called the ACADDOC.lsp and load the first one it finds.

 

Hence you can include expressions in your ACADDOC.lsp to set the various system variables, e.g.:

 

(setvar 'ORTHOMODE 1)
(setvar 'PLINEWID 0.0)

As for setting the current layer to "0", you may want to check that it isn't frozen first, and if so, thaw it. Similarly, unlocking it and turning it On:

 

(command "_.-layer" "_T" "0" "_U" "0" "_ON" "0" "_S" "0" "")

Alternatively, using the DXF Group codes to avoid the command-line output, include the following in your ACADDOC.lsp:

 

(
   (lambda ( / b c e )
       (setq e (entget (tblobjname "LAYER" "0"))
             b (assoc 70 e)
             c (assoc 62 e)
             e (subst (cons 62 (abs (cdr c))) c e)
             e (subst (cons 70 (boole 4 5 (cdr b))) b e)
       )
       (entmod e)
       (setvar 'CLAYER "0")
       (princ)
   )
)

 

On a side note, since AutoCAD will always search the working directory first, you can include project-specific ACADDOC.lsp files in the directory with the project to automatically set the environment for that project.

Posted

Ohh, I see! I had been so fixated on using the acaddoc.lsp file purely for creating new command strings to call forth routines, I had completely forgotten that it can load and manipulate settings in this way. Of course, it makes perfect sense now 8) Thanks so much for your help!

Posted

Think of the ACADDOC.lsp as just another LISP file - when loaded, the expressions contained therein will be evaluated. Usually, such expressions are 'defun' statements to define LISP commands that may be called at the command-line, but of course any LISP expressions included in the file will be evaluated (which is what makes the 'auto-loading' behaviour of the ACADDOC LISP so inviting for malicious code).

  • 6 months later...
Posted (edited)

Hey guys, I’m back with another query on this!

 

I’ve initiated the following in my acaddoc file:

 

(command "FILEDIA" "0""._-PSETUPIN" "C:/JB DESKTOP/Office/IMPORTED PLOT STYLES 
&LAYERS.dwg" "*" "FILEDIA" "1"))

 

A simple lisp that brings in page setups on openingany drawing. However, I like this routine so much I have made a command for italso:

 

(DEFUN C:IPS () (command "FILEDIA""0" "._-PSETUPIN" "C:/JB 
DESKTOP/Office/IMPORTED PLOTSTYLES & LAYERS.dwg" "*" "FILEDIA" "1"))

 

 

Having one above the other in my acaddoc file cancelsthe lower one out, so I either get the auto load version or the command version…Why is this?! Yes I know I wouldn’t normally need both but this is a goodexample as I’ve witnessed things like this before and made sketchy workarounds.Can anyone offer some advice? Cheers!

Edited by DWG Destroyer

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...