.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

9 REPLIES 9
Reply
Message 1 of 10
dahovey
3219 Views, 9 Replies

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

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()
9 REPLIES 9
Message 2 of 10
rdswords
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?
Message 3 of 10
dahovey
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" :)))
Message 4 of 10
mhawkins126
in reply to: dahovey

The program you are writing would be very useful to me, is there anyway I can get it?
Message 5 of 10
dahovey
in reply to: dahovey

Well? What are you using it for? e-mail me at
david.hovey@fitch.com
Message 6 of 10
t.willey
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
Message 7 of 10
dahovey
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.
Message 8 of 10
t.willey
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.
Message 9 of 10

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


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Innovation and R&D Lead, AtkinsRéalis

Facebook | Twitter | LinkedIn

Message 10 of 10

 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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost