Jump to content

Combining 2 LISP routines?


Guest Drafter_Joe

Recommended Posts

Guest Drafter_Joe

Hi!

 

I have a LISP routine, GOCHNGPLT, that I wonder if it can be combined with another, GETPLOTDEVICES, so that GOCHNGPLT only runs if it has to? I don't understand either AutoLISP or VisualLISP well enough to easily figure this out, or at all.

 

GETPLOTDEVICES returns a list of each layout and the plotter for each. GOCHNGPLT changes a plotter to a "default" plotter.

 

I need the plotter used in GOCHNGPLT to be checked against the plotter in each layout and only change the layouts that use a different plotter, if I want it to at the time, or quietly exit before the dialog box opens if the plotters in all the layouts are the same as the one in GOCHNGPLT. I can see that a loop is required with conditional statements, but I don't know how to use VLISP to do that.

 

I have attached the LISP files so that the post will not be any longer than necessary.

 

Any advice or ideas are most welcome!

 

Thank you for your time and attention!

 

Joe

GOCHNGPLT.lsp

getplotdevices.lsp

Link to comment
Share on other sites

hi, im not sure am i right,

example if we have this:

'(("Layout1" . "RICOH Aficio MP C3500 PCL 6") ("Layout2" . "None") ("Model" . "Bullzip PDF Printer")) 

so you need to apply the ploting device on the GOCHNGPLT.lsp?

 

Is this your default plotter?

(setq device "\\\\jec-fpb01\\HP LaserJet 5200 Series PCL 5") 

ie: you intend to switch the device based on the list provided by getplotdevices.lsp c:GPD ?

note: i suggest to localize variable

