Batch Part Library Editor

Document created by joe_krolla on Oct 13, 2010
Version 1Show Document
  • View in full screen mode

Author (required): Al Layson


Platform/Format: VBScript


Use case description (required)

The EditLibraryParts.vbs script provides the mechanics for Editing Parts in the Central Library's Parts Partition. It begins by compiling a list of partitions and parts to process. It does this in a way that allows you to easily customize the resulting compilation by allowing you to define and specify filter functions that specifiy whether or not to include or exclude a partition and part. After compilation it will execute the edit process which will open each part and feed its part object to an edit function that you define and specify. This function is required to return a true or false value to indicate whether or not to save the Complete Parts Database as a result of any one part edit. It is not possible to save just one part - all parts must be saved. Below is an example use of the Subroutine "EditCLParts" that is included in the script and the functions that it uses, specified and defined by you.


'Modify the call to EditCLParts to specify your

'Partition Filter Function name (IE "myPartitionFilter")

'Part Filter Function name (IE "myPartFilter")

'Editor Function name (IE "EditPart")

'Do not change the Subroutine name "main()"

Sub main()
     EditCLParts libPath & libName,"myPartitionFilter","myPartFilter","EditPart"
End Sub


'Define your Partition Filter Function

'Return True to include

'This example excludes all partitions except the "darpa" partition


Function myPartitionFilter(oPartition)



     If oPartition.Name="darpa" Then myPartitionFilter=True


End Function



'Define your Part Filter Function

'Return True to include

'This example includes only those parts with a part name that is not prefixed with "DARPA_"


Function myPartFilter(oPart)


     If Not InStr(oPart.Name,"DARPA_")=1 then myPartFilter=True

End Function



'Define your Editor

'Return True to save the entire Parts DB.

'This example modifies the existing Part Name and Description by inserting the Word "DARPA_" at the beginning of the Name and "DARPA: " at the beginning of the Description.


Function EditPart(oPart)


     oPart.Name="DARPA_" + oPart.Name

     oPart.Description="DARPA: " + oPart.Description

End Function



At the top of the script is a Const DBUG=0 statement that controls the maximum number of parts to process where 0=All. This will allow you to minimize the runtime for debug purposes.


The script may be executed one of two ways:

1) Executed via "mgcscript" in a windows command prompt with the Pathname of the library given as the sole argument:

                "mgcscript C:\VBScripts\EditLibraryParts.vbs C:\Libraries\20078\Library.lmc"

2) Open the script in IDE - Library Manager's File->Open Script Form and execute the "Play" button. However, this may require an Automation Pro license. It does in Expedition/FablinkXE/Drawing Editor.

The script will write to "EditCLParts.txt" in the library's LogFile directory. Use this file to determine status of the run. Use an editor to view the file that will open files in use, ie Notepad.exe. When completed, this file will open in Notepad.


HINT: when writing/debugging your Editor Function, do so first in a separate script. Otherwise, it will take considerably longer for debug.






Location of the zip file:



Copyright 2010 Mentor Graphics Corporation. All Rights Reserved. Recipients who obtain this code directly from Mentor Graphics use it solely for internal purposes to serve as example Java or Java Script plugins. This code may not be used in a commercial distribution. Recipients may duplicate the code provided that all notices are fully reproduced with and remain in the code. No part of this code may be modified, reproduced, translated, used, distributed, disclosed or provided to third parties without the prior written consent of Mentor Graphics, except as expressly authorized above. THE CODE IS MADE AVAILABLE "AS IS" WITHOUT WARRANTY OR SUPPORT OF ANY KIND. MENTOR GRAPHICS OFFERS NO EXPRESS OR IMPLIED WARRANTIES AND SPECIFICALLY DISCLAIMS ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR WARRANTY OF NON-INFRINGEMENT. IN NO EVENT SHALL MENTOR GRAPHICS OR ITS LICENSORS BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS) WHETHER BASED ON CONTRACT, TORT OR ANY OTHER LEGAL THEORY, EVEN IF MENTOR GRAPHICS OR ITS LICENSORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.