Performing Basic Print Management Example for Visual Basic
Private Sub PerformBasicPM()
Dim objPrintSCU As New LEADDicomPrintSCU
'Set objPrintSCU = New LEADDicomPrintSCU
objPrintSCU.Timeout = 60 ' 60 seconds
objPrintSCU.EnableMethodErrors = False
' Establish the Association
Dim nRet As Integer
nRet = objPrintSCU.Associate("10.0.2.20", 7104, "PrintSCP", "PrintSCU", _
PRNSCU_BASIC_GRAYSCALE_PM_META_SOP_CLASS + _
PRNSCU_BASIC_COLOR_PM_META_SOP_CLASS + _
PRNSCU_BASIC_ANNOTATION_BOX_SOP_CLASS + _
PRNSCU_BASIC_PRINT_IMAGE_OVERLAY_BOX_SOP_CLASS + _
PRNSCU_PRESENTATION_LUT_SOP_CLASS + _
PRNSCU_PRINT_JOB_SOP_CLASS + _
PRNSCU_PRINTER_CONFIGURATION_RETRIEVAL_SOP_CLASS)
If nRet = DICOM_ERROR_PRINTSCU_ASSOCIATE_RQ_REJECTED Then
MsgBox "Source = " & objPrintSCU.AssociateRejectSource & ", " & _
"Reason = " & objPrintSCU.AssociateRejectReason, , _
"Association Request was Rejected"
Exit Sub
ElseIf nRet <> DICOM_SUCCESS Then
MsgBox "Error code: " & nRet, , "Failed to Establish the Association"
Exit Sub
End If
' Abort the Association if none of the Basic Print Management Meta SOP Classes
' is supported on the Association
If objPrintSCU.IsClassSupported(PRNSCU_BASIC_GRAYSCALE_PM_META_SOP_CLASS) = False And _
objPrintSCU.IsClassSupported (PRNSCU_BASIC_COLOR_PM_META_SOP_CLASS) = False Then
objPrintSCU.AbortAssociation
Exit Sub
End If
' Display some printer info
'GetPrinterInfo objPrintSCU
' Display some printer configuration info
'GetPrinterConfigInfo objPrintSCU
' Create a Film Session
With objPrintSCU.FilmSession
.IncludedParameters = 0
.Create
MsgBox .SOPInstanceUID, , "Film Session SOP Instance UID"
End With
' Update the Number of Copies and Print Priority of the Film Session
With objPrintSCU.FilmSession
.IncludedParameters = FS_NUMBER_OF_COPIES + FS_PRINT_PRIORITY
.NumberOfCopies = 1
.PrintPriority = "MED"
.Update
End With
With objPrintSCU.FilmBox
.IncludedParameters = 0
If .MainObject.IsClassSupported (PRNSCU_BASIC_ANNOTATION_BOX_SOP_CLASS) Then
.IncludedParameters = .IncludedParameters + FB_ANNOTATION_DISPLAY_FORMAT_ID
.AnnotationDisplayFormatID = "SomeID"
End If
' Create a Film Box
.Create
MsgBox .SOPInstanceUID, , "Film Box SOP Instance UID"
End With
Dim sPresLUTInstanceUID As String
' Create a Presentation LUT
With objPrintSCU.PresentationLUT
If .MainObject.IsClassSupported (PRNSCU_PRESENTATION_LUT_SOP_CLASS) Then
If .Create("C:\PresLUT.dic") = DICOM_SUCCESS Then
sPresLUTInstanceUID = .GetSOPInstanceUID()
MsgBox sPresLUTInstanceUID, , "Pres LUT SOP Instance UID"
End If
End If
End With
If Len(sPresLUTInstanceUID) Then
' Update the Film Box to reference the Presentation LUT we just created
With objPrintSCU.FilmBox
.IncludedParameters = FB_REF_PRES_LUT_INSTANCE_UID
.RefPresLUTInstanceUID = sPresLUTInstanceUID
.Update
End With
End If
Dim sOverlayBoxInstanceUID As String
' Create an Image Overlay Box
With objPrintSCU.ImageOverlayBox
If .MainObject.IsClassSupported (PRNSCU_BASIC_PRINT_IMAGE_OVERLAY_BOX_SOP_CLASS) Then
.OverlayOriginRow = 1
.OverlayOriginColumn = 1
.IncludedParameters = 0
If .Create("C:\Overlay.dic") = DICOM_SUCCESS Then
sOverlayBoxInstanceUID = .GetSOPInstanceUID()
MsgBox sOverlayBoxInstanceUID, , "Image Overlay Box SOP Instance UID"
End If
End If
End With
' Update the Image Box. Since the Image Display Format of the Film Box was
' set to "STANDARD\1,1", then we are supposed to have one Image Box created
' by the Print SCP.
If objPrintSCU.ImageBoxes.Count Then
With objPrintSCU.ImageBoxes(0)
MsgBox .SOPInstanceUID, , "Image Box SOP Instance UID"
.IncludedParameters = 0
If Len(sOverlayBoxInstanceUID) Then
.IncludedParameters = .IncludedParameters + IB_REF_IMAGE_OVERLAY_BOX_INSTANCE_UID
.RefImageOverlayBoxInstanceUID = sOverlayBoxInstanceUID
End If
.Update "C:\Image.dic"
End With
End If
' Update the Annotation Boxes (if there are any)
Dim AnnBox As LAnnotationBox
For Each AnnBox In objPrintSCU.AnnotationBoxes
AnnBox.TextString = "Some Text"
AnnBox.Update
Next
' Change the Overlay Origin of the Image Overlay Box referenced by the
' Image Box
If Len(sOverlayBoxInstanceUID) Then
With objPrintSCU.ImageOverlayBox
.IncludedParameters = OB_OVERLAY_ORIGIN
.OverlayOriginRow = 10
.OverlayOriginColumn = 10
.Update sOverlayBoxInstanceUID
End With
End If
Dim sPrintJobInstanceUID As String
' Print the Film Session (or the Film Box; there is no difference since we
' have a single Film Box in the Film Session)
If True Then
With objPrintSCU.FilmSession
.PrintSession
sPrintJobInstanceUID = .PrintJobSOPInstanceUID
End With
Else
With objPrintSCU.FilmBox
.PrintBox
sPrintJobInstanceUID = .PrintJobSOPInstanceUID
End With
End If
' Display some info about the Print Job
If (objPrintSCU.IsClassSupported(PRNSCU_PRINT_JOB_SOP_CLASS)) Then
'GetPrintJobInfo objPrintSCU, sPrintJobInstanceUID
End If
' Delete the Film Box (anyway, it would be deleted when the Film Session
' is deleted)
objPrintSCU.FilmBox.Delete
' Delete the Film Session
objPrintSCU.FilmSession.Delete
' Delete the Presentation LUT
If Len(sPresLUTInstanceUID) Then
objPrintSCU.PresentationLUT.Delete sPresLUTInstanceUID
End If
' Delete the Image Overlay Box
If Len(sOverlayBoxInstanceUID) Then
objPrintSCU.ImageOverlayBox.Delete sOverlayBoxInstanceUID
End If
' Release the Association and close the connection
objPrintSCU.ReleaseAssociation
End Sub