Showing posts with label Text. Show all posts
Showing posts with label Text. Show all posts

Thursday, July 14, 2011

Convert net labels to text Labels and vice versa

Click on a text label and it will be converted to a net label, click on a text label on it will be converted to a net label.

Sub Label2Text

If SchServer Is Nothing Then Exit Sub
Set CurrentSheet = SchServer.GetCurrentSchDocument
If CurrentSheet is Nothing Then Exit Sub

Call SchServer.ProcessControl.PreProcess(CurrentSheet, "")
Set Alocation = CurrentSheet.Location

While CurrentSheet.ChooseLocationInteractively(Alocation,"Select Label")

Set HitTest = CurrentSheet.CreateHitTest(eHitTest_AllObjects, ALocation)

If (HitTest.HitTestCount > 0) Then
  For I = 0 to (HitTest.HitTestCount-1)

    If HitTest.HitObject(I).ObjectId = eLabel Then
      Set SchLabel = SchServer.SchObjectFactory(eNetLabel,eCreate_GlobalCopy)
      SchLabel.FontID = HitTest.HitObject(I).FontID
      Schlabel.Text = HitTest.HitObject(I).Text
      Schlabel.Location = HitTest.HitObject(I).Location
      CurrentSheet.RegisterSchObjectInContainer(SchLabel)
      CurrentSheet.GraphicallyInvalidate
      CurrentSheet.RemoveSchObject(HitTest.HitObject(I))
      Call SchServer.RobotManager.SendMessage(CurrentSheet.I_ObjectAddress,_
      c_BroadCast,SCHM_PrimitiveRegistration,HitTest.HitObject(I).I_ObjectAddress)

    ElseIf HitTest.HitObject(I).ObjectId = eNetLabel Then

      Set SchLabel = SchServer.SchObjectFactory(eLabel,eCreate_GlobalCopy)
      SchLabel.FontID = HitTest.HitObject(I).FontID
      Schlabel.Text = HitTest.HitObject(I).Text
      Schlabel.Location = HitTest.HitObject(I).Location
      CurrentSheet.RegisterSchObjectInContainer(SchLabel)
      CurrentSheet.RemoveSchObject(HitTest.HitObject(I))
      CurrentSheet.GraphicallyInvalidate
      Call SchServer.RobotManager.SendMessage(CurrentSheet.I_ObjectAddress,_
      c_BroadCast,SCHM_PrimitiveRegistration,HitTest.HitObject(I).I_ObjectAddress)

    End If

  Next

End If
Wend

Call SchServer.ProcessControl.PostProcess(CurrentSheet, "")
CurrentSheet.GraphicallyInvalidate

End Sub



www.tdpcb.com

Tuesday, May 24, 2011

Open a text file and read the contents line by line.

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