TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ELOQUINTET on January 10, 2008, 10:49:21 AM

Title: load certain files in startup suite based on profile
Post by: ELOQUINTET on January 10, 2008, 10:49:21 AM
We have 2 different profiles with the main difference being the printer configurations. I have taken some code that i had in our acad.lsp and and created 2 seperate lisp files which will load page setups from different dwt files. I am having to add the appropriate lisp file to the startup suite depending on which profile is loaded. I'm wondering if there is a way I can automate this process?
Title: Re: load certain files in startup suite based on profile
Post by: Guest on January 10, 2008, 10:52:48 AM
Why not just load it from the ACAD.lsp file instead, depending on what profile name is active?
Title: Re: load certain files in startup suite based on profile
Post by: ELOQUINTET on January 10, 2008, 10:57:31 AM
yes i suppose it could be done from that end as well. the lisp is below and the only difference between this one and the other is the dwt it loads from. i would need to see which profile is active then load the page setups from the corresponding dwt. How would i modify this to make that happen? Thanks Matt

Code: [Select]
;;  Function to delete all user plot set ups then load page setups from page-setups.dwt
(defun c:Del_Pagesetups (/ curdwg pslayout x)
 (vl-load-com)
 (setq
   curdwg   (vla-get-ActiveDocument (vlax-get-Acad-Object))
   pslayout (vla-get-Layout (vla-get-PaperSpace curdwg))
 ) ;_ end of setq
 ;; Call RefreshPlotDeviceInfo before GetPlotDeviceNames
 (vla-RefreshPlotDeviceInfo pslayout)
 (vlax-for x (vla-get-Plotconfigurations curdwg)
   (vla-delete x)
 ) ;_ end of vlax-for
)               ; End Plot_config_list
(c:Del_Pagesetups)

(command ".-psetupin" "PAGE-SETUPS.DWT" "*")

