.NET

Reply
Valued Contributor
dahovey
Posts: 81
Registered: ‎07-27-2006
Message 1 of 10 (1,364 Views)

Batch plotting problem in VB.net (very close to success)

1364 Views, 9 Replies
09-18-2007 03:43 PM
I desparately need help...I'm working on a batch plot manager in vb.net. I found this code on the posts here and modified it to accomidate my program.

The problem is that my program will loop through the selecteditems of a listbox and I know the loop works properly...It will successfully plot each time but it plots the same drawing each time though.

I'm not exactly sure how to specify what open drawing to plot...Is it the plotsettings object, the validator. I thought is was drawing name that is passed to the BeginDocument method, but I've debuged what is passed to the method and it works properly.

The idea of my program is that the user can manually select what open drawings to plot and what settings to use.

The odd thing is that the print queue in windows shows the unique filenames of the each drawing when plotting but the same page plots each time.

Any thoughts?? Any suggestions would be greatly appreciated.



Dim i As Integer, iDocs As Integer
Dim bFound As Boolean
Dim dOrigin(0 To 1) As Double
Dim bReturnVal As Boolean
Dim acadDocument As Autodesk.AutoCAD.ApplicationServices.Document
Dim strSelectedDrawing As String
Dim strPlotFilename As String
'Dim origSDI As Boolean = Application.AcadApplication.Preferences.System.SingleDocumentMode
Dim plotInfo As PlotInfo = New PlotInfo()
Dim piValidator As PlotInfoValidator = New PlotInfoValidator()
Dim plotSet As PlotSettings
Dim plotEngine As PlotEngine = PlotFactory.CreatePublishEngine
Dim plotDialog As PlotProgressDialog = New PlotProgressDialog(False, 1, False)
Dim strListItem As String
Dim pmDrawing As pmDrawingRecord

'Change over to MDI mode to plot, then return to existing setting
Dim psValidator As PlotSettingsValidator


For Each strListItem In lstDrawings.SelectedItems

For Each pmDrawing In pmOpenDrawings
If strListItem.StartsWith(pmDrawing.strName) = True Then
Exit For
End If
Next

For Each acadDocument In acadApp.DocumentManager
If pmDrawing.strName = acadDocument.Name Then
Exit For
End If
Next

plotSet = New PlotSettings(True)

psValidator = PlotSettingsValidator.Current

'Sets the plot to model space
'MsgBox("Layouts: " & LayoutManager.Current.LayoutCount)

plotInfo.Layout = LayoutManager.Current.GetLayoutId("Model")

psValidator.SetPlotConfigurationName(plotSet, cboDeviceName.Text, cboPaperSize.Text)
'Sets the paper units
psValidator.SetPlotPaperUnits(plotSet, PlotPaperUnit.Inches)
'Set the plotter to plot landscape, upside down
psValidator.SetPlotRotation(plotSet, PlotRotation.Degrees090)
'Sets the boundaries to drawing extents
psValidator.SetPlotType(plotSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents)
'psValidator.SetPlotWindowArea(plotSet, extents1)
'Instructs AutoCAD to use a standard scale (scale to fit), not a custom scale
psValidator.SetUseStandardScale(plotSet, True)
psValidator.SetStdScaleType(plotSet, StdScaleType.ScaleToFit)
'Instructs AutoCAD not to center the plot, and use the given offset
psValidator.SetPlotCentered(plotSet, True)
'psValidator.SetPlotOrigin(plotSet, New Point2d(0.0, 0.75))
'Set the style for the plot
psValidator.SetCurrentStyleSheet(plotSet, cboPen.Text)
'Remove reference to the PlotSettingsValidator
psValidator = Nothing
plotSet.ShadePlot = PlotSettingsShadePlotType.AsDisplayed
'Plot with lineweights
plotSet.PrintLineweights = True
plotSet.ScaleLineweights = False

'Override the plot settings with our own
plotInfo.OverrideSettings = plotSet

'validate the plot info
piValidator.Validate(plotInfo)
MsgBox("Validated:" & plotInfo.IsValidated)
'pivalidator.
'Application.AcadApplication.Preferences.System.SingleDocumentMode = False

If plotEngine IsNot Nothing Then
plotDialog.IsVisible = True
plotDialog.OnBeginPlot()
plotEngine.BeginPlot(plotDialog, Nothing)
plotEngine.BeginDocument(plotInfo, pmDrawing.strName, Nothing, 1, False, Nothing)

'Dim curItem As Integer
'For curItem = 0 To lstFiles.SelectedItems.Count - 1
acadDocument.LockDocument()
Dim filename As String '= lstFiles.SelectedItems(curItem)
'Dim document As acadApp = Acad.Documents.Open((Path.Combine(Acad.ActiveDocument.Path, filename)), True)
Dim pageInfo As PlotPageInfo = New PlotPageInfo()

'Set the current layout to the model layer
LayoutManager.Current.CurrentLayout = "Model"

