Example 4: Using Objects in Scripts

This script demonstrates the usage of some of the Application level methods/properties/events.

The script demonstrates these concepts best when multiple sheets and multiple schematics are opened before running the script. The script expects a application window to be open and one, or more schematics to be open.

The queries at the end of the script demonstrate the scope of the query depending on the object used.

The object variables have the following usage scopes:

  • vdapp = Xpedition Designer application

  • vddocColl - Xpedition Designer documents (open files in Xpedition Designer)

  • vddoc - Xpedition Designer document (the active document)

  • vdview - Current view

    Note:

    Keep in mind that the variable values must be refreshed when navigating the design to ensure that any scripting object is reporting/operating on the desired design data.

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.

Option Explicit 
 
Dim VDM_COMP, VD_ALL, VDFILL_VERT, VD_SELECTED 
Dim vdapp,vddoc, vdview, vddocColl, Comp, CompRefdes, inc 
Dim ProjDir,ProjName 
Dim Index, ItemObj, ItemName 
 
' 
' The following constants are known within Xpedition Designer and  
' DO NOT need to be defined when the script is run from within 
' Xpedition Designer.  Running the script as a client using a debugger,  
' Xpedition Designer doesn't understand it's internal enumerated variables  
' and their values, so we are providing them here. 
'  
' Once a script has been debugged, the intention is to run them 
' within the Xpedition Designer application, it is not necessary to set 
' the enumerations as they will be provided within the application. 
' 
	VDM_COMP =  128 
	VD_ALL = 0 
	VD_SELECTED = 1 
	VDFILL_VERT = 13 
	inc = 1 
 
' The following 2 lines are allow for the Xpedition Designer Application  
' to be invoked and adds the type library.	 
' When using an external debugger, you may need these lines, 
' even though they are not used, in order for the debugger to load the  
' application's Type library. 
' 
	'Set vdapp = CreateObject("ViewDraw.Application")	 
	' invokes viewdraw.exe and gives you back the app object 
	'vdapp.Scripting.AddTypeLibrary("ViewDraw.Application")   
	' Adds the Xpedition Designer Type library. 
 
' Attach to a running Xpedition Designer process 
 
	Set vdapp = GetObject(,"ViewDraw.Application")	 
	vdapp.visible = True  
	 
' Create a view object which points to the current active  
' drawing displayed in Xpedition Designer 
 
	Set vdview = vdapp.ActiveView		 
		 
' Create a Document object which points to the current active  
' document in memory for Xpedition Designer 
	Set vddoc  = vdapp.ActiveDocument 
	MsgBox "ActiveDocument Name: " & vddoc.name,,"Vddoc Name" 
	 
' 
'  ****** Begin Flat design navigation example  ******* 
' 
	Dim CurBlock, CurBlockNamePage 
' Create the block object 
	Set CurBlock = vdview.block 
 
' Create a variable whose value is the filename and extension. 
	CurBlockNamePage = CurBlock.GetName(1) & "." & CurBlock.SheetNum 
	MsgBox "The current schematic and page is : " & CurBlockNamePage,,"Initial Block/Page" 
 
' Push to the next page using the Xpedition Designer Command line command 
	vdapp.ExecuteCommand "PSH" 'Pushes to next page. 
	Set vdview = vdapp.ActiveView	 
	Set CurBlock = vdview.block 
	CurBlockNamePage = CurBlock.GetName(1) & "." & CurBlock.SheetNum 
	MsgBox "The current schematic and page is : " & CurBlockNamePage,,"Block/Page Post Push" 
 
' Return to the previous view using the Xpedition Designer Pop command
' line command 
	vdapp.ExecuteCommand "Pop"' Create the block object 
	Set vdview = vdapp.ActiveView 
	Set CurBlock = vdview.block 
	CurBlockNamePage = CurBlock.GetName(1) & "." & CurBlock.SheetNum 
	MsgBox "The current schematic and page is : " & CurBlockNamePage,,"Block/Page Post Pop" 
 
' 
' ******    End Flat design navigation example  *******  
' 
' 
' ******    Begin Adding box and setting object property example ****** 
 
	MsgBox "About to add a box",,"Advise Adding Box" 
	 
' Use the AddBox method to add a box. Requires two xy coordinates 
	CurBlock.AddBox 50,50,350,350 ' Form: x(lowerleft),y(lowerleft),x(upperright),y(upperright), 
' The box which was just added is still selected. 
	Dim gBoxColl,gBox, VDM_BOX: VDM_BOX = 2 
' 
' The following statements create a collection of the selected boxes, 
' then, for each selected box found, sets the fill style to vertical, 
' deletes the box, then performs an undo, then deselects the box using 
' the box object Selected property. 
' 
	Set gBoxColl = vdview.query (VDM_BOX, VD_Selected) 
		For Each gBox In gBoxColl  
			' Set fill style to vertical 
			gBox.fillstyle(VDFILL_VERT) 
			' Refresh the graphics so the vertical cross hatch is displayed. 
			vdapp.executecommand "refresh" 
			MsgBox "Filled the box",,"What did I do to the box?" 
			MsgBox "About to Delete Selected",,"Deleting.." 
			' Demonstrating the DeleteSelected method 
			' (parameter)False leaves dangling nets; True removes them. 
			' As there aren't any nets on the graphical box, either seting 
			' would be ok.  Must be correctly specified for components. 
			CurBlock.DeleteSelected(False)  
			MsgBox "Deleted the box",,"Advisory" 
			' Executing a command line command to undo the deletion. 
			vdapp.ExecuteCommand "undo" 
			' Deselecting the box. Same as clicking the Left mouse button 
			' in an unoccupied are of the drawing. 
			gBox.Selected = False 
		Next  
	MsgBox "Box Added, Check schematic",,"Add Box Verify" 
 
