Skip navigation

This Question is Answered

1 "correct" answer available (5 pts)
86,898 Views 8 Replies Last post: Apr 16, 2012 4:54 AM by Rapport RSS
Rapport Contributor 25 posts since
May 26, 2011
Currently Being Moderated

Apr 10, 2012 11:17 PM

How to extract cell name for each refdes in PCB using VB script?

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?

yu.yanfeng EDA JEDI 1,202 posts since
Jul 23, 2008
Currently Being Moderated
Apr 11, 2012 7:34 AM in response to: Rapport
Re: How to extract cell name for each refdes in PCB using VB script?

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

yu.yanfeng EDA JEDI 1,202 posts since
Jul 23, 2008
Currently Being Moderated
Apr 12, 2012 6:28 AM in response to: Rapport
Re: How to extract cell name for each refdes in PCB using VB script?

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

yu.yanfeng EDA JEDI 1,202 posts since
Jul 23, 2008
Currently Being Moderated
Apr 13, 2012 4:48 AM in response to: Rapport
Re: How to extract cell name for each refdes in PCB using VB script?

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.

1.jpg

 

Yanfeng

matthias.cosaert Active 38 posts since
Aug 13, 2008
Currently Being Moderated
Apr 12, 2012 2:50 AM in response to: Rapport
Re: How to extract cell name for each refdes in PCB using VB 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,

Attachments:

More Like This

  • Retrieving data ...

Bookmarked By (0)