User:Smallman12q/Scripts/Transperify

From Wikipedia, the free encyclopedia

The following is a visual basic script for adding transparent backgrounds to molecular projections produced in ChemDraw with SVGs.

The script requires that you have XP (or higher) with VBS installed (this is installed on most Windows machines).

Setup[edit]

  1. Open notepad
  2. Copy and paste the code below into notepad
  3. In notepad, select File->Save as and select "All files" at "File Save as Type"
  4. Enter the title Transperify.vbs and select save in a directory.

Usage[edit]

  1. Export image in ChemDraw as SVG
  2. Drag-and-drop saved image onto the script's icon.
  3. The svg will be automatically converted (virtually instantly)
  4. The svg now has a transparent background. Enjoy!

If you have any questions, please ask at my talk page at: User talk:Smallman12q

Source[edit]

'Transperify.vbs
'Public Domain September 2010
'Version 1.1
'Written by Smallman12q in Visual Basic Script (VBS)
'Source + Instructions at http://en.wikipedia.org/wiki/User:Smallman12q/Scripts/Transperify

'Desc: This vbs script will add a transparent background to svgs generated by ChemDraw 12
'Usage: Simply drag-and-drop the svg generated by ChemDraw onto this script and a transparent background will be added.

'Changes
'1.1 (Sept 7 2010) - Supports drag-and-drop of multiple svgs onto the script. Removed error check as errors are already caught.

Sub fixit(item)
    'Make sure its an svg file
    If (Right(item, 4) = ".svg") Then
       
        Const ForReading = 1
        Const ForWriting = 2
        Dim strText, strNewText
       
        'Read file
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objFile = objFSO.OpenTextFile(item, ForReading)
        strText = objFile.ReadAll
        objFile.Close
       
        'Append a fill-opacity="0.0" to fill="rgb(255, 255, 255)"
        strNewText = Replace(strText, """rgb(255, 255, 255)""", """rgb(255, 255, 255)"" fill-opacity=""0.0""")
       
        'Write to file
        Set objFile = objFSO.OpenTextFile(item, ForWriting)
        objFile.WriteLine(strNewText)
        objFile.Close
        'MsgBox("Done")'Debug
    End If
End Sub

'Check to make sure drag-and-drop
If( WScript.Arguments.Count < 1) Then
    MsgBox "You must drag and drop the file onto this."
    WScript.Quit 1 'There was an error
   
Else 'There are some arguments
    Set objArgs = WScript.Arguments
    For I = 0 To objArgs.Count - 1 'Check all the arguments
        fixit(objArgs(I))
    Next
End If

WScript.Quit 0 'Exit okay

'ChemDraw is the property of CambridgeSoft

Code resources[edit]