Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Importing a profile through lisp

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
anieves228
518 Views, 11 Replies

Importing a profile through lisp

Hi All,

 

I'm trying to import a profile (.arg) through lisp. We will be doing a silent deployment of the acaddoc.lsp to +50 computers. Ive seen several lisps that claim to do this but since I'm not the best coder my understanding is limited. For example: from JTB world(I keep seeing this as a solution to quite a few forums). I don't know where I would actually put the profile location or name. Code below. Thank you in advance!

 

 

;;; profiles.lsp
;;; miscellaneous profile commands
;;; By Jimmy Bergmark
;;; Copyright (C) 1997-2008 JTB World, All Rights Reserved
;;; Website: www.jtbworld.com
;;; E-mail: info@jtbworld.com
;;;  2000-01-25
;;;  2003-01-23 Added functions
;;;  2008-08-08 Added forceImport

(vl-load-com)

; Brute force a profile to be imported
; (forceImport "profilename" "C:\\temp\\testprof.arg" 1)
; inclpathinfo=1 The path information in the registry file will be preserved.
; inclpathinfo=0 The path information in the registry file will not be preserved.
; return T if profile is imported
(defun forceImport (profilename argname inclpathinfo / tmp1 tmp2)
  (setq tmp1 "<<most-temporary1>>")
  (deleteProfile tmp1)
  (if (importProfile tmp1 argname inclpathinfo)
    (progn
      (putActiveProfile tmp1)
      (deleteProfile profilename)
      (renameProfile tmp1 profilename)
      (putActiveProfile profilename)
      T
    )
    nil
  )
)

(defun getActiveProfile ()
  (vla-get-activeprofile
    (vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))
  )
)

(defun putActiveProfile (profilename)
  (vla-put-activeprofile
    (vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))
    profilename
  )
)

(defun getAllProfileNames(/ allprofiles)
  (vla-getallprofilenames
    (vla-get-profiles (vla-get-preferences (vlax-get-acad-object))) 
    'allprofiles
  )
  (vlax-safearray->list allprofiles)
)

(defun existProfile (profilename)
  (not (not (member
    (strcase profilename)
    (mapcar '(lambda (x) (strcase x)) (getallprofilenames))
  )))
)

(defun c:listProfileNames(/ nr profnames)
  (setq nr 0)
  (setq profnames (getAllProfileNames))
  (repeat (length profnames)
    (princ (nth nr profnames))
    (print)
    (setq nr (1+ nr))
  )
  (princ)
)

; return T if profile is deleted and nil if not
(defun deleteProfile (profilename)
  (if (and
        (/= (strcase profilename) (strcase (getActiveProfile)))
        (existProfile profilename))
    (not (vla-deleteprofile
      (vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))
      profilename
    ))
  )
)

; Delete all profiles except the current profile
(defun deleteAllProfilesExceptCurrent (/ item)
  (foreach item	(getAllProfileNames)
    (vl-catch-all-apply
      'vla-deleteprofile
      (list (vla-get-profiles
	      (vla-get-preferences (vlax-get-acad-object))
	    )
	    item
      )
    )
  )
)

; return T if profile is reseted and nil if not
(defun resetProfile (profilename)
  (if (existProfile profilename)
    (not (vla-resetprofile
      (vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))
      profilename
    ))
  )
)

; return T if profile is renamed and nil if not
; if profilenameNew exist it's substituded with profilenameOld
(defun renameProfile (profilenameOld profilenameNew)
  (if (existProfile profilenameOld)
    (not (vla-renameprofile
      (vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))
      profilenameOld
      profilenameNew
    ))
  )
)

; return T if profile is copied and nil if not
; if profilename2 exists it's copied
(defun copyProfile (profilename1 profilename2)
  (if (existProfile profilename1)
    (not (vla-copyprofile
      (vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))
      profilename1
      profilename2
    ))
  )
)

; (exportProfile "profilename" "C:\\TEMP\\profilename.arg")
; if path is omitted profile is saved in active directory
; overwrites argname if it exists
; return T if profile is exported
(defun exportProfile (profilename argname)
  (if (existProfile profilename)
    (not (vla-exportprofile
      (vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))
      profilename
      argname
    ))
  )
)

; (importProfile "profilename" "C:\\TEMP\\profilename.arg" 1)
; overwrites profilename if it exists
; if path is omitted profile is imported from active directory
; inclpathinfo=1   The path information in the registry file will be preserved.
; inclpathinfo=0   The path information in the registry file will not be preserved.
; return T if profile is imported
(defun importProfile (profilename argname inclpathinfo)
  (not (vl-catch-all-apply 'vla-importprofile (list
    (vla-get-profiles (vla-get-preferences (vlax-get-acad-object)))
    profilename
    argname
    inclpathinfo
  ))
  )
)

