User:Smallman12q/Scripts/Transperify
Appearance
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]- Open notepad
- Copy and paste the code below into notepad
- In notepad, select File->Save as and select "All files" at "File Save as Type"
- Enter the title Transperify.vbs and select save in a directory.
Usage
[edit]- Export image in ChemDraw as SVG
- Drag-and-drop saved image onto the script's icon.
- The svg will be automatically converted (virtually instantly)
- 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://wiki.riteme.site/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]- http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=9692&lngWId=4
- http://blogs.technet.com/b/heyscriptingguy/archive/2005/02/08/how-can-i-find-and-replace-text-in-a-text-file.aspx
- http://www.microsoft.com/downloads/details.aspx?familyid=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
- http://msdn.microsoft.com/en-us/library/1cbft50a%28v=VS.85%29.aspx
- http://my.opera.com/Lee_Harvey/blog/2007/04/21/try-catch-finally-in-vbscript-sure
- http://msdn.microsoft.com/en-us/library/z2b05k8s%28v=VS.85%29.aspx