' 
' *******   End Adding box and setting object property example ****** 
' 
 
' 
' *******  Begin application visibility control example. 
' 
 
' The following lines toggle the visibility of the Application (Xpedition 
' Designer window).  The message boxes simply allow the user to see the 
' application visibility set to invisible. 
 
	vdapp.Visible = False    							 
	MsgBox "Just made the Application invisible",,"What Happened?" 
	vdapp.visible =True 
	MsgBox "Just made the Application visible",,"What Happened Now?" 
 
' 
' *******  End application visibility control example. 
' 
' *******  Begin Project and software information extraction example **** 
' 
	'Assigns the primary directory pointer to the variable ProjDir 
	'and the project Name to the variable ProjName, then displays  
'   both in a message box	 
 
	ProjDir = vdapp.GetProjectData.GetProjectPath 
	ProjName = vdapp.GetProjectData.GetProjectName 
	MsgBox "Project Name is " & ProjName & vbCrLf &_ 
		   "Project Directory is: " & ProjDir,,"Project information" 
 
	MsgBox vdapp.Name & "  " & vdapp.version & vbCrLf &_ 
		   "Executable " & vdapp.fullname,,"Xpedition Designer Information" 
		    
 
' ViewFull method resets CurrentView to full screen. 
	Dim CurrentView 
	Set CurrentView = vdapp.ActiveView 
	CurrentView.viewfull 
' 
' *******  End Project and software information extraction example ****** 
' 
 
' 
' ******* Begin Status Bar control example  
' 
	vdapp.StatusBarText("Starting Test")	 
' 
' ******* End Status Bar control example  
	' 
 
	MsgBox "Setting Xpedition Designer window non-interactive.",,"Disable 
 mouse/keyboard Input" 
	 
	vdapp.interactive = false	' Xpedition Designer Application window will
								' not respond to mouse/keyboard entries 
								' until vdapp.interactive is set to 
								' True.  This includes all window controls 
								' such as minmize/maximize, etc. 
 
	vdapp.busycursor = True		' Set the cursor to the hour glass. 
 
	MsgBox "Xpedition Designer: Mouse/keyboard input disabled",,"Disable 
Message" 
 
	' Issue a message to the status bar. 
	vdapp.StatusBarText("Script has disabled this Xpedition Designer Window from accepting any user input") 
 
' 
' *******  End Disabling the Application window example   ******** 
	' 
 
'  ***** Begin cycling through and reporting on all the components on  
'        the open documents 
' 
'  Cycle through the open documents and display component information.   
' Uses a copy of some code from above to activate the different documents. 
' 
	' Create a collection of documents 
	Set vddocColl = vdapp.documents 
	' Process all documents using index to "target" each in the collection. 
	For Index=1 To vddocColl.Count  ' Number of open documents 
		Set ItemObj = vddocColl.Item(Index)  
		' Create a document object for members of the collection 
		ItemName = ItemObj.Name ' Document object's "Name" property 
   		MsgBox "Document Name: " & ItemName & vbCrLf &_ 
   			   "Document Index: " & Index,,"Document Information" 
' 
' Document Activate example 
' 
		MsgBox "Changing the active document to " & ItemObj.Name,,"Changing Selected Tab" 
		ItemObj.activate() 
		 
		Set vdview = vdapp.ActiveView 
		' Create the block object 
		Set CurBlock = vdview.block 
			For Each Comp in vdview.Query(VDM_COMP, VD_ALL)	 
		' Queries ONLY the current active 
		' schematic/symbol file in Xpedition Designer 
		' (e.g. queries only the current "view") 
				' Select the component 
				Comp.selected = True 
				' Zoom in on each component as it's being processed. 
				vdapp.executecommand "zselect" 
				' Set variable CompRefdes to the Refdes value 
				Set CompRefdes = Comp.FindAttribute("Ref Designator")	 
	 
				' Test for the existence of the REFDES attribute 
					If CompRefdes Is Nothing Then 
		    			MsgBox 	"No REFDES attribute found and component count is "_ 
								& inc & vbCrLf &_ 
						  	 	"Component ID " & Comp.uid & vbCrLf &_ 
						   		"Current document is " &_  
								vdapp.activeDocument.name,,_ 
								"Component Info - No Refdes" 
					Else 
						MsgBox "REFDES: " & CompRefdes.Value &_ 
								" and component count is " & inc & vbCrLf &_ 
							   "Component ID " & Comp.uid & vbCrLf &_ 
							   "Current document is " &_ 
								vdapp.activeDocument.name,,_ 
								"Component Info for Comps with REFDES" 
					End If	 
				inc = inc + 1 
				' Deselect comp and its attributes. Setting the Comp.selected 
				' property to False will not deselect the its attributes. 
				CurBlock.deselectall  
			Next ' Each Component 
	Next ' Each Document 
	 
	MsgBox "End of Script",,"Script Ending Dialog" 
	 
' 
'  *******   Begin Enabling the Application window example ******* 
' 
	' Change the cursor back to the pointer 
	vdapp.busycursor = False   ' True sets cursor graphic to hour glass;  
							   ' false sets graphic to pointer 
							   ' The pointer itself, however remains active. 
	' Enable the application window to respond to mouse and keyboard input.	 
	vdapp.interactive = True   ' True enables GUI interaction; False  
							   ' disables mouse and keyboard inputs 
 
' 
'  *******   End Enabling the Application window example ******* 
' 
 
	 
	' Issue a message to the status bar. 
	' Displays the string in Xpedition Designer status bar in the lower
   ' left of the window frame. 
	vdapp.StatusBarText("Script finished successfully!")