Ilogic or vba print screenshot image

Ilogic or vba print screenshot image

Anonymous
Not applicable
1,199 Views
3 Replies
Message 1 of 4

Ilogic or vba print screenshot image

Anonymous
Not applicable

Hi Guys,

 

I found this code (CAD pro systems ltd) to create an image file screenshot which works really well.

It saves the image file to the same location as the part or assembly that you have screenshot.

Does anyone know how to print the screenshot directly to my printer?

 

‘Create the pre-set list of output resolutions 

availableRes = New String() {“640 x 480”, “1024 x 768”, “1280 x 1024”, “1920 x 1080”}

‘Get the required resolution from an InputListBox.

selectedRes = InputListBox(“Select Resolution”,availableRes, “”, “Export JPG”, “Available Size”)

‘Set the required background colour
'using the RGB values below. 

‘Note that this will not work if you
'have a image image as your background!

Dim topColor As Color = ThisApplication.TransientObjects.CreateColor(255, 255, 255)‘255,255,255 = white.

Select Case selectedRes

   
Case = “640 x 480”

       
width = 640

       
height = 480

   
Case = “1024 x 768”

       
width = 1024

       
height = 768

   
Case = “1280 x 1024”

       
width = 1280

       
height = 1024

   
Case = “1920 x 1080”

       
width = 1920

       
height = 1080

End Select

imageName = ThisDoc.PathAndFileName(False)

Dim cam As Camera

cam = ThisApplication.ActiveView.Camera

Dim Time As DateTime = DateTime.Now

‘Reformat the time to remove the :
'symbol because it not allowed for file names.

Dim Format As String = “HH.mm.ss”

currentTime = Time.ToString(Format) ‘Replaces : with . from time format.

‘Add current filename, resolution, and current time to make the image filename.

imageName = imageName & ” ” & selectedRes & ” ” & currentTime

cam.SaveAsBitmap((imageName & “.jpg”), width, height, topColor)

 

 

This is my code I have to print drawings, can this be modified?

 

SyntaxEditor Code Snippet

Dim oDrgDoc As DrawingDocument
        oDrgDoc = ThisApplication.ActiveDocument
        
        ' Set reference to drawing print manager
        ' DrawingPrintManager has more options than PrintManager
        ' as it's specific to drawing document
        Dim oDrgPrintMgr As DrawingPrintManager
        oDrgPrintMgr = oDrgDoc.PrintManager
        ' Set the printer name
        ' comment this line to use default printer or assign another one
        oDrgPrintMgr.Printer = "\\virginia\Canon 3500"
        'oDrgPrintMgr.AllColorsAsBlack = False
        'oDrgPrintMgr.ColorMode = kPrintDefaultColorMode
        'Set the paper size , scale and orientation
        oDrgPrintMgr.ScaleMode = kPrintBestFitScale
        oDrgPrintMgr.PaperSize = PaperSizeEnum.kPaperSizeA3
        oDrgPrintMgr.PrintRange = kPrintAllSheets
        oDrgPrintMgr.Orientation = kLandscapeOrientation
        oDrgPrintMgr.SubmitPrint

 

Cheers 

Tony

0 Likes
Accepted solutions (2)
1,200 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Accepted solution

Hi All,

 

I found a solution.

Pass the filename and filepath into VBA and then print from there.

 

Cheers for looking.

0 Likes
Message 3 of 4

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Nice to know that you have found a solution. Can you please update post with solution? it may be useful to forum people in future.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 4 of 4

Anonymous
Not applicable
Accepted solution

Pass the variable to vba as argument 1 :-

 

VBA Code:-

 

 

Public Sub PrintAnyDocument(ByVal argument1 As String)
Dim TargetFolder
Dim FileName
Dim ObjShell As Object
Dim ObjFolder As Object
Dim ObjItem As Object
Dim ColItems As Object

If InStrRev(argument1, "\") <> 0 Then
TargetFolder = Left(argument1, InStrRev(argument1, "\"))
FileName = Right(argument1, Len(argument1) - Len(TargetFolder))
End If
Set ObjShell = CreateObject("Shell.Application")
Set ObjFolder = ObjShell.NameSpace(TargetFolder)
Set ColItems = ObjFolder.Items
For Each ObjItem In ColItems
If ObjItem.Name = FileName Then
ObjItem.InvokeVerbEx ("Print")
Exit For
End If
Next
Set ObjItem = Nothing
Set ColItems = Nothing
Set ObjFolder = Nothing
Set ObjShell = Nothing
End Sub

0 Likes