Hi All,
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, app
Dim fso, f1
Dim outputFileName, outputString
Dim 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 Next
Set app = GetObject(, "MGCPCB.Application")
If Err Then
Set app = GetObject(, "MGCPCB.FablinkXEApplication")
Err.Clear
End If
Call Scripting.AddTypeLibrary("MGCPCB.Application")
' create a file system object for data output
Set fso = CreateObject("Scripting.FileSystemObject")
' dump the component information
app.LockServer
Call 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 " & outputFileName
End If
Call app.Gui.CursorBusy(False)
app.UnlockServer
f1.Close()
Set fso = Nothing
Set pcbDoc = Nothing
Set app = Nothing
Hi yu.yanfeng,
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?
Yanfeng
Hi yu.yanfeng,
In report writer, its not possible to take the cell name as report from PCB.
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.
Hi,
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)
Best regards,
Hello matthias,
Thank you very much........ It works and I am very happy to work with this.
