I want to extract refdes, cell name & part number for each component in PCB. How to do this using VB script? Can any one help me out for this?
There is a ais.vbs script under Mentor install directory, you can modify one to fit your need.
a ready script modified from ais.vbs is here:
Dim pcbDoc, appDim fso, f1Dim outputFileName, outputStringDim pcbComps, pcbComp, i, designNumber
Public Function GetLicensedDoc(appObj) On Error Resume next Dim key,licenseServer,licenseToken,docObj
Set GetLicensedDoc = Nothing Set docObj = appObj.ActiveDocument If (Err) Then Call appObj.Gui.StatusBarText("No active document: " + _ Err.Description,epcbStatusFieldError) Exit Function End If
key = docObj.Validate(0) Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application") licenseToken = licenseServer.GetToken(key) Set licenseServer = Nothing Err.Clear docObj.Validate(licenseToken) If (Err) Then Call appObj.Gui.StatusBarText("No active document license: " + _ Err.Description,epcbStatusFieldError) Exit Function End If Set GetLicensedDoc = docObj End Function
On Error Resume NextSet app = GetObject(, "MGCPCB.Application")If Err Then Set app = GetObject(, "MGCPCB.FablinkXEApplication") Err.ClearEnd IfCall Scripting.AddTypeLibrary("MGCPCB.Application")
' create a file system object for data outputSet fso = CreateObject("Scripting.FileSystemObject")
' dump the component informationapp.LockServerCall app.Gui.StatusBarText("output in process",epcbStatusField1)Call app.Gui.CursorBusy(True)
Set pcbDoc = GetLicensedDoc(app)
If (Not pcbDoc Is Nothing) Then designNumber = pcbDoc.Name numberOfLayers = pcbDoc.LayerCount
outputFileName = pcbDoc.Path + "report.txt" Set f1 = fso.CreateTextFile(outputFileName, True)
f1.WriteLine("ReferenceDesignator CellName PartNumber") Set pcbComp = pcbDoc Set pcbComps = pcbDoc.Components pcbComps.Sort For Each pcbComp In pcbComps If (pcbComp.Placed = True) Then outputString = pcbComp.Name +" "+pcbComp.Cell+" "+ pcbComp.partnumber f1.WriteLine(outputString) End If Next
app.Gui.Display "The output file is " & outputFileNameEnd If
app.UnlockServerf1.Close()Set fso = NothingSet pcbDoc = NothingSet app = Nothing
Thanks for your quick reply and timely help. But when I run this script it generates the report.txt file with only headers of the components. It's not extracting the refdes, cellname & partnumber from the components. As per the coding if the components placement is true it should extract the information from component. I read the coding fully. I don't know where it went wrong. I have attached the output file for your reference. Can you help me on this to extract the component informations?
This scripts works well. I don't know what happened on your side. BTW, Why not use the report writer to get this type of list?
In report writer, its not possible to take the cell name as report from PCB.
Report writer was target to output customized reports. Althoug Mentor have dicided to EOL it long time, but it still have capability to output a components list for ref, cell name and part number.
What you have pointed out is correct. But it will report only topcell & bottom cell. I need the alternative cell also to be in report. So this can be able to make it through only script.
Here is a script that exports Refdes,Side, Used cell, Comp type and part number of placed components to excel.
Might not work for embedded components (we don't use that so didn't look into checking for that)
Thank you very much........ It works and I am very happy to work with this.
Retrieving data ...