plotDialog.OnBeginSheet()


plotEngine.BeginPage(pageInfo, plotInfo, True, Nothing)

plotEngine.BeginGenerateGraphics(Nothing)
plotEngine.EndGenerateGraphics(Nothing)
plotEngine.EndPage(Nothing)
plotDialog.OnEndSheet()

plotEngine.EndDocument(Nothing)
plotEngine.EndPlot(Nothing)

plotDialog.OnEndPlot()

End If

plotSet.Dispose()
Next


piValidator.Dispose()
plotInfo.Dispose()
plotDialog.Dispose()
plotEngine.Dispose()
Distinguished Contributor
rdswords
Posts: 240
Registered: ‎05-15-2007
Message 2 of 10 (1,364 Views)

Re: Batch plotting problem in VB.net (very close to success)

09-20-2007 12:57 PM in reply to: dahovey
I don't know the answer to this because I do C#, not VB, but what is the difference between your utility and the publish function in AutoCAD?
Valued Contributor
dahovey
Posts: 81
Registered: ‎07-27-2006
Message 3 of 10 (1,364 Views)

Re: Batch plotting problem in VB.net (very close to success)

09-20-2007 01:03 PM in reply to: dahovey
I found the answer.
I solved it by setting the mdiactivedocument to the desired document. Appearently this is what dictates what document is plotted because now it works.

The difference between what I'm creating and publish isn't an enourmous amount of things. You can get an idea with the screen capture attached. I can click on a preset and it fills in the plotting info into the selection combo boxes (the plotting settings are not dependent on the "Page Setup" settings in the drawing)

I have a separate macro that displays a dialog much like this one that batch plots PDF's...I am very proud of this PDF plotter since it uses Adobe Acrobat 7.0, Adobe Distiller, Postscript and creates great PDF's (Sure other programs out there do this) but few are for free and can be custimized at will like having your own code.

I love programming so I'm willing to do the "work" :smileyhappy:))
Active Member
mhawkins126
Posts: 8
Registered: ‎10-01-2007
Message 4 of 10 (1,364 Views)

Re: Batch plotting problem in VB.net (very close to success)

10-01-2007 11:10 AM in reply to: dahovey
The program you are writing would be very useful to me, is there anyway I can get it?
Valued Contributor
dahovey
Posts: 81
Registered: ‎07-27-2006
Message 5 of 10 (1,364 Views)

Re: Batch plotting problem in VB.net (very close to success)

10-01-2007 11:13 AM in reply to: dahovey
Well? What are you using it for? e-mail me at
david.hovey@fitch.com
Mentor
t.willey
Posts: 2,504
Registered: ‎02-17-2004
Message 6 of 10 (1,364 Views)

Re: Batch plotting problem in VB.net (very close to success)

10-01-2007 11:59 AM in reply to: dahovey
Did you get it to work the way you wanted it to?

--

Tim
"A blind man lets nothing block his vision."


wrote in message news:5737009@discussion.autodesk.com...
Well? What are you using it for? e-mail me at
david.hovey@fitch.com
Valued Contributor
dahovey
Posts: 81
Registered: ‎07-27-2006
Message 7 of 10 (1,364 Views)

Re: Batch plotting problem in VB.net (very close to success)

10-01-2007 12:03 PM in reply to: dahovey
Yes. It needs some work to do all the things I want it to. But everything involving interfacing with AutoCAD I've got figured out. I've also been able to incorporate showing preview window before plotting to device with the help of someone at Autodesk.
Mentor
t.willey
Posts: 2,504
Registered: ‎02-17-2004
Message 8 of 10 (1,364 Views)

Re: Batch plotting problem in VB.net (very close to success)

10-01-2007 12:09 PM in reply to: dahovey
Cool. Glad to hear that.

--

Tim
"A blind man lets nothing block his vision."


wrote in message news:5737077@discussion.autodesk.com...
Yes. It needs some work to do all the things I want it to. But everything
involving interfacing with AutoCAD I've got figured out. I've also been able
to incorporate showing preview window before plotting to device with the
help of someone at Autodesk.
Member
MUSTAFA.SALAHELDIN
Posts: 5
Registered: ‎03-27-2013
Message 9 of 10 (565 Views)

Re: Batch plotting problem in VB.net (very close to success)

10-09-2013 12:12 PM in reply to: dahovey

I'm interested to get a copy of your project. I intended to convert it to c#.

ADN Support Specialist
Balaji_Ram
Posts: 735
Registered: ‎03-21-2011
Message 10 of 10 (534 Views)

Re: Batch plotting problem in VB.net (very close to success)

10-11-2013 04:25 AM in reply to: MUSTAFA.SALAHELDIN

 Hi Mustafa,

 

Does this blog post help ?

http://adndevblog.typepad.com/autocad/2012/05/named-view-plotting.html

 

You can also find many other plotting samples by searching Kean's blog, AutoCAD Devblog and The Swamp.

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!