Author Topic: Layout Cutter  (Read 2484 times)

0 Members and 1 Guest are viewing this topic.

ChrisCarlson

  • Guest
Layout Cutter
« on: October 24, 2014, 11:43:54 AM »
Lee' I'm using your layout cutter routine you wrote eons ago.

http://www.cadtutor.net/forum/showthread.php?60158-Lisp-to-create-tabs-from-Selection-Window&p=408267&viewfull=1#post408267


I understand what the routine does but I can't seem to understand how it's changing the applied page setups. For instance I have a layout tab with page setup to my plotter, 30" x 42", 1:1 with extents. When I make a layout the new tab is set to DWG to PDF.pc3, 30" x 42", Fit to Page with layout view. I think this might be the default page setup for the DWG file, easy peasy. However something is changing the page setup of the source layout tab. I'm not even sure how to trouble shoot to see what is modifying it?

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Layout Cutter
« Reply #1 on: October 24, 2014, 12:50:08 PM »
I can only think there is perhaps a bug with the ActiveX copyfrom method - try the following code instead:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:layoutcutter ( / cnt doc idx lay lst new prf psp sel str tmp )
  2.     (setq prf "Layout"
  3.           psp (= 1 (getvar 'cvport))
  4.     )
  5.     (if (setq sel (ssget "_:L" (list (if psp (cons 410 (getvar 'ctab)) '(410 . "Model")))))
  6.         (progn
  7.                   lay (vla-get-activelayout doc)
  8.                   tmp (mapcar 'strcase (cons "model" (layoutlist)))
  9.                   cnt 0
  10.             )
  11.             (while (member (strcase (setq str (strcat prf (itoa (setq cnt (1+ cnt)))))) tmp))
  12.             (setq new (vla-add (vla-get-layouts doc) str))
  13.             (repeat (setq idx (sslength sel))
  14.                 (setq lst (cons (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))) lst))
  15.             )
  16.             (vlax-invoke doc 'copyobjects
  17.                 (if psp (cons (vla-item (vla-get-block lay) 0) (reverse lst)) (reverse lst))
  18.                 (vla-get-block new)
  19.             )
  20.             (foreach obj lst (vla-delete obj))
  21.             (if psp
  22.                 (foreach prp
  23.                    '(
  24.                         PlotType
  25.                         PlotHidden
  26.                         PlotOrigin
  27.                         PlotRotation
  28.                         PlotViewportBorders
  29.                         PlotViewportsFirst
  30.                         PlotWithLineweights
  31.                         PlotWithPlotStyles
  32.                         ScaleLineweights
  33.                         ShowPlotStyles
  34.                         StandardScale
  35.                         StyleSheet
  36.                         UseStandardScale
  37.                         CanonicalMediaName
  38.                         CenterPlot
  39.                         ConfigName
  40.                         PaperUnits
  41.                     )
  42.                     (vl-catch-all-apply 'vlax-put-property (list new prp (vlax-get-property lay prp)))
  43.                 )
  44.             )
  45.         )
  46.     )
  47.     (princ)
  48. )
« Last Edit: October 24, 2014, 06:21:01 PM by Lee Mac »

ChrisCarlson

  • Guest
Re: Layout Cutter
« Reply #2 on: October 24, 2014, 02:07:17 PM »
Errors out on an automation error, not sure you can pull CanonicalMediaName from vlax-get-property?

Switching

Code - Auto/Visual Lisp: [Select]

to

Code - Auto/Visual Lisp: [Select]
  1. ((strcat(vla-put-(prp))) new (strcat(vla-get-(prp))) lay)

bad function:PLOTTYPE, I don't think I'm creating the vla-put correctly though.


//EDit...

Wait, that's not the issue. Just need to rearrange the prp I believe.
« Last Edit: October 24, 2014, 02:23:18 PM by ChrisCarlson »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Layout Cutter
« Reply #3 on: October 24, 2014, 06:21:11 PM »
Code updated above.

ChrisCarlson

  • Guest
Re: Layout Cutter
« Reply #4 on: October 27, 2014, 08:08:28 AM »
Thanks for the update, so I see the differences between the two versions but have a few general questions.

vl-catch-all-apply sounds like an if statement where if the property can be applied, apply it but it differs where when an error occurs it continues processing the remaining properties? What happens to the error statements?

I also see the CanonicalMediaName was moved further down the list, how did you determine where it goes, simple trial and error?


Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Layout Cutter
« Reply #5 on: October 27, 2014, 08:16:29 AM »
vl-catch-all-apply sounds like an if statement where if the property can be applied, apply it but it differs where when an error occurs it continues processing the remaining properties? What happens to the error statements?

vl-catch-all-apply is equivalent to the AutoLISP apply function, but will catch any exceptions without crashing the program and ceasing evaluation. Therefore, this expression will attempt to apply the vlax-put-property function to the list of arguments (i.e. attempt to set the relevant ActiveX property), without crashing the code should a property fail to be set. This is not an ideal solution but more of a 'sledgehammer' approach as some might say, since we are not actually resolving the error, but just ignoring those properties which fail.

The code is not currently using the error object returned, but the error message could be output to the user if necessary.

I also see the CanonicalMediaName was moved further down the list, how did you determine where it goes, simple trial and error?

I simply moved the properties pertaining to the plot itself to the top of the list, as other properties will depend on these plot properties (e.g. CenterPlot depends on PlotType etc.).