; Brute force a profile to be imported and all the resting to be deleted
; (forceImportAndDeleteTheRest "profilename" "C:\\temp\\testprof.arg" 1)
; inclpathinfo=1   The path information in the registry file will be preserved.
; inclpathinfo=0   The path information in the registry file will not be preserved.
; return T if profile is imported
(defun forceImportAndDeleteTheRest (profilename argname inclpathinfo / tmp1 tmp2)
  (setq tmp1 "<<most-temporary1>>")
  (deleteProfile tmp1)
  (if (importProfile tmp1 argname inclpathinfo)
    (progn
      (putActiveProfile tmp1)
      (deleteProfile profilename)
      (renameProfile tmp1 profilename)
      (putActiveProfile profilename)
      (deleteAllProfilesExceptCurrent)
      T
    )
    nil
  )
)

 

 

11 REPLIES 11
Message 2 of 12
paullimapa
in reply to: anieves228

Looks like you'll have to include in acaddoc.lsp a line to load JTB world's profiles.lsp 

Then at the end of profiles.lsp include one of the following lines to import your profile:

; Brute force a profile to be imported
(forceImport "profilename" "C:\\temp\\testprof.arg" 1)

or:

; overwrites profilename if it exists
(importProfile "profilename" "c:\\temp\\profilename.arg" 1)

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 3 of 12
Sea-Haven
in reply to: anieves228

For 50 pc's have you looked at a setup lisp rather than playing with acaddoc.lsp ? I had multiple users would just run a lisp once on their pc and all is set up, it could set a profile but I just set all the support paths required, templates etc and loaded the correct menu's to be used, even added user prefer toolbar options. We ran from a server much easier as only 1 location for all code and relevant dwgs.

 

Sample, company names removed.

 

; resets the paths usefull for update versions of Autocad
; by AlanH Consulting
; This sets a reference to the install path of your product
; the gets are their for info maybe other use
; use this to find other settings 
;(vlax-dump-object (vla-get-files (vla-get-preferences (vlax-get-Acad-object))) T)



(vl-load-com)
(defun setpaths ( / *files* doc) 
; make temp directory
(if (vl-file-directory-p "C:\\Acadtemp\\")
(Princ "Acadtemp exists")
(vl-mkdir "C:\\AcadTEMP\\")
)


(setq *files*  (vla-get-files  (vla-get-preferences (vlax-get-Acad-object))))

; savepath
;(vla-get-AutoSavepath *files*)
(vla-put-AutoSavepath *files* "C:\\AcadTemp")

; custom icons
;(vla-get-CustomIconPath *files*))
(vla-put-CustomIconPath *files* "L:\\Autodesk\\ICONS")

; custom menu
;(vla-get-Menufile *files*))
;(vla-put-Menufile  *files* "C:\\Users\\2013xxx")

; printers config
;(vla-get-PrinterConfigPath *files*)
(vla-put-PrinterConfigPath *files* "L:\\AutoDESK\\Plotting\\Plot Styles 2011")

; printers style sheet
;(vla-get-PrinterStyleSheetPath *files*)
(vla-put-PrinterStyleSheetPath *files* "L:\\AutoDESK\\Plotting\\Plot Styles")

; printer drv's
;(vla-get-PrinterDescPath *files*)
(vla-put-PrinterDescPath *files* "L:\\AutoDESK\\Plotting\\Drv")

; print spooler
;(vla-get-PrintSpoolerPath *files*)
(vla-put-PrintSpoolerPath *files* "C:\\AcadTemp\\")

; template  path
;(vla-get-TemplateDwgPath *files*)
(vla-put-TemplateDwgPath *files* "L:\\Autodesk\\c3d Templates")

; template location
;(vla-get-QnewTemplateFile *files*)
(vla-put-QnewTemplateFile *files* "L:\\Autodesk\\c3d Templates\\xxxx-2019.dwt")

;make new support paths exist + new
(setq paths (vla-get-SupportPath *files*))
(setq XXXXpaths "L:\\autodesk\\supportfiles;L:\\autodesk\\lisp;L:\\autodesk\\fonts;")
(setq newpath (strcat XXXXpaths paths))
(vla-put-SupportPath *files* newpath)

; Tempdirectory 
;(vla-get-TempFilePath *files*))
(vla-put-TempFilePath *files* "C:\\AcadTemp\\")

;   PlotLogFilePath = "C:\\Documents and Settings\\YYYY.XXXX-AD\\localsettings\\application data\\autodesk\\c3d 2011\\enu\\"
(vla-put-PlotLogFilePath *files* "C:\\AcadTemp\\")

;   LogFilePath = "C:\\Documents and Settings\\YYYY.XXXX-AD\\localsettings\\application data\\autodesk\\c3d 2011\\enu\\"
(vla-put-LogFilePath *files* "C:\\AcadTemp\\")


; xref temp path
;(vla-get-TempXrefPath *files*))
(vla-put-TempXrefPath *files* "C:\\AcadTemp\\")

; end use of *files*

