View Full Version : Creating a batch file for profiles
Toffy
26th Jan 2005, 06:41 pm
Hello. Im new to this forum.
Hope you will be able to help me out.
I am in the process of creating a .bat file which will (amongst other things) Import a number of default profiles (which are saved on
a server)
Id like to be able to run this on any PC with full autocad on to quickly load on my default drop down menus and paths (which have been previously edited and saved in my .arg files)
If anyone can think of a way to do this i would be extremely grateful and im getting a bit of a headache
so far i have this:
md "%USERPROFILE%\FM-CAD\"
copy "G:\ACAD\setup\profile1.arg" "%USERPROFILE%\FM-CAD\profile1.arg"
copy "G:\ACAD\setup\profile2.arg" "%USERPROFILE%\FM-CAD\profile2.arg"
copy "G:\ACAD\setup\profile3.arg" "%USERPROFILE%\FM-CAD\profile3.arg"
copy "G:\ACAD\setup\profile4.arg" "%USERPROFILE%\FM-CAD\profile4.arg"
This adds the .arg files into the individuals own 'section' of windows but im stumped as how to get autocad to recognise them.
Thanks
Dommy2Hotty
26th Jan 2005, 07:08 pm
This adds the .arg files into the individuals own 'section' of windows but im stumped as how to get autocad to recognise them...
Meaning they do not show up in the "PROFILES" section of the "OPTIONS"? If so, you can create a script file and have the batch file start AutoCAD and run the script file after it copies the .arg's over.
Toffy
26th Jan 2005, 07:19 pm
Meaning they do not show up in the "PROFILES" section of the "OPTIONS"? If so, you can create a script file and have the batch file start AutoCAD and run the script file after it copies the .arg's over.
Thanks for your help.
Yes it copies the .arg's into c:\documents and settings\myname\FM-CAD
but they do not appear in the PROFILE section of CAD (in options)
Do you mean i could write a script file that would import the profiles? has anybody done this before? and could i ask the batch file to do it instead of having to actualy run the script file?
Dommy2Hotty
26th Jan 2005, 07:42 pm
I'll have to look into how to import the profile, but yes, the batch file can start AutoCAD and run the script. All you would have to do is execute the batch file
ECHO OFF
CLS
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO BATCH PLOT
ECHO 11x17 SHEET SIZE
ECHO SCALE: 1/4" = 1'-0"
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO Press "ESC" to Exit or...
pause
CLS
ECHO ON
FOR %%V IN (*A-??.DWG) DO START /W "c" "C:\Program Files\Autodesk Architectural Desktop 2005\acad.exe" %%V /nologo /C "C:\AutoCAD_Custom\Configs" /b "Z:\Scripts\Plotting\BatchPlot-11x17-48.scr"
ECHO OFF
CLS
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO PLOTTING COMPLETED SUCCESSFULLY!
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
PAUSE
FOR %%V IN (*.BAK) DO DEL %%V
FOR %%V IN (*.LOG) DO DEL %%V
FOR %%V IN (*.BAT) DO DEL %%V
Toffy
26th Jan 2005, 07:50 pm
I'll have to look into how to import the profile, but yes, the batch file can start AutoCAD and run the script. All you would have to do is execute the batch file
Thanks id be very grateful if you could do that as i cant find a command line way to get into options or profiles. (its not -profiles, -options or anything like that as far as i can tell)
but i dont really know what im doing when it comes to script files.
Dommy2Hotty
26th Jan 2005, 08:54 pm
The following taken from Kenny Ramage at AfraLisp (http://www.afralisp.com)
About Profiles (http://www.afralisp.com/vl/profiles.htm)
Profile Samples (shown below) (http://www.afralisp.com/vl/profile-samples.htm)
;;; DESCRIPTION:
;;; Sample profile manipulation utilities.
;;; All functions return T on success and nil
;;; on failure. See comments above each function
;;; for additional details.
;;;
;;; EXAMPLES:
;;;
;;; - Set active profile:
;;; (sample-profile-set-active "MyProfile")
;;;
;;; - Import a profile:
;;; (sample-profile-import
;;; "c:\\myExportedProfile.arg" "MyFavoriteProfile" T)
;;;
;;; - Delete a profile:
;;; (sample-profile-delete "unwanted")
;;;
;;;
;;; - Import a profile, even if it already exists, and set it active.
;;;
;;; (sample-profile-import "c:\\CompanyProfile.arg" "MyProfile" T)
;;; (sample-profile-set-active "MyProfile")
;;;
;;;
;;; - Import a profile, if not already present, and set it active
;;;
;;; (if (not (sample-profile-exists "myProfile"))
;;; (progn
;;; (sample-profile-import "c:\\CompanyProfile.arg" "MyProfile" T)
;;; (sample-profile-set-active "MyProfile")
;;; )
;;; )
;;;
;;;
;;; - Import a profile and set it active when AutoCAD is first started.
;;; Place the following code in acaddoc.lsp with the desired ".arg" filename
;;; and profile name...
;;;
;;; (defun s::startup ()
;;; (if (not (vl-bb-ref ':sample-imported-profile))
;;; ;;have we imported the profile yet?
;;; (progn
;;;
;;; ;; Set a variable on the bulletin-board
;;; ;; to indicate that we've been here before.
;;; (vl-bb-set ':sample-imported-profile T)
;;;
;;; ;; Import the profile and set it active
;;; (sample-profile-import
;;; "c:\\CompanyProfile.arg" "MyProfile" T)
;;; (sample-profile-set-active "MyProfile")
;;;
;;; );progn then
;;; );if
;;; );defun s::startup
;;;
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;
;; This helper function gets the profiles object.
;;
(defun sample-get-profiles-object ( / app pref profs )
(vl-load-com)
(and
(setq app (vlax-get-acad-object))
(setq pref (vla-get-preferences app))
(setq profs (vla-get-profiles pref))
)
profs
);defun sample-get-profiles-object
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;
;; Determine if a profile exists.
;; Returns T if the specified profile name exists, and nil if not.
;;
(defun sample-profile-exists ( name / profs )
(and name
(setq names (sample-profile-names))
(member (strcase name) (mapcar 'strcase names))
)
);defun sample-profile-exists
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;
;; Set the active profile.
;; NOTES:
;; - If the specified profile name is already active
;; then the function returns T and makes no additional
;; changes.
;;
;; - The specified profile must exist.
;; (You can import a profile using the 'sample-profile-import'
;; function.) If the specified profile does not exist, the
;; function returns nil.
;;
(defun sample-profile-set-Active ( name / profs )
(and
name
(setq profs (sample-get-profiles-object))
(or (equal (strcase name) (strcase (getvar "cprofile")))
(not (vl-catch-all-error-p (vl-catch-all-apply
'vla-put-activeProfile (list profs name))))
)
);and
);defun sample-profile-set-Active
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;
;; Delete the specified profile.
;; Fails if the specified profile is current.
;;
(defun sample-profile-delete ( name / profs )
(and
name
(setq profs (sample-get-profiles-object))
(not (vl-catch-all-error-p (vl-catch-all-apply
'vla-deleteprofile (list profs name))))
)
);defun sample-profile-delete
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;
;; Copy profile.
;;
(defun acad-pref-profile-copy ( source target / profs )
(and
source
target
(setq profs (sample-get-profiles-object))
(not (vl-catch-all-error-p (vl-catch-all-apply
'vla-CopyProfile (list profs source target))))
)
);defun sample-profile-copy
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;
;; Get a list of profile names
;;
(defun sample-profile-names ( / profs result )
(and
(setq profs (sample-get-profiles-object))
(not (vl-catch-all-error-p (vl-catch-all-apply
'vla-GetAllProfileNames (list profs 'result))))
result
(setq result (vlax-safearray->list result))
)
result
);defun sample-profile-names
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;
;; Rename
;;
(defun sample-profile-rename ( oldName newName / profs )
(and
oldName
newName
(setq profs (sample-get-profiles-object))
(not (vl-catch-all-error-p (vl-catch-all-apply
'vla-RenameProfile (list profs oldName newName))))
)
);defun sample-profile-rename
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;
;; Get a unique profile name.
;; This function returns a unique profile name
;; that is guaranteed to not be present in the current
;; list of profiles.
;;
(defun sample-get-unique-profile-name ( / names n name )
(setq names (sample-profile-names)
names (mapcar 'strcase names)
name "TempProfileName"
n 1
)
(while (member (strcase (setq name (strcat name (itoa n)))) names)
(setq n (+ n 1))
)
name
);defun sample-get-unique-profile-name
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;
;; Import
;; This function imports the specified .arg file and creates
;; a new profile with the provided profile name.
;; If the specified profile already exists, it will be overwritten.
;; If the 'bUsePathInfo' parameter is non-nil then path information
;; will be imported from the specified
;; file. Otherwise, path information will be ignored.
;;
;; NOTES:
;; This function does not set the active profile.
;; If you import a new profile it will not become active
;; unless it matches the name of the existing active profile.
;;
;; You can set the active profile by calling:
;; (sample-profile-set-active "ProfileName")
;;
(defun sample-profile-import ( filename profileName bUsePathInfo /
sample-old Error profs isCProfile
tempProfile result )
;; Set up an error handler so, if something goes wrong,
;;we can put things back the way we found them
(setq sample-oldError *error*)
(defun *error* ( msg / )
(if (and profileName
tempProfile
(equal tempProfile (getvar "cprofile"))
)
(progn
;; Something went wrong so put things back the way they were.
(sample-profile-rename tempProfile profileName)
(sample-profile-set-active profileName)
(sample-profile-delete tempProfile)
);progn then
);if
(setq *error* sample-oldError)
(if msg
(*error* msg)
(princ)
)
);defun *error*
(if (and bUsePathInfo
(not (equal :vlax-false bUsePathInfo))
)
(setq bUsePathInfo :vlax-true)
(setq bUsePathInfo :vlax-false)
)
(if (and filename
(setq filename (findfile filename))
profileName
(setq profs (sample-get-profiles-object))
);and
(progn
;; We can't import directly to the current profile,
;; so if the provided profile name matches
;; the current profile, we'll need to:
;; - rename the current profile to a unique name
;; - import
;; - set the new one current
;; - delete the old one with the temp name
(setq isCProfile (equal (strcase (getvar "cprofile"))
(strcase profileName)))
(if isCProfile
(progn
(setq tempProfile (sample-get-unique-profile-name))
(sample-profile-rename (getvar "cprofile") tempProfile)
);progn then
);if
;; Import
(setq result (not (vl-catch-all-error-p (vl-catch-all-apply
'vla-ImportProfile (list profs profileName
filename bUsePathInfo)))))
(if isCProfile
(progn
;; Handle current profile case...
;; If the import was successful,
;;then set the new profile active and delete the original
;; else if something went wrong, then put the old profile back
(if (and result
(setq result (sample-profile-set-Active profileName))
;; set the newly imported profile active
);and
(sample-profile-delete tempProfile)
;; then delete the old profile
(sample-profile-rename tempProfile profileName)
;; else rename the original profile back to its old name
);if
);progn then
);if
);progn then
);if
(*error* nil) ;; quietly restore the original error handler
result
);defun sample-profile-import
(princ)
Toffy
27th Jan 2005, 10:48 am
The following taken from Kenny Ramage at AfraLisp (http://www.afralisp.com)
About Profiles (http://www.afralisp.com/vl/profiles.htm)
Profile Samples (shown below) (http://www.afralisp.com/vl/profile-samples.htm)
again. thank you for going out of your way to help me.
I have tried playing with this code below and making a script file but it doesnt seem to work.
I tried putting this
(sample-profile-import "c:\\profile1.arg" "MyProfile" T)
in a text document and naming it test.scr but it doesnt seem to do anything in cad when run. I just get this
Command: scr
SCRIPT
Command: (sample-profile-import
(_> "c:\\profile1.arg" "myprofile.arg" T)
Error: Routine terminated.
Command:
SCRIPT
and asks for the script file name again.
if i use
sample-profile-import "c:\\profile1.arg" "MyProfile"
i get this
Command: scr
SCRIPT
Command: sample-profile-import Unknown command "SAMPLE-PROFILE-IMPORT". Press
F1 for help.
Sorry for being a nuicence but can somebody point me in the right direction?
hendie
27th Jan 2005, 03:31 pm
the above sample is a Lisp file and not a script.
You would still need to open Autocad in order to run it.
Toffy
1st Feb 2005, 05:16 pm
the above sample is a Lisp file and not a script.
You would still need to open Autocad in order to run it.
ok. so could i include it in a batch file still?
for instance
@ECHO OFF
ECHO Hit any key to run this file or press Ctrl+C to Cancel
================================================== ====
pause
md "%USERPROFILE%\FM-CAD\"
copy "c:\temp\ACAD2002.arg" "%USERPROFILE%\CAD\ACAD2002.arg"
"C:\Program Files\Autocad 2002\acad.exe"
[code for automaticaly running lisp this time only?]
Also for information this is what my batch file looks like to far
md "%USERPROFILE%\CAD\"
copy "G:\ACAD\setup\ACAD2002.arg" "%USERPROFILE%\CAD\ACAD2002.arg"
"C:\Program Files\Autodesk Map 3D 2005\acad.exe"
"C:\Program Files\Autocad 2002\acad.exe"
(LISP TO PUT PROFILES INTO CAD)
@TSKILL acad
I cant work out why cad wont close when running this, as if i run the command in a seperate batch file it does.
Powered by vBulletin™ Version 4.1.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.