Get path of file on clipboard
<CommandMethod("TcX3")> _
Sub TcX3()
'MsgBox(GetClipboardFilePath)
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(GetClipboardFilePath)
End Sub
Public Function GetClipboardFilePath() As String
Dim dataObject = System.Windows.Forms.Clipboard.GetDataObject
' Get the list of available formats
Dim formats() As String = dataObject.GetFormats()
For Each format As String In formats
' In case of AutoCAD 2013 this would be "AutoCAD.R19"
If format.StartsWith("AutoCAD.") Then
Using stream As IO.MemoryStream = dataObject.GetData(format)
' Unicode encoding is 16 bit (2 bytes) just like ACHAR
Using reader As IO.TextReader = New IO.StreamReader(stream, System.Text.Encoding.ASCII)
' 0..259 = 260
Dim text(259) As Char
reader.Read(text, 0, 260)
' There will be lots of 0 value characters in the array
' that we need to clean up
Return New String(text).TrimEnd(New Char() {Chr(0)})
End Using
End Using
End If
Next
Return Nothing
End Function
Sub TcX3()
'MsgBox(GetClipboardFilePath)
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(GetClipboardFilePath)
End Sub
Public Function GetClipboardFilePath() As String
Dim dataObject = System.Windows.Forms.Clipboard.GetDataObject
' Get the list of available formats
Dim formats() As String = dataObject.GetFormats()
For Each format As String In formats
' In case of AutoCAD 2013 this would be "AutoCAD.R19"
If format.StartsWith("AutoCAD.") Then
Using stream As IO.MemoryStream = dataObject.GetData(format)
' Unicode encoding is 16 bit (2 bytes) just like ACHAR
Using reader As IO.TextReader = New IO.StreamReader(stream, System.Text.Encoding.ASCII)
' 0..259 = 260
Dim text(259) As Char
reader.Read(text, 0, 260)
' There will be lots of 0 value characters in the array
' that we need to clean up
Return New String(text).TrimEnd(New Char() {Chr(0)})
End Using
End Using
End If
Next
Return Nothing
End Function
[本日志由 tiancao1001 于 2014-01-19 02:10 AM 编辑]
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |