- Imports SwConst
- Imports System.Drawing.Printing
- Imports SldWorks
- Imports System.IO
- Module swRelated
- Public Sub loadsw()
- ReDim SwFinalFiles(Form1.ListBox1.Items.Count - 1)
- '将列表装入数组
- For ix As Integer = 0 To SwFinalFiles.GetUpperBound(0)
- SwFinalFiles(ix) = Form1.ListBox1.Items(ix)
- Next
- If SwFinalFiles.Length <> 0 Then
- Form1.PSbar1.Maximum = SwFinalFiles.GetUpperBound(0)
- Form1.PSbar1.Minimum = 0
- swApp = New SldWorks.SldWorks
- If Form1.CboxShowSW.Checked = True Then
- swApp.Visible = True
- Else : swApp.Visible = False
- End If
- MsgBox("即将开始,建议关闭所有程序以保证足够内存")
- Dim i As Integer
- For i = 0 To SwFinalFiles.GetUpperBound(0)
- Try
- Form1.PSbar1.Value = i
- swMod = swApp.OpenDoc(SwFinalFiles(i), 3)
- swDoc = swMod
- '图片颜色变成黑白
- boolstatus = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swTiffImageType, swTiffImageType_e.swTiffImageBlackAndWhite)
- '图片分辨率设为选定值
- boolstatus = swApp.SetUserPreferenceIntegerValue(swUserPreferenceIntegerValue_e.swTiffPrintDPI, intDPI)
- '图片存放的目录全名
- intSheetCount = swDoc.GetSheetCount '文件中图纸数量
- mysheet = swDoc.GetSheetNames '图纸名称列表
- For j As Integer = 0 To intSheetCount - 1
- '获取图纸的大小尺寸
- tmpInt = swDoc.Sheet(mysheet(j).ToString).GetSize(stWidth, stHeight)
- stWidth = stWidth * 1000
- stHeight = stHeight * 1000
- If stHeight = 594 Or stHeight = 841 Then
- Form1.ListLargePapers.Items.Add(SwFinalFiles(i))
- Exit For
- End If
- If stHeight = 210 Or stHeight = 297 Then
- '选择了直接出图,并且选择的是A4和A3的图纸,
- If Form1.CBoxEnable.Checked = True Then
- '选择打印机
- swMod.Printer = Form1.cbxPtA4.SelectedItem
- '设置页面参数
- Dim a As PageSetup
- a = swMod.PageSetup
- a.HighQuality = True
- a.ScaleToFit = True
- Dim tt As Boolean
- a.DrawingColor = swPageSetupDrawingColor_e.swPageSetup_BlackAndWhite
- a.PrinterPaperSize = PaperKind.A4
- tt = a.UsePageSetupOnSheets()
- If stWidth = 297 Or stWidth = 210 Then 'A4图纸
- swMod.PrintDirect()
- End If
- If stWidth = 420 Then 'A3图纸
- swMod.PrintOut(j + 1, j + 1, 1, False, swMod.Printer, 0.67, False)
- End If
- Else
- '将图纸录入集合
- swSingleDraw = New SwDraw
- tmpSavefile = Application.StartupPath & "\OutputImage" & i.ToString & _
- mysheet(j).ToString & ".tif"
- swMod.SaveAs(tmpSavefile) '保存成jpg文件
- With swSingleDraw
- .drawDir = tmpSavefile
- .drawHeight = stHeight
- .drawWidth = stWidth
- End With
- If stWidth = 210 Then
- swSingleDraw.PaperSize = "A4"
- End If
- If stWidth = 420 Then
- swSingleDraw.PaperSize = "A3"
- End If
- End If
- End If
- '如果是A2的尺寸,处理同上。
- If stHeight = 420 Then
- '将图纸录入集合
- swSingleDraw = New SwDraw
- tmpSavefile = Application.StartupPath & "\OutputImage" & i.ToString & _
- mysheet(j).ToString & ".tif"
- swMod.SaveAs(tmpSavefile) '保存成TIF文件
- With swSingleDraw
- .drawDir = tmpSavefile
- .drawHeight = stHeight
- .drawWidth = stWidth
- End With
- If stWidth = 594 Then
- swSingleDraw.PaperSize = "A2"
- End If
- End If
- '录入完毕,图纸尺寸全部放入到了对象swSingleDraw中
- swDrawCollecton.Add(swSingleDraw)
- swDoc.SheetNext()
- Next
- swApp.CloseDoc(SwFinalFiles(i))
- swDoc = Nothing
- swMod = Nothing
- Catch ex As Exception
- End Try
- Next
-
- getA2s()
- fillPaper()
- joinPicture()
- MsgBox("successed!")
- Else : MsgBox("list not exist")
- End If
- End Sub
- End Module
复制代码 |