Printing without using DicomPrint

Before the DicomPrint object was added to DicomObjects, it was necessary to do DICOM printing using a DicomConneciton object, and direct use of normalised operations. Since the addition (many years ago!) of the DicomPrint object, this is not normally necessary, but for those with specialised needs, or you wish to keep it asynchronous, it does have a use.

The code below gives a starting point for those wishing to do this themselves

   Dim cn As DicomConnection
   Dim cx As DicomContexts
   Dim Printer As DicomDataSet
   Dim ims As DicomImages
   Dim Thisim As DicomImage
   Dim BFSUID As String, FilmboxUID As String
   Dim ImageBoxList As DicomDataSets
   Dim Session As DicomDataSet
   Dim Filmbox As DicomDataSet
   Dim RefSessionItem As DicomDataSet
   Dim RefSessionSequence As DicomDataSets
   Dim ImageSequenceHolder As DicomDataSet
   Dim ImageSequence As DicomDataSets
   Dim NullDataSet As DicomDataSet
   Dim imno As Integer, imnofilm As Integer
   
   ' This example uses explicit UIDs for objects created.
   ' This should not be necessary, as the SCP should create the item itself
   ' if necessary, but it
   
   ' a) Shows how to use an image object to create UIDs
   ' b) Keeps the AGFA validation tool happy ! 
   
   Dim uidimage As New DicomImage
   Dim uidroot As String, uidint As Integer
   uidint = 0
   uidroot = uidimage.InstanceUID & "."
   
   Set cn = DICOM_Demonstration.Viewer.New("dicomconnection")
   Set ims = DICOM_Demonstration.Viewer.Images
   
   Set cx = cn.Contexts
   cx.Add doMeta_BasicGrayscalePrint
   Dim ts(3) As String
   ts(1) = doTS_ImplicitVRLittleEndian
   ts(2) = doTS_ExplicitVRLittleEndian
   ts(3) = doTS_ExplicitVRBigEndian
   cx(1).OfferedTS = ts
   
   cn.SetDestination OptionsBox.PrintNode, OptionsBox.PrintPort, OptionsBox.PrintCallingAE, OptionsBox.PrintAE
   cn.MetaSOPClass = doMeta_BasicGrayscalePrint
   cn.Wait
   
   ' Get the printer object (though you don't actually use it !)
   Set Printer = New DicomDataSet
   cn.NGet doSOP_Printer, doInstance_Printer, Printer
   cn.Wait
   
   ' Create a film session
   Set Session = New DicomDataSet
   Session.Attributes.Add &H2000, &H10, 1 ' copies
   uidint = uidint + 1
   cn.NCreate doSOP_BasicFilmSession, uidroot & uidint, Session

   cn.Wait
   BFSUID = cn.LastInstanceUID
   
   imno = 1
   Do While imno <= ims.Count
        imnofilm = 1
        'Create a film box
        Set Filmbox = New DicomDataSet
        Set RefSessionItem = New DicomDataSet
        Set RefSessionSequence = New DicomDataSets
        
        Filmbox.Attributes.Add &H2010, &H10, OptionsBox.PrintFormat
        Filmbox.Attributes.Add &H2010, &H40, OptionsBox.PrintOrientation
        Filmbox.Attributes.Add &H2010, &H50, OptionsBox.FilmSize
        Filmbox.Attributes.Add &H2010, &H60, OptionsBox.Magnification
        Filmbox.Attributes.Add &H2010, &H100, "BLACK"
        Filmbox.Attributes.Add &H2010, &H110, "BLACK"
        Filmbox.Attributes.Add &H2010, &H120, 6
        Filmbox.Attributes.Add &H2010, &H130, 241
        Filmbox.Attributes.Add &H2010, &H140, "NO"
        RefSessionItem.Attributes.Add 8, &H1150, doSOP_BasicFilmSession
        RefSessionItem.Attributes.Add 8, &H1155, BFSUID
        RefSessionSequence.Add RefSessionItem
        Filmbox.Attributes.Add &H2010, &H500, RefSessionSequence
        uidint = uidint + 1
        cn.NCreate doSOP_BasicFilmBox, uidroot & uidint, Filmbox
        
        cn.Wait
        FilmboxUID = cn.LastInstanceUID
        
        Set ImageBoxList = cn.ReturnedDataSet.Attributes(&H2010, &H510).Value
        
        Do While imno <= ims.Count And imnofilm <= ImageBoxList.Count
           Set Thisim = ims(imno)
           If OptionsBox.Capture Then
               Thisim.StretchToFit = False
               Thisim.Zoom = 1
               Set Thisim = Thisim.Capture(True)
           End If
           
           'Fill the image boxes
           Set ImageSequenceHolder = New DicomDataSet
           Set ImageSequence = New DicomDataSets
           ImageSequenceHolder.Attributes.Add &H2020, &H10, imnofilm
       
           ImageSequence.Add Thisim ' yes, a DicomImage MAY be added to a DicomDatasets collection
           ImageSequenceHolder.Attributes.Add &H2020, &H110, ImageSequence
           
           cn.NSet doSOP_BasicGrayscaleImageBox, ImageBoxList(imnofilm).Attributes(8, &H1155), ImageSequenceHolder
           cn.Wait
           
           imno = imno + 1
           imnofilm = imnofilm + 1
        Loop
        
        Set NullDataSet = New DicomDataSet
        cn.NAction doSOP_BasicFilmBox, FilmboxUID, 1, NullDataSet
        cn.Wait
        
        cn.NDelete doSOP_BasicFilmBox, FilmboxUID
        cn.Wait
   Loop
   
   cn.Close
Relevance: