Example 2: Opening a Data Sheet

The following script provides a flexible launching method for datasheets with an attribute populated with only the filename in Databook.

This example launches Acrobat Reader to open the datasheet. This script provides the functionality for the menu item created in “Example 1: Create/Add Menus”.

The script acquires the value of an environment variable, MY_DS. This value is the directory in which the datasheets are located. The script then finds the DataSheet attribute value of the selected component and launches the datasheet in Acrobat.

In order for this script to run, a part must be selected when you choose the menu item.

You can use this script via any of the methods described in “Running Scripts”.

Note:

Mentor Graphics recommends that you use COM versioning syntax in script examples that use GetObject and CreateObject. Without COM versioning, the script will access the last installation to which the release switcher pointed.

' Get the attribute for DataSheet from the part on the schematic 
Option Explicit 
' Used to populate  Object browser in script editor 
' set vdapp = CreateObject("Viewdraw.Application") 
 
 
' Run on an open document. 
Dim vdapp,vddoc,vdview 
 
' **** Use the code within the asterisk area for an open drawing **** 
 Set vdapp = GetObject (,"ViewDraw.Application") 
Scripting.AddTypeLibrary("ViewDraw.Application") 
Set vddoc = vdapp.ActiveDocument 
 Set vdview = vdapp.ActiveView 
' ************* End of open drawing code ********************* 
 
' Get attributes on selected part 
	Dim DataSheetDir, DataSheet, DataSheetName, RefDes, RefDesValue, Comp 
	' Get the value a system environment variable whose value is the 
	' directory containing the datasheets and advise the user. 
	DataSheetDir = Scripting.GetEnvVariable ("MY_DS") 
	 
	MsgBox "DataSheetDir is " & DataSheetDir,,"Data Sheet Directory" 
 
	'Create a collection using the Query method, of the 
	'components which are selected on the schematic 
	For Each Comp in vdview.Query(VDM_COMP, VD_Selected) 
 
		' Identify the Data_Sheet attribute on the component 
		Set DataSheet = Comp.FindAttribute("DATA_SHEET") 
		 
		' Use the If conditional to determine if the attribute exists. 
		' If it doesn't, advise the user. 
		' If it does, execute the statements after Else 
	 
			If DataSheet Is Nothing Then 
				MsgBox "No DATA_SHEET Attribute on this part",,"Data Sheet Exists?" 
			Else 	 
				' Get the Data_sheet attribute value  
				DataSheetName = DataSheet.value 
				 
				' Processing the REFDES is optional and is used basically for 
				' completeness/debug. 
				' Create an object for the REFDES attribute 
				Set RefDes = Comp.FindAttribute("Ref Designator") 
				If RefDes Is Nothing Then 
					MsgBox "No Ref Designator Property found.",,"What's the problem" 
				else 
					RefDesValue = RefDes.value 
				End If ' REFDES is nothing 
				' Check to see if the DATASHEET attribute has a value. 
				If DataSheetName = "" Then 
					MsgBox "Data sheet name not specified for component " & RefDesValue,,"Data Sheet?" 
				Else 
					MsgBox "Refdes is: " & RefDesValue & vbCrLf &_ 
				 "Data Sheet filename is " & DataSheetName,,"Confirmation" 
	' Concatenate a defined directory path to the datasheet attribute value 
					Dim DataSheetFileName 
					DataSheetFileName = DataSheetDir & "\" & DataSheetName 
					' Inform the user of the datasheet which will be opened. 
					MsgBox "Data Sheet file Name: " & DataSheetFileName,,"Data Sheet To Open" 
 
		' Example of how to launch a third party executable 
		Dim Win 
		Set win =CreateObject("WScript.shell") ' Create the windows object 
	'Use the run method to launch an application on the specific datasheet 
		    		win.run "Acrobat.exe " & DataSheetFileName  
		    	End If  
		   End If  
	Next