El ordenador donde se vaya a ejecutar el programa ha de tener Solid Edge instalado. En este caso, las pruebas se han hecho para Solid Edge ST4.
Primero hay que agregar las siguientes referencias, que se pueden coger de la carpeta donde se haya instalado Solid Edge.
Además, en este código se inserta un cajetín de texto donde introducir a voluntad lo que queramos.
También se indica la impresora donde imprimir.
VBRUN.dll
Interop.SolidEdgeConstants.dll
SolidEdgeFramework.dll
SolidEdgeFrameworkSupport.dll
Interop.VBA.dll
Luego, el código es el siguiente:
On Error Resume Next
objApp = GetObject(, "SolidEdge.Application")
If Err.Number Then
‘ Solid Edge is not running. Clear the previous error.
Err.Clear()
‘ Start Solid Edge.
objApp = CreateObject("SolidEdge.Application")
‘ Cannot start Solid Edge, so exit the program.
If Err.Number Then
MsgBox("Cannot start Solid Edge.", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Open & Save")
End
End If
‘ Make Solid Edge visible.
objApp.Visible = True
End If
On Error Resume Next
‘ Open the document.
objDoc = Nothing
objDoc = objApp.Documents.Open(rutadeldocumento)
Dim objSheet As Object
Dim objTextBoxes As Object
Dim X1 As Double, X2 As Double
Dim Y1 As Double, Y2 As Double
Dim objTextBox1 As Object
Dim objTextEdit As Object
Dim seTextSelectRange As String
‘Make sure the active environment is Draft.
‘Reference the active sheet.
objSheet = objApp.ActiveDocument.ActiveSheet
‘Reference the Sheet object.
‘Reference the TextBoxes collection.
objTextBoxes = objApp.ActiveDocument.ActiveSheet.TextBoxes
‘Use the AddByTwoPoints method to create a text box.
‘The points are defined by the X1, Y1, X2, Y2 variables.
‘The z values of the point are defined as zero.
X1 = 0 : Y1 = 0
X2 = 30 : Y2 = 0.007
objTextBox1 = objTextBoxes.AddByTwoPoints _
(X1, Y1, 0, X2, Y2, 0)
‘Place the text in the text box.
objTextBox1.Text = textodelcajetin
‘Reference the new TextEdit object.
objTextEdit = objTextBox1.Edit
‘Bold the word "TextBox."
‘First, select the range of characters in the editor. El tamaño va en pulgadas, no en el tamaño de fuente que estamos acostumbrados.
objTextEdit.TextSize = 0.003
‘Then set the bold flag.
objTextEdit.Bold = True
‘ Set a default, so response for unhandled cases is consistent. Aquí indicamos DINA4 como predeterminado.
lPaperSize = VBRUN.PrinterObjectConstants.vbPRPSA4
lPaperOrient = VBRUN.PrinterObjectConstants.vbPRORLandscape
‘ Determine the size of the sheet.
Select Case objDoc.ActiveSheet.SheetSetup.SheetSizeOption
Case SolidEdgeConstants.PaperSizeConstants.igIsoA3Tall
lPaperSize = VBRUN.PrinterObjectConstants.vbPRPSA3
lPaperOrient = VBRUN.PrinterObjectConstants.vbPRORPortrait
Case SolidEdgeConstants.PaperSizeConstants.igIsoA3Wide
lPaperSize = VBRUN.PrinterObjectConstants.vbPRPSA3
lPaperOrient = VBRUN.PrinterObjectConstants.vbPRORLandscape
Case SolidEdgeConstants.PaperSizeConstants.igIsoA4Tall
lPaperSize = VBRUN.PrinterObjectConstants.vbPRPSA4
lPaperOrient = VBRUN.PrinterObjectConstants.vbPRORPortrait
Case SolidEdgeConstants.PaperSizeConstants.igIsoA4Wide
lPaperSize = VBRUN.PrinterObjectConstants.vbPRPSA4
lPaperOrient = VBRUN.PrinterObjectConstants.vbPRORLandscape
Case SolidEdgeConstants.PaperSizeConstants.igAnsiBWide
lPaperSize = VBRUN.PrinterObjectConstants.vbPRPS11x17
lPaperOrient = VBRUN.PrinterObjectConstants.vbPRORLandscape
Case SolidEdgeConstants.PaperSizeConstants.igAnsiBTall
lPaperSize = VBRUN.PrinterObjectConstants.vbPRPS11x17
lPaperOrient = VBRUN.PrinterObjectConstants.vbPRORPortrait
Case SolidEdgeConstants.PaperSizeConstants.igAnsiAWide
lPaperSize = VBRUN.PrinterObjectConstants.vbPRPSLetter
lPaperOrient = VBRUN.PrinterObjectConstants.vbPRORLandscape
Case SolidEdgeConstants.PaperSizeConstants.igAnsiATall
lPaperSize = VBRUN.PrinterObjectConstants.vbPRPSLetter
lPaperOrient = VBRUN.PrinterObjectConstants.vbPRORPortrait
Case SolidEdgeConstants.PaperSizeConstants.igAnsiDWide
lPaperSize = VBRUN.PrinterObjectConstants.vbPRPS11x17
lPaperOrient = VBRUN.PrinterObjectConstants.vbPRORLandscape
Case SolidEdgeConstants.PaperSizeConstants.igAnsiDTall
lPaperSize = VBRUN.PrinterObjectConstants.vbPRPS11x17
lPaperOrient = VBRUN.PrinterObjectConstants.vbPRORPortrait
End Select
On Error GoTo 0
‘El parámetro PrintRange:=2 es para que imprima sólo la primera hoja del plano.
objDoc.PrintOut(Printer:=nombredeimpresora, Orientation:=lPaperOrient, ColorAsBlack:=True, PaperSize:=lPaperSize, Scale:=1.0#, PrintRange:=2)
‘Cierra el plano sin guardar.
objDoc.Close(False)
objApp.quit()
objDoc = Nothing
‘ Give the application time to process the document closure
objApp.DoIdle()