As written this needs to be run with a PCB file active.
Sub ReadTextFile
'Constants for File Handling
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const TristateUseDefault = -2
Const TristateTrue = -1
Const TristateFalse = 0
Dim Board
Dim FileName
Dim oFS
Dim oFile
Dim oStream
Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then Exit Sub
'File Handling - Place a text file named "TextFile.txt" in
'the same directory as the current board that is open.
FileName=Left(Board.FileName, InstrRev(Board.FileName, "\") ) & "TextFile.txt"
'Check for the text file
If Not FileExists(FileName) Then
ShowMessage ( FileName & " was not found.")
Exit Sub
End If
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFile = oFS.GetFile(FileName)
Set oStream = oFile.OpenAsTextStream(ForReading, TristateUseDefault)
I = 1
'Read the file in
Do While Not oStream.AtEndOfStream
sRecord = oStream.ReadLine
ShowMessage ( "Line #" & I & " " & sRecord )
I = I + 1
Loop
oStream.Close
End Sub
www.tdpcb.com
Altium Designer Script Information in VB for PCB Layout and Schematic Capture by Bill Smock from Tru Designs, San Diego, CA.
Showing posts with label File. Show all posts
Showing posts with label File. Show all posts
Tuesday, May 24, 2011
Monday, May 16, 2011
Report a list of net names in PCB to a file.
Get a list of net names in the PCB and write a report (text file).
Sub ReportNets
Dim Board
Dim FileName
Dim ReportFile
Dim ReportDocument
Dim fso
BeginHourGlass
Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then Exit Sub
FileName = Left(Board.FileName, InstrRev(Board.FileName, "\") ) & "ReportNets.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set ReportFile = fso.CreateTextFile(FileName, True)
NetIterator = Board.BoardIterator_Create
NetIterator.AddFilter_ObjectSet(MkSet(eNetObject))
NetIterator.AddFilter_LayerSet(AllLayers)
NetIterator.AddFilter_Method(eProcessAll)
Set NetFound = NetIterator.FirstPCBObject
While Not (NetFound Is Nothing)
Call ReportFile.WriteLine( NetFound.Name )
Set NetFound = NetIterator.NextPCBObject
Wend
Board.BoardIterator_Destroy(NetIterator)
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
ReportFile.Close
Set ReportDocument = Client.OpenDocument("Text", FileName)
If Not (ReportDocument Is Nothing) Then
Client.ShowDocument(ReportDocument)
End If
EndHourGlass
End Sub
www.tdpcb.com
Sub ReportNets
Dim Board
Dim FileName
Dim ReportFile
Dim ReportDocument
Dim fso
BeginHourGlass
Set Board = PCBServer.GetCurrentPCBBoard
If Board is Nothing Then Exit Sub
FileName = Left(Board.FileName, InstrRev(Board.FileName, "\") ) & "ReportNets.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set ReportFile = fso.CreateTextFile(FileName, True)
NetIterator = Board.BoardIterator_Create
NetIterator.AddFilter_ObjectSet(MkSet(eNetObject))
NetIterator.AddFilter_LayerSet(AllLayers)
NetIterator.AddFilter_Method(eProcessAll)
Set NetFound = NetIterator.FirstPCBObject
While Not (NetFound Is Nothing)
Call ReportFile.WriteLine( NetFound.Name )
Set NetFound = NetIterator.NextPCBObject
Wend
Board.BoardIterator_Destroy(NetIterator)
Call AddStringParameter("Action", "Redraw")
RunProcess("PCB:Zoom")
ReportFile.Close
Set ReportDocument = Client.OpenDocument("Text", FileName)
If Not (ReportDocument Is Nothing) Then
Client.ShowDocument(ReportDocument)
End If
EndHourGlass
End Sub
www.tdpcb.com
Labels:
File,
Net,
PCB File Name,
Report
Subscribe to:
Posts (Atom)