(defun c:change_page_setups (/ *adoc*      *adoc*
     *layouts* page_setups dcl_id
     userclick selection   plotcfg
     clay
    )
;;;
  (defun get_page_setup (doc func / lst)
    (vlax-map-collection
      (vla-get-plotconfigurations doc)
      '(lambda (x) (setq lst (cons ((eval func) x) lst)))
    )
    (reverse lst)
  )
;;;
  (defun getSelectedItems (tilename AllItemsList / indexes)
    (if (setq indexes (get_tile tilename))
      (setq indexes (read (strcat "(" indexes ")"))
    indexes (mapcar '(lambda (n) (nth n AllItemsList))
    indexes
    )
      )
    )
    indexes
  )
;;;
  (setq *acad* (vlax-get-acad-object))
  (setq *adoc* (vla-get-activedocument *acad*))
  (setq *layouts* (vla-get-layouts *adoc*))
  (vl-load-com)
  (defun on_list_pick ()
    (if (= (get_tile "page_setup_names") "")
      (mode_tile "select" 1)
      (mode_tile "select" 0)
    )
  )
  (and
    (setq page_setups (get_page_setup *adoc* 'vla-get-name))
    (setq dcl_id (load_dialog "page_setups.dcl"))
    (new_dialog "page_setup" dcl_id)
    (start_list "page_setup_names")
    (mapcar 'add_list page_setups)
    (not (end_list))
    (action_tile "cancel" "(done_dialog 0)")
    (action_tile
      "select"
      (strcat
"(setq selection (getSelectedItems \"page_setup_names\" page_setups))"
"(done_dialog 1)"
      )
    )
    (action_tile "page_setup_names" "(on_list_pick)")
    (not (mode_tile "select" 1))
    (setq userclick (start_dialog))
  )
  (if dcl_id
    (unload_dialog dcl_id)
  )
  (if (and userclick selection)
    (and
      (setq plotcfg (vla-item (vla-get-plotconfigurations *adoc*)
      (car selection)
    )
      )
      (vlax-map-collection
*layouts*
'(lambda (x)
   (if (eq (vla-get-modeltype x) :vlax-false)
     (vla-copyfrom x plotcfg)
   )
)
      )
    )
  )
  (princ)
)
Title: Re: load certain files in startup suite based on profile
Post by: Guest on January 10, 2008, 11:24:25 AM
(alert (getvar "cprofile"))  will tell you what the current profile name is.
Title: Re: load certain files in startup suite based on profile
Post by: ELOQUINTET on January 10, 2008, 11:49:13 AM
yes i know how to get the current profile but don't need to alert the user. i need to load page setups from a dwt based on which is current.
Title: Re: load certain files in startup suite based on profile
Post by: ronjonp on January 10, 2008, 11:58:39 AM
yes i know how to get the current profile but don't need to alert the user. i need to load page setups from a dwt based on which is current.

Code: [Select]
(defun instemp (/ pro)
  (setq pro (strcase (getvar 'cprofile)))
  (cond ((= pro "TEMP1")
;;do stuff
)
((= pro "TEMP2")
;;do stuff
)
((= pro "TEMP2")
;;do stuff
)
  )
)
Title: Re: load certain files in startup suite based on profile
Post by: pmvliet on January 10, 2008, 01:40:22 PM
You say you are switching profiles for printer configurations. May I ask what you are changing
that is unique? Or why you need 2 different profiles?

The reason I am asking is you are changing profiles which then causes you to change printing characteristics.
In your case, you have 2 of each and  1 of each go together if I am following you correctly.

I'm just thinking, you can make the profile change and printing preference change in one lisp routine
and only have 1 profile for your users.

If you don't want to consider that, the suggestion by ronjonp would work.
Or if your different profiles had a menu (could be hidden) you could put it in
that menu.mnl file.

Pieter
Title: Re: load certain files in startup suite based on profile
Post by: ELOQUINTET on January 10, 2008, 02:39:47 PM
OK here is the scenario that i have. i have some drafters in my department and i have some more drafters in another department. when we want to print an 8x11 drawing we choose a pagesetup which will send it to this printer and when they choose the same page setup it goes to another printer. i initially created different pc3 files for them and gave them a different mapping for pc3 files in options. i nitially just had one profile and just manually changed this path when installing. The problem I was encountering was that if a user selects a pagesetup that uses a pc3 file which looks for a plotter they don't have installed it tells them they need to update the pc3 file. this dialogue box does not allow the user to cancel out so most users just select another printer which in turn screws up the pc3 for the people who have that printer installed. the quick fix would be to have everyone that does cad connected to all of the possible printers but the other people are in a different workgroup and the IT guys claim that they don't have time to install a printer that the user will not be using and don't want to allow me to do it either. To avoid this conflict i wanted to setup two profiles, template files with pagesetups in them and 2 folders with different pc3 files. I don't want the user to have the option so select screw it up on any level. Does this make sense now?
Title: Re: load certain files in startup suite based on profile
Post by: ELOQUINTET on January 10, 2008, 02:41:43 PM
Ron,

I tried to implement your idea and put the code back in our acad.lsp but it is not loading any pagesetups?

Code: [Select]
(defun loadfromdwt (/ pro)
  (setq pro (strcase (getvar 'cprofile)))
  (cond ((= pro "Mechoshade Standard")
(command ".-psetupin" "PAGE-SETUPS.DWT" "*")
)
((= pro "Mechoshade Standard PM")
(command ".-psetupin" "PAGE-SETUPS PM.DWT" "*")
)
  )
)
Title: Re: load certain files in startup suite based on profile
Post by: ronjonp on January 10, 2008, 02:49:57 PM
The strcase is looking for an all caps string to match to.

Try this....it will remove all pagesetups before trying to import so it won't stall when a duplicate is encountered.

Code: [Select]
(defun loadfromdwt (/ pro pc)
  (setq pro (getvar 'cprofile)
pc  (vla-get-Plotconfigurations
      (vla-get-ActiveDocument
(vlax-get-Acad-Object)
      )
    )
  )
  (cond ((= pro "Mechoshade Standard")
(vlax-map-collection pc 'vla-delete)
(command ".-psetupin" "PAGE-SETUPS.DWT" "*")
)
((= pro "Mechoshade Standard PM")
(vlax-map-collection pc 'vla-delete)
(command ".-psetupin" "PAGE-SETUPS PM.DWT" "*")
)
  )
  (princ)
)
Title: Re: load certain files in startup suite based on profile
Post by: pmvliet on January 10, 2008, 04:09:49 PM
Instead of loading files based on profile, why don't you have it change based on who they are or as you state they are in a different workgroups?? If they are in "your workgroup" load this and if they are in "that workgroup" load that.
Why involve multiple profiles if you don't need to... I apologize if I'm missing something totally obvious

Another option would be to implement a different plotting system that it automated such like MP is working on:
http://www.theswamp.org/index.php?topic=20741.msg (http://www.theswamp.org/index.php?topic=20741.msg)

I developed something similar using scripts and a plotting pull-down menu.
If the user wanted to print 11x17 to the printer next to them, they selected it.
If they then wanted an 11x17 to print across the hall, they selected that option.
Everything is behind the scenes and I did not keep page setups in each individual file.

I guess that is getting away from what you desire, but I'm just trying to look at it from
a different perspective.

Pieter

Title: Re: load certain files in startup suite based on profile
Post by: ELOQUINTET on January 10, 2008, 04:39:35 PM
ron the complete routine deletes all page setups prior to loading specified new ones (see full code at the beginning). So you are saying all I need to do is capitalize the profile names and strcase should work fine? I will test this out myself. Pieter I understand what you mean but I think in my environment this method is the easiest to use. We have people moving back and forth between these 2 workgroups (don't ask) so it's easiest to load a different profile if they move and off to work they go. Thanks for your input though
Title: Re: load certain files in startup suite based on profile
Post by: ronjonp on January 10, 2008, 04:48:23 PM
I would do it like pmvliet....right now I check the IP addresses (same domain, two different logon servers) to determine which pagesetups need to be loaded and what shared printers need to be pointed to.
Title: Re: load certain files in startup suite based on profile
Post by: ELOQUINTET on January 10, 2008, 04:56:10 PM
well i tried to put the profile names in caps and even eliminate spaces and it doesn't load any page setups. I would really prefer not to have to go to that deep of a level because when I start probing that deeply in our network configuration the IT guys get defensive and elude my questions. This is why I'd prefer to not have to have it based on network info but autocad profile that way i am in control of the variables.
Title: Re: load certain files in startup suite based on profile
Post by: ronjonp on January 10, 2008, 05:01:49 PM
Did you try my last solution?
Title: Re: load certain files in startup suite based on profile
Post by: ELOQUINTET on January 10, 2008, 05:13:28 PM
Ron,

If you mean this one I changed the profile names back to match those in the code then put this in our acad.lsp and when I open acad it shows some page setups but I don't think it deletes the ones that already exist in our template because when i switch to the other profile and restart autocad the pagesetups are not different. All I have in acad.lsp is this:

Code: [Select]
(defun loadfromdwt (/ pro pc)
  (setq pro (getvar 'cprofile)
pc  (vla-get-Plotconfigurations
      (vla-get-ActiveDocument
(vlax-get-Acad-Object)
      )
    )
  )
  (cond ((= pro "Mechoshade Standard")
(vlax-map-collection pc 'vla-delete)
(command ".-psetupin" "PAGE-SETUPS.DWT" "*")
)
((= pro "Mechoshade Standard PM")
(vlax-map-collection pc 'vla-delete)
(command ".-psetupin" "PAGE-SETUPS PM.DWT" "*")
)
  )
  (princ)
)
Title: Re: load certain files in startup suite based on profile
Post by: ronjonp on January 10, 2008, 05:28:46 PM
Are you calling it by using (loadfromdwt)?
Title: Re: load certain files in startup suite based on profile
Post by: ELOQUINTET on January 10, 2008, 05:43:38 PM
i'm just putting it in my acad.lsp but not running it. so should i rather save this out as a seperate lisp then run it from acad.lsp. I'm not sure I understand you're question I guess?
Title: Re: load certain files in startup suite based on profile
Post by: ronjonp on January 10, 2008, 05:48:02 PM
You need to run it, all you are doing is loading it....

(defun loadfromdwt (/ pro pc)
  (setq   pro (getvar 'cprofile)
   pc  (vla-get-Plotconfigurations
         (vla-get-ActiveDocument
      (vlax-get-Acad-Object)
         )
       )
  )
  (cond   ((= pro "Mechoshade Standard")
   (vlax-map-collection pc 'vla-delete)
   (command ".-psetupin" "PAGE-SETUPS.DWT" "*")
   )
   ((= pro "Mechoshade Standard PM")
   (vlax-map-collection pc 'vla-delete)
   (command ".-psetupin" "PAGE-SETUPS PM.DWT" "*")
   )
  )
  (princ)
)
(loadfromdwt);;this is what runs the routine
Title: Re: load certain files in startup suite based on profile
Post by: ELOQUINTET on January 11, 2008, 09:18:08 AM
ah i see now i got it it works great. i added it to our acad.lsp and it's super. i will be testing this further today but for now it looks like exactly what i needed. thanks for your help
Title: Re: load certain files in startup suite based on profile
Post by: ronjonp on January 11, 2008, 09:27:59 AM
Glad to help :)
Title: Re: load certain files in startup suite based on profile
Post by: ELOQUINTET on January 16, 2008, 04:25:03 PM
Ron or anyone else who might have some insight. I added this code to our acad.lsp and are having some problems when publishing. Let me explain, We do not and cannot have a pagesetup for every possible printing scenario for instance we get architectural files in so many forms that we often have to create a page setup for this using window, save the page setup, then open publish and apply this page setup to any added layouts. It is stopping after the first layout publishes. What I need to figure out is how to specify a list of layouts to delete using the vla-delete part and retain whatever page setups were created for that file. In other words I want it to delete only the page setups, which ever ones are present which would need to be redefined when they are imported from the dwt(s). Am I making sense?
Title: Re: load certain files in startup suite based on profile
Post by: ronjonp on January 16, 2008, 04:48:09 PM
Dan,

You could use something like this to remove only the pagesetups in the list of names:

Code: [Select]
(vlax-map-collection
  pc
  '(lambda (x)
     (if (member
   (vla-get-name x)
   '("nameofpagesetup1" "nameofpagesetup2" "nameofpagesetup2");;names here...case sensitive
)
       (vla-delete x)
     )
   )
)
Title: Re: load certain files in startup suite based on profile
Post by: ELOQUINTET on January 16, 2008, 05:29:56 PM
ron when i load it now i am getting this message, what's going on?

error: misplaced dot on input

Code: [Select]
;;This loads the page setups from either page setups.dwt or setups pm.dwt depending on which profile is loaded
(defun loadfromdwt (/ pro pc)
  (setq   pro (getvar 'cprofile)
   pc  (vla-get-Plotconfigurations
         (vla-get-ActiveDocument
      (vlax-get-Acad-Object)
         )
       )
  )
  (cond   ((= pro "Mechoshade Standard")
(vlax-map-collection
  pc
  '(lambda (x)
     (if (member
   (vla-get-name x)
   '("A1-FX" "A1-PDF 5D" "A1-PDF Bluebeam" "A1-PROT" "d-prot-500ps" "d-prot-800" D-Prot PDF Bluebeam" "D-Prot Xerox510" "DETAILS 11 X 17" "DETAILS 11 X 17 PDF 5D" "DETAILS 11 X 17 PDF Bluebeam" "HP LASER 11x17" "LANDSCAPE" "LANDSCAPE-PDF" "LEGAL" "LEGAL-FAX" "LEGAL-PDF" "small_copy")
)
       (vla-delete x)
     )
   )
)
   (command ".-psetupin" "PAGE-SETUPS.DWT" "*")
   )
   ((= pro "Mechoshade Standard PM")
   (vlax-map-collection pc 'vla-delete)
   (command ".-psetupin" "PAGE-SETUPS PM.DWT" "*")
   )
  )
  (princ)
)
(loadfromdwt);;this is what runs the routine
Title: Re: load certain files in startup suite based on profile
Post by: ronjonp on January 16, 2008, 05:32:35 PM
D-Prot PDF Bluebeam" is missing a quote.

On a side note....are you familiar with the VLIDE editor? If you put your code in there to analyze it, the color coding and auto formatting would really help you with some of this small troubleshooting. (VLIDE on the command line...NEW...then paste in your code).



Title: Re: load certain files in startup suite based on profile
Post by: Kerry on January 16, 2008, 05:37:57 PM
D-Prot PDF Bluebeam" is missing a quote.

Eloquintet 
 
If you were to use the VLIDE in AutoCAD to view the code you'd notice this mismatch immediately.


Oooops , Ron updated his post to show the same thing :-)
Title: Re: load certain files in startup suite based on profile
Post by: ELOQUINTET on January 17, 2008, 10:30:35 AM
Sorry guys I should've done that but my mind is not functioning on all cylinders right now. I am about to leave my job and am trying to fix a bunch of things and whatnot. my apologies