Print function freezes for a couple of minutes

Print function freezes for a couple of minutes

snappyjazz
Collaborator Collaborator
358 Views
3 Replies
Message 1 of 4

Print function freezes for a couple of minutes

snappyjazz
Collaborator
Collaborator

Hello,

I made the following print function. It works fine on my computer, but it freezes for a few minutes on another user's computer. I put dialog boxes in there so we would know which step locks it up, and the 11th one is the last one we see until it unfreezes. This means "Printr.SubmitPrint()" is the culprit. Both of us can manually print (using the same settings as in the code) and it prints fine. Has anyone had an issue like this? What was your resolution?

 

PS-Just checking; in AutoCAD there's a print in the background setting, is there an equivalent in Inventor? 

 

#Region " Btn_Print_C_BestFit_OnExecute"
        Private Sub Btn_Print_C_BestFit_OnExecute(Context As Inv.NameValueMap) Handles Btn_Print_C_BestFit.OnExecute
MsgBox("1" & vbNewLine & "Started!", MsgBoxStyle.Information, "Debugging Info")

            ' Get the active document
            Dim DrwDoc As Inv.DrawingDocument            
            ' Exit if the active document isn't a drawing
            Try : DrwDoc = g_InvApp.ActiveDocument : MsgBox("2" & vbNewLine & "Got the Drawing Document.", MsgBoxStyle.Information, "Debugging Info") : Catch ex As Exception : MsgBox("This isn't a drawing document", MsgBoxStyle.Information, "Document warning") : Exit Sub : End Try


            ' Setup an empty Print Manager (printer) for the drawing
            Dim Printr As Inv.DrawingPrintManager = DrwDoc.PrintManager
            MsgBox("3" & vbNewLine & "Made a Printer Manager.", MsgBoxStyle.Information, "Debugging Info")

            ' Set the printer
            Printr.Printer = g_Plotter_DD
            MsgBox("4" & vbNewLine & "Set our plotter as the destination.", MsgBoxStyle.Information, "Debugging Info")

            'orientation
            If DrwDoc.ActiveSheet.Width > DrwDoc.ActiveSheet.Height Then : Printr.Orientation = Inv.PrintOrientationEnum.kLandscapeOrientation
            Else : Printr.Orientation = Inv.PrintOrientationEnum.kPortraitOrientation
            End If
            MsgBox("5" & vbNewLine & "Set the drawing orientation.", MsgBoxStyle.Information, "Debugging Info")

            ' Set paper size
            'Printr.PaperSize = Inv.PaperSizeEnum.kPaperSizeCSheet
            Printr.PaperSize = Inv.PaperSizeEnum.kPaperSizeCustom
            Printr.PaperWidth = SheetSize.Arch.C.Width_cm
            Printr.PaperHeight = SheetSize.Arch.C.Height_cm
            MsgBox("6" & vbNewLine & "Set the Paper Size, Width, and Height.", MsgBoxStyle.Information, "Debugging Info")

            ' Set number of copies
            Printr.NumberOfCopies = 1
            MsgBox("7" & vbNewLine & "Set the # of copies.", MsgBoxStyle.Information, "Debugging Info")

            ' Set Print Range
            Printr.PrintRange = Inv.PrintRangeEnum.kPrintCurrentSheet
            MsgBox("8" & vbNewLine & "Set the current sheet as the print range.", MsgBoxStyle.Information, "Debugging Info")

            ' Rotate 90 deg
            Printr.Rotate90Degrees = True
            MsgBox("9" & vbNewLine & "Set to rotate the sheet 90 deg.", MsgBoxStyle.Information, "Debugging Info")

            ' Set the source
            Printr.PaperSource = 1
            MsgBox("10" & vbNewLine & "Printing to paper source 1.", MsgBoxStyle.Information, "Debugging Info")

            ' Set Scale
            'Printr.Scale = 0.125
            Printr.ScaleMode = Inv.PrintScaleModeEnum.kPrintBestFitScale
            MsgBox("11" & vbNewLine & "Set the plot scale.", MsgBoxStyle.Information, "Debugging Info")

            ' Send to printer
            Printr.SubmitPrint()
            MsgBox("12" & vbNewLine & "Submitted plot to the plotter." & vbNewLine & "END OF PRINT COMMAND", MsgBoxStyle.Information, "Debugging Info")

        End Sub
#End Region

If I'm missing any code or info please ask. My brain is frazzled!

0 Likes
359 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @snappyjazz.  The main things that stand out to me in your code are the two terms that I do not recognize "SheetSize.Arch.C.Width_cm" & "SheetSize.Arch.C.Height_cm".  What are those?  I initially suspected that they might be the unquoted names of local UserParameters, but your code appears to be for something like a Windows Form Button type event handler, which would be external and not work, so that is not a correct assumption.  Then I thought that maybe 'SheetSize' may be a custom Class or Interface type object that you created within your project's referenced code somewhere, but I just don't know.

You might have better luck using something like a Logger.Info() type lines, instead of the MsgBox() type lines as feedback, because normal messages are not always a good choice within event handler type codes.  Does the delay seem random, or is it every time for that other user?

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

snappyjazz
Collaborator
Collaborator

@WCrihfield Thank you for responding. Unfortunately the delay is every time for the other user. You're close about this being a button event handler; it is an event for a button I added to the ribbon. You're correct about SheetSize being a custom class. I created it so its easy to understand the code. See below for the class breakdown.

 

PS-Thanks for the tip about Logger.Info(). I'm not familiar with it but will look in to it. The MsgBox's were for debugging purposes only and will be deleted. 

 

 

