Author Topic: Updating Layout object, with plot settings  (Read 8692 times)

0 Members and 1 Guest are viewing this topic.

T.Willey

  • Needs a day job
  • Posts: 5251
Updating Layout object, with plot settings
« on: March 31, 2006, 11:51:25 AM »
Anyone know why this won't work?

To test it.  Set the current layout to a different plotter, than the second one in the plotter list, and to a different style.  I use a style that would print in color, and then the one that is assigned to the layout within the routine would print black.  It shows that the ctb file is current, but it won't recognize it.  I have look at the help files, and seen when it says you need to add RefreshPlotDevice, and where you need to add a Regen.  I have added them where I think they should be, and I even tested it with added them one of the afore mentioned methods after each call, and it still doesn't work.

Any help is appreciated.
Code: [Select]
(defun c:Test (/ AcadObj FilesObj ActLo ctbList PlotterList PaperList FitToggle *error* ActDoc)

(defun *error* (msg)

(prompt (strcat "\n Error --> " msg))
(vl-bt)
)
;-------------------------------------------------------------
(defun GetPlotters (FilesObj)

(vl-directory-files
 (vla-get-PrinterConfigPath
  FilesObj
 )
 "*.pc3"
 1
)
)
;--------------------------------------------------------------
(defun GetPlotStyles (FilesObj)

(vl-directory-files
 (vla-get-PrinterStyleSheetPath
  FilesObj
 )
 "*.ctb"
 1
)
)
;---------------------------------------------------------------
(defun GetPaperNames (Lo PlotterFile)
(vlax-invoke Lo 'RefreshPlotDeviceInfo) ; CAB

(if (/= (strcase PlotterFile) (strcase (vla-get-ConfigName Lo)))
 (vla-put-ConfigName Lo PlotterFile)
)
(vlax-invoke Lo 'RefreshPlotDeviceInfo)
(vlax-invoke Lo 'GetCanonicalMediaNames)
)
;------------------------------------------------------------------

  (setq FitToggle "1")
  (setq AcadObj (vlax-get-Acad-Object))
  (setq FilesObj (vla-get-Files (vla-get-Preferences AcadObj)))
  (setq ActLo (vla-get-ActiveLayout (vla-get-ActiveDocument AcadObj)))
  (setq ctbList (GetPlotStyles FilesObj))
  (setq PlotterList (GetPlotters FilesObj))
  (setq PaperList (GetPaperNames ActLo (nth 2 PlotterList)))

    (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
    (vla-RefreshPlotDeviceInfo ActLo)
    (vlax-put ActLo 'ConfigName (nth 2 PlotterList))
    (vlax-put ActLo 'PlotType acExtents)
    (vlax-put ActLo 'CanonicalMediaName (nth 2 PaperList))
    (vlax-put ActLo 'PlotRotation ac90degrees)
    (vlax-put ActLo 'StandardScale (if (= FitToggle "0") acVpCustomScale acVpScaleToFit))
    (vlax-invoke ActDoc 'Regen acActiveViewport)
    (vlax-put ActLo 'PlotHidden :vlax-false)
    (vlax-put ActLo 'ScaleLineweights :vlax-true)
    (if (= FitToggle "0")
     (progn
      (vlax-invoke ActLo 'SetCustomScale (/ 1.0 (rtos (last lst))))
      (vlax-invoke ActDoc 'Regen acActiveViewport)
     )
    )
    (vla-RefreshPlotDeviceInfo ActLo)
    (vlax-put ActLo 'StyleSheet (nth 2 ctbList))
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Updating Layout object, with plot settings
« Reply #1 on: March 31, 2006, 01:21:28 PM »
Tim,
I don't have an answer and can't 'play' right now, but THIS thread, and the links within it, might prove beneficial.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Updating Layout object, with plot settings
« Reply #2 on: March 31, 2006, 03:30:29 PM »
I didn't find any help in the posted link, or any link that was in that link.
Thanks for trying.

I have narrowed it down.  The problem is with assigning the ConfigName.  Once you assign that, then all is lost for some reason, no matter how may RefreshPlotDevice I put in or Regens.  I'm total lost, and frustrated.  I guess I could always go the command route, but this should work.  It works in my other batch plot routine, but when I tried to copy the same idea, it won't work.

Thanks again.  I hope this isn't a lost cause.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: Updating Layout object, with plot settings
« Reply #3 on: March 31, 2006, 04:05:12 PM »
Does it have to be lisp?

Code: [Select]
Option Explicit

Public Sub SetupAndPlot(ByRef Plotter As String, CTB As String, SIZE As String, PSCALE As String, ROT As String)
    Dim Layout As AcadLayout
    On Error GoTo Err_Control
    Set Layout = ThisDrawing.ActiveLayout
    Layout.RefreshPlotDeviceInfo
    Layout.ConfigName = Plotter    ' CALL PLOTTER
    Layout.PlotType = acExtents
    Layout.PlotRotation = ROT    ' CALL ROTATION
    Layout.StyleSheet = CTB    ' CALL CTB FILE
    Layout.PlotWithPlotStyles = True
    Layout.CanonicalMediaName = SIZE    ' CALL SIZE
    Layout.PaperUnits = acInches
    Layout.StandardScale = PSCALE    'CALL PSCALE
    Layout.ShowPlotStyles = False
    ThisDrawing.Plot.NumberOfCopies = 1
    Layout.CenterPlot = True
    Layout.ScaleLineweights = False
    Layout.PaperUnits = acInches
    Layout.RefreshPlotDeviceInfo
    ThisDrawing.Regen acAllViewports
    ZoomExtents
    Set Layout = Nothing
    ThisDrawing.Save
Exit_Here:
    Exit Sub

Err_Control:
    Select Case Err.Number
        Case "-2145320861"
            MsgBox "Unable to Save Drawing- " & Err.Description
        Case "-2145386493"
            MsgBox "Drawing is setup for Named Plot Styles." & (Chr(13)) & (Chr(13)) & "Run CONVERTPSTYLES command", vbCritical, "Change Plot Style"
        Case Else
            MsgBox "Unknown Error " & Err.Number
    End Select
End Sub

This can be called w/ lisp

(command "vbastmt" "SetupAndPlot("11x17Draft.pc3", "11X17-CHECKSET.ctb", "ANSI_B_(11.00_x_17.00_Inches)", acScaleToFit, ac90degrees)")
« Last Edit: March 31, 2006, 04:19:19 PM by CmdrDuh »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Updating Layout object, with plot settings
« Reply #4 on: March 31, 2006, 04:26:39 PM »
OK, Tim, maybe I'm not following what you are trying to end up with......I made a few minor changes (different plot device, item 6 vs 2, and added the code to actually plot) and it seems to do what I'd expect it to....:
Code: [Select]
(defun c:Test (/ AcadObj FilesObj ActLo ctbList PlotterList PaperList FitToggle *error* ActDoc)

(defun *error* (msg)

(prompt (strcat "\n Error --> " msg))
(vl-bt)
)
;-------------------------------------------------------------
(defun GetPlotters (FilesObj)

(vl-directory-files
(vla-get-PrinterConfigPath
  FilesObj
)
"*.pc3"
1
)
)
;--------------------------------------------------------------
(defun GetPlotStyles (FilesObj)

(vl-directory-files
(vla-get-PrinterStyleSheetPath
  FilesObj
)
"*.ctb"
1
)
)
;---------------------------------------------------------------
(defun GetPaperNames (Lo PlotterFile)
(vlax-invoke Lo 'RefreshPlotDeviceInfo) ; CAB

(if (/= (strcase PlotterFile) (strcase (vla-get-ConfigName Lo)))
(vla-put-ConfigName Lo PlotterFile)
)
(vlax-invoke Lo 'RefreshPlotDeviceInfo)
(vlax-invoke Lo 'GetCanonicalMediaNames)
)
;------------------------------------------------------------------

  (setq FitToggle "1")
  (setq AcadObj (vlax-get-Acad-Object))
  (setq FilesObj (vla-get-Files (vla-get-Preferences AcadObj)))
  (setq ActLo (vla-get-ActiveLayout (vla-get-ActiveDocument AcadObj)))
  (setq ctbList (GetPlotStyles FilesObj))
  (setq PlotterList (GetPlotters FilesObj))
  (setq PaperList (GetPaperNames ActLo (nth 6 PlotterList)))
 

    (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
    (vla-RefreshPlotDeviceInfo ActLo)
    (vlax-put ActLo 'ConfigName (nth 6 PlotterList))
    (vlax-put ActLo 'PlotType acExtents)
    (vlax-put ActLo 'CanonicalMediaName (nth 2 PaperList))
    (vlax-put ActLo 'PlotRotation ac90degrees)
    (vlax-put ActLo 'StandardScale (if (= FitToggle "0") acVpCustomScale acVpScaleToFit))
    (vlax-invoke ActDoc 'Regen acActiveViewport)
    (vlax-put ActLo 'PlotHidden :vlax-false)
    (vlax-put ActLo 'ScaleLineweights :vlax-true)
    (if (= FitToggle "0")
     (progn
      (vlax-invoke ActLo 'SetCustomScale (/ 1.0 (rtos (last lst))))
      (vlax-invoke ActDoc 'Regen acActiveViewport)
     )
    )
    (vla-RefreshPlotDeviceInfo ActLo)
    (vlax-put ActLo 'StyleSheet (nth 2 ctbList));also used 0 and it went from b/w to color
  (vla-RefreshPlotDeviceInfo ActLo)
  (vla-plottodevice (vla-get-plot actdoc))
  (princ)
)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Updating Layout object, with plot settings
« Reply #5 on: March 31, 2006, 04:55:15 PM »
Does it have to be lisp?

This can be called w/ lisp

(command "vbastmt" "SetupAndPlot("11x17Draft.pc3", "11X17-CHECKSET.ctb", "ANSI_B_(11.00_x_17.00_Inches)", acScaleToFit, ac90degrees)")
If I knew anything about VBA, then I would use yours, so that I could up keep it, but since I don't know anything about VBA, I would rather stick with lisp.  Maybe I will study your code when I have some free time, and see if I can understand it.
Thanks for sharing.

OK, Tim, maybe I'm not following what you are trying to end up with......I made a few minor changes (different plot device, item 6 vs 2, and added the code to actually plot) and it seems to do what I'd expect it to....:
The problem that I am seeing here, is that when you plot it, the ctb file won't be used.  It will used whatever was associated to that layout when you opened the drawing.  Attached is the before, and after.  Notice that they look the same, but the second one should be black and white, not all the colors.

Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Updating Layout object, with plot settings
« Reply #6 on: March 31, 2006, 05:45:49 PM »
The problem that I am seeing here, is that when you plot it, the ctb file won't be used.  It will used whatever was associated to that layout when you opened the drawing.  Attached is the before, and after.  Notice that they look the same, but the second one should be black and white, not all the colors.
OK, that's what i thought you were saying.....but when I tested the version I posted in R2002 it used whatever I wanted it to.......I'll go try it in R2006.....yep, works as desired there, too.

These were both created by the lisp I posted from the same drawing that I opened with another plotter as the default. The only change in the lisp I made between the 2 was to change the # of the ctb file in the list to use for 2 to 3.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Updating Layout object, with plot settings
« Reply #7 on: March 31, 2006, 06:49:30 PM »
That is wierd.  I tried yours here, change the numbers because they weren't working with my setup, and the same results happened as with my code.  I'm A2k4, and a Win2000 box (not my choice).  I hope this isn't just me.

Thanks for trying, I don't understand what is happening, unless it is version specific.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Updating Layout object, with plot settings
« Reply #8 on: March 31, 2006, 09:56:49 PM »
It is quite strange, but I have heard of this before (I thought that link I gave before covered it, but I guess not). I tested with both R2002 & R2006 on WinXP Home

Chuck Gabriel

  • Guest
Re: Updating Layout object, with plot settings
« Reply #9 on: April 01, 2006, 11:35:29 AM »
This sounds like the same problem Danny is having.  Am I right Jeff?

The fact that it works fine for you and me makes me think this must be a configuration issue.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Updating Layout object, with plot settings
« Reply #10 on: April 01, 2006, 02:13:36 PM »
Yes, Chuck. That's what I thought. But I'm stumped as to what config seting(s) would affect this.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Updating Layout object, with plot settings
« Reply #11 on: April 03, 2006, 12:03:04 PM »
I have had other problems, where others have not.  My setup here is a network license (don't know if that matters either).  I will see what I can come up with.

Thanks for the help, and letting me know that I'm the only crazy one here.   :ugly:
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Chuck Gabriel

  • Guest
Re: Updating Layout object, with plot settings
« Reply #12 on: April 03, 2006, 12:43:20 PM »
Could you post a screen shot showing what options you have selected in the properties dialog, on the "Plotting" tab?

I have experimented briefly with changing some settings that I thought could be responsible, but I haven't had any luck reproducing the problem.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Updating Layout object, with plot settings
« Reply #13 on: April 03, 2006, 12:57:44 PM »
Sure.  Let me know if there is anything else I can do to help you slove this.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Chuck Gabriel

  • Guest
Re: Updating Layout object, with plot settings
« Reply #14 on: April 03, 2006, 10:04:24 PM »
I have now reproduced the problem, but I can't figure out how to stop reproducing the problem. :-(  Ugh.

I'm too tired to mess with it any more right now, but I'll try again as time permits.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Updating Layout object, with plot settings
« Reply #15 on: April 04, 2006, 11:08:28 AM »
Thanks for the help Chuck.  If there is any idea you want me to try, or to run with, just let me know.  I appreciate all the help.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Chuck Gabriel

  • Guest
Re: Updating Layout object, with plot settings
« Reply #16 on: April 04, 2006, 12:28:00 PM »
In retrospect, I'm not sure the problem I had last night is the same problem you are having, but here goes anyway.

The problem (as I saw it) was that my lineweights didn't look right (they were all the same).  I was able to get color vs. monochrome as long as I selected a plotter that supported color.

Here is the test rig I used (modified from your and Jeff's posts):

Code: [Select]
(defun c:Test (/    AcadObj     FilesObj    ActLo
       PlotterList Plotter     PaperList   PaperSize
       ctbList    ctbFile     FitToggle   *error*
       ActDoc
      )

  (defun *error* (msg)
    (prompt (strcat "\n Error --> " msg))
    (vl-bt)
  )
;;;------------------------------------------------------------------
  (defun SelectFromList (msg alist / index choice)
    (setq index 0)
    (foreach item alist
      (terpri)
      (princ index)
      (princ (strcat "\t" item))
      (setq index (1+ index))
    )
    (princ (strcat "\n" "\n" msg))
    (initget (logior 1 4))
    (setq choice (getint))
    (nth choice alist)
  )
;;;------------------------------------------------------------------
  (setq FitToggle 1
AcadObj   (vlax-get-Acad-Object)
ActDoc   (vla-get-ActiveDocument (vlax-get-Acad-Object))
ActLo   (vla-get-ActiveLayout ActDoc)
  )
  (vla-RefreshPlotDeviceInfo ActLo)
  (setq PlotterList (vlax-invoke ActLo 'GetPlotDeviceNames)
Plotter     (SelectFromList
      "Choose the number of the plotter you wish to use: "
      PlotterList
    )
  )
  (vla-put-ConfigName ActLo Plotter)

  (setq PaperList (vlax-invoke ActLo 'GetCanonicalMediaNames)
PaperSize (SelectFromList
    "Choose the number of the paper size you wish to use: "
    PaperList
  )
  )
  (vla-put-CanonicalMediaName ActLo PaperSize)

  (setq ctbList (vlax-invoke ActLo 'GetPlotStyleTableNames)
ctbFile (SelectFromList
  "Choose the number of the style sheet you wish to use: "
  ctbList
)
  )
  (vla-put-StyleSheet ActLo ctbFile)

  (vla-put-PlotType ActLo acExtents)
  (vla-put-PlotRotation ActLo ac90degrees)
  (if (zerop FitToggle)
    (progn
      (vla-put-StandardScale ActLo acVpCustomScale)
      (vla-SetCustomScale ActLo (/ 1.0 (rtos (last lst))))
    )
    (vla-put-StandardScale ActLo acVpScaleToFit)
  )
  (vla-put-PlotHidden ActLo :vlax-false)
  (vla-put-ScaleLineweights ActLo :vlax-false)
  (vla-put-ShowPlotStyles ActLo :vlax-true)
  (vla-put-PlotWithLineweights ActLo :vlax-true)
  (vla-Regen ActDoc acActiveViewport)
  (vla-DisplayPlotPreview (vla-get-plot ActDoc) acFullPreview)
  (princ)
)

Note that I only called RefreshPlotDeviceInfo once.  According to the docs, that's all you need.

What it took to get my lineweights to print properly was to set ScaleLineweights to false.

I hope that helps, but if that isn't the problem you are having, maybe it will help someone else.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Updating Layout object, with plot settings
« Reply #17 on: April 04, 2006, 12:38:17 PM »
This got me closer, but it is still showing the preview with the wrong ctb file.  It shows the right one in the dialog box, but it won't print/preview with that one.  It will print/preview with the one assigned to the drawing prior to the command being called.

Thanks for trying.  This is so frustrating.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Updating Layout object, with plot settings
« Reply #18 on: April 05, 2006, 12:02:54 PM »
Since I/we couldn't get this to work on MY system, I just went the command route, and it seems to work.  Thanks for all the effort, and letting me know that I was coding right, it's just my setup here doesn't like it for some reason.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.