(defun C:GPD (/ [color="red"]dvc[/color])
...
...

 

regarding GOCHGPLT.lsp

I'm not sure need to prefix

device to (strcat "\\\jec-fpb01\\" device) ?

but you can try both..

 

add in blue

...
...
(foreach item (layoutlist) ;
 [color="blue"][b](if (setq device (cdr	(assoc item (vl-remove-if ''((x) (= (cdr x) "None")) (c:GPD)))[/b] ;_ end of assoc
[b]		)[/b] ;_ end of cdr
    [b])[/b] ;_ end of setq[/color]
   (progn (setvar "ctab" item)
   (command "._-plot"  "Yes" ;Detailed plot configuration? [Yes/No] <No>: Y
	    "" ;Enter a layout name or [?] <0_01a>:
	    [color="red"]device[/color] ;Enter an output device name or [?] <DWG To PDF.pc3>: ;
[color="red"]; if device doesn't work try this (strcat "\\\jec-fpb01\\" device)?[/color]
	    "11x17" ;Enter paper size or [?] <ISO full bleed A3>:
	    "Inches" ;Enter paper units [inches/Millimeters] <Inches>:				
	    "Landscape" ;Enter drawing orientation [Por.../Lan...] <Lan...>:
	    "No" ;Plot upside down? [Yes/No] <No>:
	    "Extents" ;Enter plot area [D.../E.../L.../V.../W...] <Window>:
	    "1:1" ;Enter plot scale or [Fit] <1=1>:
	    "Center" ;Enter plot offset (x,y) or [Center] <Center>:
	    "Yes" ;Plot with plot styles? [Yes/No] <Yes>:
	    "monochrome.ctb" ;Enter plot style table name or [?] <>:
	    "Yes" ;Plot with lineweights? [Yes/No] <Yes>:
	    "No" ;Scale lineweights with plot scale? [Yes/No] <No>:
	    "No" ;Plot paper space first? [Yes/No] <No>:
	    "No" ;Hide paperspace objects? [Yes/No] <No>:
	    "No" ;Write plot to a file [Yes/No] <N>:
	    "Yes" ;Save changes to page setup [Yes/No]? <N>:
	    "No" ;Proceed with plot [Yes/No] <Y>:
	    ) ;_ end of command
;_ end of command
;command
   ) ;progn
[color="blue"]   [b] ) [/b];_ end of if[/color]
 ) ;foreach
...
...

Link to comment
Share on other sites

Guest Drafter_Joe

Hello, hanhphuc!

 

Thank you for the response and the new code!

 

Yes, wanting the option to apply a change of plotter in GOCHNGPLT if the list returned does not have the "default" plotter in it.

 

Yes, the device you have listed would be considered the "default" plotter.

 

And yes, I'm wanting to change the plotter depending on what list getplotdevices returns.

 

I'm glad you were able to understand the issues! I will give your additional code a try a little later today and let you know if it worked or not. Thank you again!

 

Joe

Link to comment
Share on other sites

Guest Drafter_Joe

Now that I have been taking a longer look at the codes of both routines, it looks like the getplotdevices routine is where the comparisons of the plot devices in each layout should be checked for my "default" plotter.

 

It would help if I knew what the getplotdevices routine does line by line. Could anyone assist in that, please?

 

(defun C:GPD (/ 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))

 

And if all the layouts use my "default" plotter, would this code previously provided by hanhphuc, be the proper code to skip calling the GOCHNGPLT routine? Does the "None" used below need to be changed to what would be my "default" plotter?

 

(foreach item (layoutlist) ;
 (if (setq device (cdr	(assoc item (vl-remove-if ''((x) (= (cdr x) "None")) (c:GOCHNGPLT))) ;_ end of assoc
		) ;_ end of cdr
    ) ;_ end of setq

 

I thank you in advance for any advice and help provided, and I appreciate your time and attention! :)

Link to comment
Share on other sites

Rather than calling PLOT Command, you could just set a named Page Setup as active for all Layouts; see this old post for reference:

 

As example, this takes +/- 1 second to apply a named Page Setup to 100 Layouts in one drawing:

 

(foreach layoutName (layoutlist)
 ([color="blue"]vla-SetActivePageSetup[/color] layoutName “[color="red"]YourPageSetupName[/color]”)
)

 

 

 

Cheers

Link to comment
Share on other sites

Guest Drafter_Joe

Thank you BlackBox!

 

I will look into your idea and the old post to see if that will work in my situation when I have a little more time.

 

I appreciate your assistance! :)

 

Joe

Link to comment
Share on other sites

 

(foreach layoutName (layoutlist)
 ([color="blue"]vla-SetActivePageSetup[/color] layoutName “[color="red"]YourPageSetupName[/color]”)
)

 

Cheers

 

Thanx for sharing sir,

but i think my version 2007 does not support _netload

 

However, this inspire me to approach VL,

im not sure does it work on OP's device?

 

quick plot function by supplying

layout device list

(vl-load-com)

(defun hp:plot!	(lst  / l i var plot sa)
http://www.cadtutor.net/forum/showthread.php?89180-Combining-2-LISP-routines
;hanhphuc 16/10/2014
 (if (and (vl-consp lst)
   hp:doc*)
   (progn (setq
     	 l (if
	     (vl-every 'vl-list-length lst )
	     (apply 'mapcar (cons 'list lst))	; Doug Wilson's transpose 
	     (mapcar ''((f) (mapcar f lst)) '(car cdr))
	     )
	 i    -1
	 plot (cadr ([color="blue"]hp:doc*[/color] "Activedocument/Plot"))
	 var  (getvar "backgroundplot")
	 sa   (vlax-make-safearray vlax-vbstring (cons 0 (1- (length (car l)))))
	 ) ;_ end of setq
   (setvar "backgroundplot" 0)
   (foreach x (car l) (vlax-safearray-put-element sa (setq i (1+ i)) x))
   (vla-setlayoutstoplot plot sa)
   (vla-plottodevice plot (nth i (cadr l)))
   (setvar "backgroundplot" var)
     	   (vlax-release-object plot)
   ) ;_ end of progn
   ) ;_ end of if
 ) ;_ end of defun


;;sub-function similar vla-get with concatenated string format "/" as delimeter
;;returns each vla-object list
(defun [color="blue"]hp:doc*[/color] (str / l lst doc n len) 
;;;hanhphuc's jobs 2014
(setq doc (vlax-get-acad-object))
(if (and str (= (type str) 'STR) (> (strlen str)2))
(progn
 (while (/= (setq len (strlen str)) 0)
   (setq n   (vl-string-search "/" str)
  l   (cons (if	n (substr str 1 n)str)l)
  str (if n (substr str (+ 2 n) (- len n))"")
     ) ;_ end of setq
   ) ;_ end of while
(foreach x  (reverse l)
(setq lst (cons (setq doc (vlax-get doc x) )lst)))
(reverse lst)
 ) ;_ end of progn
doc) ;_ end of if
) ;_ end of defun

;example: get current space 
;(setq doc ([color="blue"]hp:doc*[/color] "Activedocument/ActiveLayout/Block"))
;_$ (#<VLA-OBJECT IAcadDocument 0154a390> #<VLA-OBJECT IAcadLayout 03d84fb4> #<VLA-OBJECT IAcadPaperSpace 03d84f64>)
;(setq space (caddr doc)); #<VLA-OBJECT IAcadPaperSpace 03d84f64> 

 

command: Test , test1 , test2 , test3


(defun c:test nil (hp:plot! (vl-remove-if ''((x) (= (cdr x) "None")) [color="red"][b](c:GPD)[/b][/color])))
;note: this test must load LM's c:GPD

(defun c:test1 nil 
 (hp:plot!
   '(("Layout1" . "HP LaserJet 5200 Series PCL 5"))) ;_ end of hp:plot!
 ) ;_ end of defun

(defun c:test2 (/ device) 
 (setq device "HP LaserJet 5200 Series PCL 5")
 (hp:plot!
   (list (cons "Layout1" . device) (cons "Layout2" (strcat "\\\\jec-fpb01\\" device))); dotted list
   ) ;_ end of hp:plot!
 ) ;_ end of defun

(defun c:test3 (/ device) ; list
 (setq device "HP LaserJet 5200 Series PCL 5")
 (hp:plot!
   (list (list "Layout1" device) (list "Layout2" (strcat "\\\\jec-fpb01\\" device))); normal list
   ) ;_ end of hp:plot!
 ) ;_ end of defun

Link to comment
Share on other sites

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...