Hi,
Is there any Easy way to generate report of "Height of parts in Board"?
I am trying to generate MS-Excel report through following code
Sub Get_Height()
Dim serverIsLocked As Boolean
Dim prts As MGCPCB.Parts
Dim prt As MGCPCB.Part
Set prts = pcbdoc.Parts
prts.Sort
' Define Header
i = 2
Range("A1").FormulaR1C1 = "part Number"
Range("B1").FormulaR1C1 = "No. of parts"
Range("C1").FormulaR1C1 = "Height"
Range("D1").FormulaR1C1 = "Underside Height"
For Each prt In prts
Range("A" & i).FormulaR1C1 = prt.Name
Range("B" & i).FormulaR1C1 = prt.Components.Count
Range("C" & i).FormulaR1C1 = prt.Height(epcbUnitCurrent)
Range("D" & i).FormulaR1C1 = prt.UndersideHeight
On Error Resume Next
i = i + 1
Next
MsgBox "Done!"
End Sub
But value of "prt.Height(epcbUnitCurrent)" is shows as "-1" for all components!! ![]()
Any clue?
There are different ways the height can be defined, one is attached to the cell (default) and the other is attatched to the part (for when the default cell height isn't correct for that specific part).
Don't know if you can get the cell height directly trough automation but you can get them from ASCII export of cells (search for "Height") or from IDF export's emp file.
Yes, I am trying to extract height defined at Part level through automation.
I believe that extracting data from ASCII & IDF is time consuming task.... Unless you have any script to do that !
The height actually belongs to the placement outline.
There are a few examples of the in the AATK download. vbs/Manufacturing/POV.vbs or vbs/Manufacturing/VRML.vbs
http://sourceforge.net/projects/uwtoolbox/
Sub main()
Get_Height
End Sub
Sub Get_Height()
Dim pcbApp As MGCPCB.Application
Dim pcbDoc As MGCPCB.Document
Set pcbApp = GetObject(, "MGCPCB.Application")
Set pcbDoc = pcbApp.ActiveDocument
' get a doc licence
retVal = licenseDoc(pcbDoc)
If (retVal <> 1) Then Set pcbDoc = Nothing
Dim prts As MGCPCB.Parts
Dim prt As MGCPCB.Part
Set prts = pcbDoc.Parts
prts.Sort
' Define Header
i = 2
Range("A1").FormulaR1C1 = "part Number"
Range("B1").FormulaR1C1 = "No. of parts"
Range("C1").FormulaR1C1 = "Height"
Range("D1").FormulaR1C1 = "Underside Height"
For Each prt In prts
Range("A" & i).FormulaR1C1 = prt.Name
Range("B" & i).FormulaR1C1 = prt.Components.Count
Dim comps As Components
Dim comp As Component
Dim po As PlacementOutline
Dim pos As PlacementOutlines
Set comps = prt.Components
For Each comp In comps
Set pos = comp.PlacementOutlines
For Each po In pos
Range("C" & i).FormulaR1C1 = po.Height(epcbUnitCurrent)
Range("D" & i).FormulaR1C1 = po.UndersideSpace
Next
Next
On Error Resume Next
i = i + 1
Next
MsgBox "Done!"
End Sub
Private Function licenseDoc(docObj As MGCPCB.Document) As Integer
' =======================================================================
' Retrieve a licence for the document
' =======================================================================
On Error GoTo exit_with_error
Dim retState As Integer
Dim licenseServer As Object
Dim key As Long
Dim licenseToken As Long
Dim outErrMess As String
If (docObj Is Nothing) Then GoTo end_of_function
' Ask the document for a key
key = docObj.Validate(0)
' Get license server
On Error GoTo err_create_serverobj
Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")
If (licenseServer Is Nothing) Then GoTo err_create_serverobj
On Error GoTo exit_with_error
' Ask the license server for the license token
licenseToken = licenseServer.GetToken(key)
' Validate the document with the license token
On Error GoTo err_validate
Dim lRetval As Long
lRetval = docObj.Validate(licenseToken)
On Error GoTo exit_with_error
retState = 1
end_of_function:
' release licence server
Set licenseServer = Nothing
licenseDoc = retState
Exit Function
show_error:
Dim ioptions As Long
ioptions = vbDefaultButton1 + vbApplicationModal + vbCritical + vbOKOnly
MsgBox outErrMess, ioptions, "Retrieving license for document"
GoTo end_of_function
exit_with_error:
outErrMess = "** Error ** " + Error$
retState = -1
GoTo show_error
err_create_serverobj:
outErrMess = "** Error ** Could not create license server object"
retState = -2
GoTo show_error
err_validate:
outErrMess = "** Error ** Failed to validate document object"
outErrMess = outErrMess + vbCrLf + " License token : " + Trim(Str(licenseToken))
outErrMess = outErrMess + vbCrLf + " Document key : " + Trim(Str(key))
retState = -3
GoTo show_error
End Function
![]()
That works!
Thanks for that!
kendall_hiles wrote:
The height actually belongs to the placement outline.
There are a few examples of the in the AATK download. vbs/Manufacturing/POV.vbs or vbs/Manufacturing/VRML.vbs
http://sourceforge.net/projects/uwtoolbox/
Sub main()
Get_Height
End Sub
Sub Get_Height()
Dim pcbApp As MGCPCB.Application
Dim pcbDoc As MGCPCB.Document
Set pcbApp = GetObject(, "MGCPCB.Application")
Set pcbDoc = pcbApp.ActiveDocument
' get a doc licence
retVal = licenseDoc(pcbDoc)
If (retVal <> 1) Then Set pcbDoc = Nothing
Dim prts As MGCPCB.Parts
Dim prt As MGCPCB.Part
Set prts = pcbDoc.Parts
prts.Sort
' Define Header
i = 2
Range("A1").FormulaR1C1 = "part Number"
Range("B1").FormulaR1C1 = "No. of parts"
Range("C1").FormulaR1C1 = "Height"
Range("D1").FormulaR1C1 = "Underside Height"
For Each prt In prts
Range("A" & i).FormulaR1C1 = prt.Name
Range("B" & i).FormulaR1C1 = prt.Components.Count
Dim comps As Components
Dim comp As Component
Dim po As PlacementOutline
Dim pos As PlacementOutlines
Set comps = prt.Components
For Each comp In comps
Set pos = comp.PlacementOutlines
For Each po In pos
Range("C" & i).FormulaR1C1 = po.Height(epcbUnitCurrent)
Range("D" & i).FormulaR1C1 = po.UndersideSpace
Next
Next
On Error Resume Next
i = i + 1
Next
MsgBox "Done!"
End Sub
Private Function licenseDoc(docObj As MGCPCB.Document) As Integer
' =======================================================================
' Retrieve a licence for the document
' =======================================================================
On Error GoTo exit_with_error
Dim retState As Integer
Dim licenseServer As Object
Dim key As Long
Dim licenseToken As Long
Dim outErrMess As String
If (docObj Is Nothing) Then GoTo end_of_function
' Ask the document for a key
key = docObj.Validate(0)
' Get license server
On Error GoTo err_create_serverobj
Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")
If (licenseServer Is Nothing) Then GoTo err_create_serverobj
On Error GoTo exit_with_error
' Ask the license server for the license token
licenseToken = licenseServer.GetToken(key)
' Validate the document with the license token
On Error GoTo err_validate
Dim lRetval As Long
lRetval = docObj.Validate(licenseToken)
On Error GoTo exit_with_error
retState = 1
end_of_function:
' release licence server
Set licenseServer = Nothing
licenseDoc = retState
Exit Function
show_error:
Dim ioptions As Long
ioptions = vbDefaultButton1 + vbApplicationModal + vbCritical + vbOKOnly
MsgBox outErrMess, ioptions, "Retrieving license for document"
GoTo end_of_function
exit_with_error:
outErrMess = "** Error ** " + Error$
retState = -1
GoTo show_error
err_create_serverobj:
outErrMess = "** Error ** Could not create license server object"
retState = -2
GoTo show_error
err_validate:
outErrMess = "** Error ** Failed to validate document object"
outErrMess = outErrMess + vbCrLf + " License token : " + Trim(Str(licenseToken))
outErrMess = outErrMess + vbCrLf + " Document key : " + Trim(Str(key))
retState = -3
GoTo show_error
End Function
Thank you all!
Is there any way I can report the Assembly/Silkscreen elements, Number of placement outlines etc for all cells in a central library
by using the celleditor data model similarly? I can get the Height, Pincount, Number of layers etc using the Cell editor objects but
couldnt find a way to report the others..
This is the latest from AATK.
Opens a new Excel and adds the heights. Just drag and drop onto Expedition (Windows) use the keyin run <path> from Linux/Solaris