Small Fish Posted February 26, 2010 Posted February 26, 2010 In a dwg file that has more than one tab I would like to check if the plotter device is set to 'NONE' on any of the tabs. First I tried using : (setq GetActivePlotDevice(vla-get-ConfigName (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object))))) to find the plotter device in the current tab. This doesn't seem to work. Is there a way to find the plotter device name? I other questions but that is all for now - thanks cheers Quote
Lee Mac Posted February 26, 2010 Posted February 26, 2010 Perhaps something like this? (defun GetPlotDevices (/ dvc) (vl-load-com) ;; Lee Mac ~ 26.02.10 (vlax-map-collection (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object))) (function (lambda (layout) (vla-RefreshPlotDeviceInfo layout) (setq dvc (cons (cons (vla-get-name layout) (vla-get-ConfigName layout)) dvc))))) (reverse dvc)) Quote
alanjt Posted February 26, 2010 Posted February 26, 2010 (vla-get-configname (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object)))) Works just fine for me. Returns "None" if nothing or the plotting device name. Edit: Oops, didn't realize you replied. I hit reply, got up for a second, sat back down and finished responding. Quote
Lee Mac Posted February 26, 2010 Posted February 26, 2010 Edit: Oops, didn't realize you replied. I hit reply, got up for a second, sat back down and finished responding. Hey, no worries dude As you say, the code that SmallFish posted seemed to be correct, but sometimes I find you have to call: (vla-RefreshPlotDeviceInfo <layout>) first. Lee Quote
alanjt Posted February 26, 2010 Posted February 26, 2010 Hey, no worries dude As you say, the code that SmallFish posted seemed to be correct, but sometimes I find you have to call: (vla-RefreshPlotDeviceInfo <layout>) first. Lee That's true. I've encountered that in the past. Quote
alanjt Posted February 26, 2010 Posted February 26, 2010 I was just curious... (defun PlotDevices (/ #List) (vlax-for x (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (vla-refreshplotdeviceinfo x) (setq #List (cons (cons (vla-get-name x) (vla-get-configname x)) #List)) ) ;_ vlax-for (reverse #List) ) ;_ defun Command: (benchmark '( (getplotdevices) (plotdevices) )) Elapsed milliseconds / relative speed for 64 iteration(s): (PLOTDEVICES)........1203 / 1.17 <fastest> (GETPLOTDEVICES).....1407 / 1.00 <slowest> Command: (benchmark '( (getplotdevices) (plotdevices) )) Elapsed milliseconds / relative speed for 64 iteration(s): (GETPLOTDEVICES).....1218 / 1.00 <fastest> (PLOTDEVICES)........1219 / 1.00 <slowest> Command: (benchmark '( (getplotdevices) (plotdevices) )) Elapsed milliseconds / relative speed for 64 iteration(s): (PLOTDEVICES)........1219 / 1.01 <fastest> (GETPLOTDEVICES).....1234 / 1.00 <slowest> Command: (benchmark '( (getplotdevices) (plotdevices) )) Elapsed milliseconds / relative speed for 64 iteration(s): (GETPLOTDEVICES).....1219 / 1.00 <fastest> (PLOTDEVICES)........1219 / 1.00 <slowest> Command: (benchmark '( (getplotdevices) (plotdevices) )) Elapsed milliseconds / relative speed for 64 iteration(s): (PLOTDEVICES)........1218 / 1.00 <fastest> (GETPLOTDEVICES).....1219 / 1.00 <slowest> Quote
Small Fish Posted February 26, 2010 Author Posted February 26, 2010 Thanks Alan and Lee mac .....so it was the old "vla-RefreshPlotDeviceInfo" function that I needed . cheers . Quote
alanjt Posted February 26, 2010 Posted February 26, 2010 Thanks Alan and Lee mac .....so it was the old "vla-RefreshPlotDeviceInfo" function that I needed . cheers . Enjoy and have a good weekend. Quote
Small Fish Posted February 26, 2010 Author Posted February 26, 2010 One more question... I would like to alert/princ the user that there are one or more tabs that have 'none' as the plot device - how do I check for any 'none' pairs in the dvc dotted pair list? thanks Quote
alanjt Posted February 26, 2010 Posted February 26, 2010 One more question...I would like to alert/princ the user that there are one or more tabs that have 'none' as the plot device - how do I check for any 'none' pairs in the dvc dotted pair list? thanks Maybe something like this... (and (setq #Alert "") (foreach x (GetPlotDevices) (and (eq "None" (cdr x)) (setq #Alert (strcat #Alert (car x) "\n")) ) ;_ and ) ;_ foreach (alert (strcat "Layouts without defined plotter devices:\n\n" #Alert)) ) ;_ and Quote
Small Fish Posted February 26, 2010 Author Posted February 26, 2010 Hey Alan that looks good (I can't try it yet - but I'm sure it works) many thanks SM Quote
alanjt Posted February 26, 2010 Posted February 26, 2010 Hey Alan that looks good (I can't try it yet - but I'm sure it works) many thanks SM I think it'll give you what you need. Quote
Lee Mac Posted February 26, 2010 Posted February 26, 2010 Thanks Alan, I realised that vlax-map-collection is slower, but I fancied a change They should make vlax-map-collection act like mapcar to make it really useful. Quote
alanjt Posted February 26, 2010 Posted February 26, 2010 Thanks Alan, I realised that vlax-map-collection is slower, but I fancied a change They should make vlax-map-collection act like mapcar to make it really useful. I'd never used vlax-map-collection. I was just curious about the speed. Quote
Small Fish Posted March 1, 2010 Author Posted March 1, 2010 Alan thanks yes it works well and I like that alert box that can add depending on the list. However I seem to be having a problem with the alert box not working intermittely - and I'm not sure why? I originally also was going to make a list of tabs that had the printer set to 'NONE' however that may be too difficult. What I was trying to do is exit the code if any of the tabs selected are set to 'None' then asking the user to set to a printer device. now I've got sore eyes and a headache... I'm trying to: 1) I want to make the alert box work again 2) exit if 'none' is selected for a plotter device 3) If tabs selected do not have any 'none' then continue on. (maybe even let the user change the plotter device while program is running - but that sounds difficult) (defun c:plotdev2 (/ layout dvc #Alert layouts_to_plot) (vl-load-com) (vlax-map-collection (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object))) (function (lambda (layout) (vla-RefreshPlotDeviceInfo layout) (setq dvc (cons (cons (vla-get-name layout) (vla-get-ConfigName layout)) dvc))))) (reverse dvc) (and (setq #Alert "") (foreach x dvc (and (eq "None" (cdr x)) (setq #Alert (strcat #Alert (car x) "\n")) ) ;_ and ) ;_ foreach (alert (strcat "Layouts without defined plotter devices:\n\n" #Alert)) (exit) ) ;_ and (setq layouts_to_plot (dos_multilist " A3 prints to printer" "Select drawings to be printed" (ListLayouts))) ;more to be added later.... (princ) );defun Quote
Lee Mac Posted March 1, 2010 Posted March 1, 2010 Something like this perhaps: (defun c:plotdev2 (/ GetPlotDevices lst2str Devices) (vl-load-com) (defun GetPlotDevices (/ dvc) ;; Lee Mac ~ 26.02.10 (vlax-map-collection (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object))) (function (lambda (layout) (vla-RefreshPlotDeviceInfo layout) (setq dvc (cons (cons (vla-get-name layout) (vla-get-ConfigName layout)) dvc))))) (reverse dvc)) (defun lst2str (lst del) (if (cdr lst) (strcat (car lst) del (lst2str (cdr lst) del)) (car lst))) (if (setq Devices (vl-remove-if-not (function (lambda (x) (eq "None" (cdr x)))) (GetPlotDevices))) (alert (strcat "Layouts without defined plotter devices:\n\n" (lst2str (mapcar (function car) Devices) "\n")))) (princ)) Quote
alanjt Posted March 1, 2010 Posted March 1, 2010 ?? (defun test (/ #Msg) (setq #Msg "") (vlax-for x (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))) (vla-refreshplotdeviceinfo x) (and (eq (vla-get-configname x) "None") (setq #Msg (strcat #Msg (vla-get-name x) "\n")) ) ;_ and ) ;_ vlax-for (if (eq "" #Msg) (alert "All layouts have a defined plotter device.") (alert (strcat "Layouts without defined plotter devices:\n\n" #Msg)) ) ;_ if ) ;_ defun Quote
Small Fish Posted March 1, 2010 Author Posted March 1, 2010 wow! that works well - thanks Alan and Lee8) there's so much to learn..... Quote
Lee Mac Posted March 1, 2010 Posted March 1, 2010 You're welcome Mr Fish - I probably went for the more OOP approach, but Alans will most likely be faster. Quote
alanjt Posted March 1, 2010 Posted March 1, 2010 wow! that works well - thanks Alan and Lee8)there's so much to learn..... You're welcome. There's always something new to learn. You're welcome Mr Fish - I probably went for the more OOP approach, but Alans will most likely be faster. Well, I just thought I'd show him a less laborious option. Nothing wrong with yours, it's just slowed down by processing the same list 3 times, plus the recursion sub. What's the OOP approach? Quote
Recommended Posts
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.