Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

CatScript - Copy string to clipboard 2

Status
Not open for further replies.

man2007

Aerospace
Nov 6, 2007
283
IN
Is there any option to copy a string value to clipboard.
 
Replies continue below

Recommended for you



Code:
Sub Copy_to_Clipboard()

sString = "Paste To Clipboard"

Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("clip")

Set oWrite = oExec.stdIn

oWrite.WriteLine sString
oWrite.Close

End Sub

______

Alex ,
 
Thanks Alex for the code. I am getting this error:


getfile.aspx


Sub CATMain ()

Dim CATProdDoc As ProductDocument
Copy_to_Clipboard()

End Sub

Sub Copy_to_Clipboard()

sString = "Paste To Clipboard"

Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("clip")

Set oWrite = oExec.stdIn

oWrite.WriteLine sString
oWrite.Close

End Sub

 
Well, I have commented out Types, as I run CATIA on Windows (not UNIX), so the code is running fine now!

Sub CATMain ()

Dim CATProdDoc 'As ProductDocument
Copy_to_Clipboard()

End Sub

Sub Copy_to_Clipboard()

sString = "Paste To Clipboard"

Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("clip")

Set oWrite = oExec.stdIn

oWrite.WriteLine sString
oWrite.Close

End Sub
 
Hi,

Because I'm to lazy to right click, go in Properties and copy in clipboard from different workbenches and then paste what is in clipboard where I need, I've adapted the upper code to my needs (I need only names of different types of documents or text/dimension values in drawings).

Code:
Sub CATMain()
 
Set oPartDocument = CATIA.ActiveDocument
Set oSelection = oPartDocument.Selection
oSelection.Clear

Dim oInputType(0)
Dim oStatus

Dim MySelection3 As Object
Set MySelection3 = oPartDocument.Selection
Dim inputObjectType(0) As Variant
InputObjectType(0) = "AnyObject"
Dim Result As String
Result = MySelection3.SelectElement2(InputObjectType, "Select a dimesion/text in 2D, or a Body/CATPart/CATProduct in 3D ", False)
Set mySelection = oSelection.Item(1).Value
Dim s 'As String
Dim strToLeft 'As String
s = mySelection.Name
strToLeft = Split(s,".")(0) 

Set mySelection = oSelection.Item(1).Value
' Put it back to the clipboard
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("clip")
Set oIn = oExec.stdIn

If strToLeft = "Dimension" Then
oIn.WriteLine mySelection.GetValue.Value
oIn.Close

ElseIf strToLeft = "Text" Then
oIn.WriteLine mySelection.Text
oIn.Close

ElseIf TypeName(MySelection3.Item(1).Value) = "Part" Then
oIn.WriteLine mySelection.Name
oIn.Close

ElseIf TypeName(MySelection3.Item(1).Value) = "Product" Then
oIn.WriteLine mySelection.Name
oIn.Close

ElseIf TypeName(MySelection3.Item(1).Value) = "Body" Then
oIn.WriteLine mySelection.Name
oIn.Close

ElseIf TypeName(MySelection3.Item(1).Value) = "Document" Then
oIn.WriteLine mySelection.Name
oIn.Close

End If

End Sub

Regards
Fernando

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Top