(setq oldtrust (getvar 'trustedpaths))
(setq newtrust (strcat oldtrust ";" "L:\\Autodesk..."))
(setvar 'trustedpaths newtrust)


(princ "All Done")
) ; defun

(alert "\nSupport and trusted paths added")

(setq Menu_Path "C:\\xxx-CAD-TOOLS\\") ; Path to Menu file
(setq Menu_Name "xxx-CAD-TOOLS") ; pop menu to load
(setq Group_Name "xxxMENU") ; groupname assigned in .mnu or .mns file

(if (menugroup menu_Name)
(command "_MENUUNLOAD" menu_Name)
)
(setq cnt (vla-get-count(vla-get-menuGroups (vlax-get-acad-object))))
(if  (> (vl-string-search  "BRICSCAD" (strcase(getvar 'product))) 0)
(progn
(command "MENULOAD" (strcat Menu_Path Menu_Name ".mnu"))
(menucmd (strcat "P" (rtos (+ cnt 1) 2 0) "=+" menu_Name ".POP1"))
)
(progn
(command "MENULOAD" (strcat Menu_Path Menu_Name ".mnu"))
(menucmd (strcat "P" (rtos (+ cnt 1) 2 0) "=+" menu_Name ".POP1"))
)
)
(setvar "menubar" 1)
(command "workspace" "save" "Username" "y")

(setpaths)

(alert "Run user script for toolbars")


; exit quitely

 

 

If you need to install local version of code and dwg's can use a zip with lisp controlling where the unzip downloads to, the other way is to do an Autocad BUNDLE. 

Message 4 of 12
anieves228
in reply to: paullimapa

Ah ok it works thank  you!

Message 5 of 12
anieves228
in reply to: Sea-Haven

I have some set-up files but not to the support paths like you have which will likely work better for me. 

Message 6 of 12
paullimapa
in reply to: anieves228

Glad to have helped…cheers!!!

PS: a shout out to Jimmy Bergmark for providing all these great lisp functions 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 7 of 12
anieves228
in reply to: Sea-Haven

How would I add an if to the paths? if the path exists it'll move on to the next one. 

Message 8 of 12
anieves228
in reply to: Sea-Haven

This would be my poor attempt at creating an foreach and if 

    (foreach SP '
      (
        "X:\\Automation\\Lisp Routines\\config\\Support"
        "X:\\Automation\\Lisp Routines\\config\\fonts"
        "X:\\Automation\\Lisp Routines\\config\\LINETYPES"
      )
      
      (if
        (not
          (tblsearch Paths (vla-get-SupportPath *files*) SP)
        )
        
        (
          (setq paths (vla-get-SupportPath *files*))
      
          (setq XXXXpaths 
            "X:\\Automation\\Lisp Routines\\config\\Support;
            X:\\Automation\\Lisp Routines\\config\\fonts;
            X:\\Automation\\Lisp Routines\\config\\LINETYPES;"
          )
        
          (setq newpath (strcat XXXXpaths paths))
          (vla-put-SupportPath *files* newpath)
        )
      )
    )
Message 9 of 12
MrJSmith
in reply to: anieves228

I use a function to set support paths.

 

 

;Pass it Enviroment Variable to look for along with the path to add. The paths to add are pushed onto the front of the list, making them higher priority.
(defun AddSupportPath (dir enviromentVariable / Cpath) 
	; (print "enviromentVariable: ") (princ enviromentVariable)
	; (print "dir: " ) (princ dir)
	
	(if (setq Cpath (getenv enviromentVariable))
		(if (not (vl-string-search dir Cpath)) 
			(setenv enviromentVariable (strcat dir ";" CPath))
		)
	)
	(princ)
)
;Add Fonts Path
; (AddSupportPath  "L:\\AutoCAD\\FONTS" "ACAD")
;Adds the support search paths using the variable "ACAD"
(foreach it (list "!Essential" "!User" "!Optional") ;Highest Priority is Optional, then User, then Essential
	(AddSupportPath (strcat *lispFolder* it) "ACAD")
)

 

For your example, you could just loop through your list of paths to add and do "(AddSupportPath SP "ACAD")". It should only add them if they don't exist already. Note: Adding print configs is a little bit different.

 

Message 10 of 12
anieves228
in reply to: MrJSmith

Awesome thank you!

 

How would I add the "Printer Support File Paths"

Message 11 of 12
MrJSmith
in reply to: anieves228

Sorry turns out it is only "different" if you are doing it for BCAD. Otherwise you'd just set your printer path to the PrinterStyleSheetDir environment variable. See below:

(setq ctbFilesPath "X:\\XXXX\\Plot Styles")
(if (getenv "PrinterStyleSheetDir")
	(AddSupportPath ctbFilesPath "PrinterStyleSheetDir")
	(if (setq path (getvar "plotstylepath")) ;All this below is for BricsCAD
		(if (not (vl-string-search ctbFilesPath path))
			(setvar "plotstylepath" (strcat path ";" ctbFilesPath))
		)
	)
)
Message 12 of 12
Sea-Haven
in reply to: anieves228

2 comments, I use WCMATCH to check if support path exists, you can copy the desktop icon and edit its properties, I think its under Target there wil be a "/P profilename" eg /P <CIV3D> so you edit the profile name to what you want, we had laptops with 2 desktop icons, laptop remote & Office so would set support paths etc correct.

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report