PDA

View Full Version : Slide Shows of Images and Drawing Images



peter
2014-01-25, 08:12 AM
Well after playing with the splash screen program, I liked the fact you could display image files in a dialog, which LISP cannot do without using slides.

I also thought it might be nice to create a Slide Show, using a timer and a listbox.

So here it is on you tube.

http://www.youtube.com/watch?v=NVS59DxvD74&feature=youtu.be

If you like what you see you could download the attachments.

Here is the LISP file that calls the new .net function



(defun C:Slides ()
(slideshow "c:\\slideshow\\testbitmap.dwg" "photo1.jpg" "photo2.jpg" "photo3.jpg" "photo4.jpg" "photo5.jpg")
)

(defun C:Slides2 ()
(slideshow (list "c:\\slideshow\\testbitmap.dwg" "photo1.jpg" "photo2.jpg" "photo3.jpg" "photo4.jpg" "photo5.jpg"))
)


This is the dialog appearance:

94750

Panel1(Image), Button1(OK), Button2(Cancel), Button3(SlideShowOnOff), Listbox1(ImageFiles)

This is the Form1 Code



Imports Autodesk.AutoCAD.DatabaseServices

Public Class Form1
''' <summary>
''' OK Button
''' </summary>

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
SlideShowClass1.objTimer.Stop()
SlideShowClass1.strImageFullName = ListBox1.SelectedItem.ToString
Close()
End Sub

''' <summary>
''' Cancel Button
''' </summary>

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
SlideShowClass1.objTimer.Stop()
Close()
End Sub

''' <summary>
''' Turn Slide Show On and Off Button
''' </summary>

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If SlideShowClass1.blnSlideShowOn = True Then
SlideShowClass1.blnSlideShowOn = False
Button3.Text = "Turn Slide Show On"
Else
SlideShowClass1.blnSlideShowOn = True
Button3.Text = "Turn Slide Show Off"
End If
End Sub

''' <summary>
''' List Box Selection Callback changes image of Panel1 to image file or drawing thumbnail
''' </summary>

Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
Try
SlideShowClass1.strImageFullName = Me.ListBox1.SelectedItem.ToString
If System.IO.Path.GetExtension(SlideShowClass1.strImageFullName).ToUpper = ".DWG" Then
Dim objDatabase As New Database
objDatabase.ReadDwgFile(SlideShowClass1.strImageFullName, _
FileOpenMode.OpenForReadAndAllShare, False, Nothing)
Me.Panel1.BackgroundImage = objDatabase.ThumbnailBitmap
Else
Me.Panel1.BackgroundImage = System.Drawing.Image.FromFile(SlideShowClass1.strImageFullName)
End If
Me.BringToFront()
Catch ex As Exception
End Try
End Sub

End Class


and this is the class code



Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime

Imports System.Windows.Forms

Imports objACADApplication = Autodesk.AutoCAD.ApplicationServices.Application
Public Class SlideShowClass1
Private tpvNil As New TypedValue(LispDataType.Nil, -1)

Public Shared objForm As New Form1
Public Shared objTimer As System.Windows.Forms.Timer
Public Shared blnSlideShowOn As Boolean = True
Public Shared strImageFullName As String

''' <summary>
''' LISP Function to show slide show of images (or drawing thumbnail images)
''' </summary>

<LispFunction("SlideShow")> _
Public Function SlideShow(ByVal rbfArguments As ResultBuffer)
Try

Dim arrArguments As TypedValue() = rbfArguments.AsArray
If arrArguments.Length > 0 Then

Dim strImageFullName, strImageName As String
' Dim tpvItem As TypedValue()

blnSlideShowOn = True

If Not objForm Is Nothing Then objForm = New Form1

With objForm.ListBox1
If .Items.Count > 0 Then .Items.Clear()
For intCount = 0 To arrArguments.Length - 1
If arrArguments(intCount).TypeCode = 5005 Then
strImageName = arrArguments(intCount).Value.ToString
strImageFullName = HostApplicationServices.Current.FindFile(strImageName, _
objACADApplication.DocumentManager.MdiActiveDocument.Database, _
FindFileHint.Default)
If strImageFullName IsNot Nothing Then .Items().Add(strImageFullName)
End If
Next
strImageFullName = ""
If .Items.Count = 0 Then Return tpvNil
.SelectedIndex = 0
TimerInitialize(2000.0) '<- Milliseconds
If objForm.ShowDialog() = DialogResult.Cancel Then
Return tpvNil
End If

End With
End If

Return New TypedValue(LispDataType.Text, strImageFullName)
Catch ex As System.Exception
End Try
Return tpvNil
End Function

''' <summary>
''' Function to initialize the forms timer
''' </summary>

Private Function TimerInitialize(ByVal dblMilliseconds As Double)
Try
If objTimer Is Nothing Then
objTimer = New System.Windows.Forms.Timer
AddHandler objTimer.Tick, AddressOf TickHandler
End If
objTimer.Interval = CType(dblMilliseconds, Integer)
objTimer.Enabled = True
objTimer.Start()

Return True
Catch ex As Exception
End Try
Return False
End Function

''' <summary>
''' Timer Callback Function to switch image
''' </summary>

Private Sub TickHandler(ByVal sender As Object, ByVal e As System.EventArgs)
ImageChange(objForm.ListBox1)
End Sub

Public Delegate Sub ListBoxDelegate(ByVal objListBox As ListBox)

''' <summary>
''' Function to Change Image in Listbox to next image
''' </summary>

Public Sub ImageChange(ByVal objListBox As ListBox)
objForm.BringToFront()
If objListBox.InvokeRequired Then
objListBox.Invoke(New ListBoxDelegate(AddressOf ImageChange), objListBox)
Else
If blnSlideShowOn Then
With objForm
If .ListBox1.Items.Count > 0 Then
If .ListBox1.SelectedIndex < .ListBox1.Items.Count - 1 Then
.ListBox1.SelectedIndex += 1
Else
.ListBox1.SelectedIndex = 0
End If
End If
End With
End If
End If
End Sub

End Class



I should mention that I coded this in Visual Studio 2013 and used AutoCAD 2014 for the code package