#Region " SheetSize | Public Class"
    Public Class SheetSize
        Shared Function Arch() As ArchSheet : Dim ArchSht As New ArchSheet : Return ArchSht : End Function
        Shared Function Ansi() As AnsiSheet : Dim AnsiSht As New AnsiSheet : Return AnsiSht : End Function
    End Class
#End Region

#Region " AnsiSheet | Public Class"
    Public Class AnsiSheet
        Private _SizeObj As New SizeObject

        Public Function GetSizes(ByVal SheetSize As String) As SizeObject
            Select Case SheetSize
                Case "A"
                    _SizeObj.Width_cm = 27.94 'cm
                    _SizeObj.Height_cm = 21.59 'cm
                    _SizeObj.Width_in = 11 'in
                    _SizeObj.Height_in = 8.5 'in
                    Return _SizeObj
                Case "B"
                    _SizeObj.Width_cm = 43.18 'cm
                    _SizeObj.Height_cm = 27.94 'cm
                    _SizeObj.Width_in = 17 'in
                    _SizeObj.Height_in = 11 'in
                    Return _SizeObj
                Case "C"
                    _SizeObj.Width_cm = 55.88 'cm
                    _SizeObj.Height_cm = 43.18 'cm
                    _SizeObj.Width_in = 22 'in
                    _SizeObj.Height_in = 17 'in
                    Return _SizeObj
                Case "D"
                    _SizeObj.Width_cm = 86.36 'cm
                    _SizeObj.Height_cm = 55.88 'cm
                    _SizeObj.Width_in = 34 'in
                    _SizeObj.Height_in = 22 'in
                    Return _SizeObj
                Case "E"
                    _SizeObj.Width_cm = 111.76 'cm
                    _SizeObj.Height_cm = 86.36 'cm
                    _SizeObj.Width_in = 44 'in
                    _SizeObj.Height_in = 34 'in
                    Return _SizeObj
            End Select
        End Function
        Public ReadOnly Property A() As SizeObject
            Get
                _SizeObj = GetSizes("A")
                Return _SizeObj
            End Get
        End Property
        Public ReadOnly Property B As SizeObject
            Get
                _SizeObj = GetSizes("B")
                Return _SizeObj
            End Get
        End Property
        Public ReadOnly Property C As SizeObject
            Get
                _SizeObj = GetSizes("C")
                Return _SizeObj
            End Get
        End Property
        Public ReadOnly Property D As SizeObject
            Get
                _SizeObj = GetSizes("D")
                Return _SizeObj
            End Get
        End Property
        Public ReadOnly Property E As SizeObject
            Get
                _SizeObj = GetSizes("E")
                Return _SizeObj
            End Get
        End Property
    End Class
#End Region

#Region " ArchSheet | Public Class"
    Public Class ArchSheet
        Private _SizeObj As New SizeObject

        Public Function GetSizes(ByVal SheetSize As String) As SizeObject
            Select Case SheetSize
                Case "A"
                    _SizeObj.Width_cm = 30.48 'cm
                    _SizeObj.Height_cm = 22.86 'cm
                    _SizeObj.Width_in = 12.0 'in
                    _SizeObj.Height_in = 9.0 'in
                    Return _SizeObj
                Case "B"
                    _SizeObj.Width_cm = 45.72 'cm
                    _SizeObj.Height_cm = 30.48 'cm
                    _SizeObj.Width_in = 18.0 'in
                    _SizeObj.Height_in = 12.0 'in
                    Return _SizeObj
                Case "C"
                    _SizeObj.Width_cm = 60.96 'cm
                    _SizeObj.Height_cm = 45.72 'cm
                    _SizeObj.Width_in = 24.0 'in
                    _SizeObj.Height_in = 18.0 'in
                    Return _SizeObj
                Case "D"
                    _SizeObj.Width_cm = 91.44 'cm
                    _SizeObj.Height_cm = 60.96 'cm
                    _SizeObj.Width_in = 36.0 'in
                    _SizeObj.Height_in = 24.0 'in
                    Return _SizeObj
                Case "E"
                    _SizeObj.Width_cm = 121.92 'cm
                    _SizeObj.Height_cm = 91.44 'cm
                    _SizeObj.Width_in = 48.0 'in
                    _SizeObj.Height_in = 36.0 'in
                    Return _SizeObj
            End Select
        End Function
        Public ReadOnly Property A As SizeObject
            Get
                _SizeObj = GetSizes("A")
                Return _SizeObj
            End Get
        End Property
        Public ReadOnly Property B As SizeObject
            Get
                _SizeObj = GetSizes("B")
                Return _SizeObj
            End Get
        End Property
        Public ReadOnly Property C As SizeObject
            Get
                _SizeObj = GetSizes("C")
                Return _SizeObj
            End Get
        End Property
        Public ReadOnly Property D As SizeObject
            Get
                _SizeObj = GetSizes("D")
                Return _SizeObj
            End Get
        End Property
        Public ReadOnly Property E As SizeObject
            Get
                _SizeObj = GetSizes("E")
                Return _SizeObj
            End Get
        End Property
    End Class
#End Region

 

 

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

The 'Logger' I mentioned is a common tool used in iLogic rules since around the 2019 version for debugging and progress feedback, without interrupting the code with pop-up dialogs.  It is simply used to write textual data to the 'iLogic Log' tab of the iLogic DockableWindow.  The term 'Logger' is automatically defined for us within the 'ThisRule' Class (the Class block created automatically for us in the background), and represents an 'Autodesk.iLogic.Interfaces.IRuleLogger' Interface Type object.  It has 6 methods for writing to different levels (Debug, Error, Fatal, Info, Trace, Warn, and of course ToString).  So that term is readily available to us for use in iLogic rules, but you would likely need to include a reference to the source file, and create a variable for one if you wanted to use it in something like an ApplicationAddIn or external EXE type solution.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes