Friday, April 29, 2011

Create a Schematic pin in a library part

Places a pin in a schematic library part. Open a schematic library (or create a new one.)  Run script and in the current part a pin will be placed.

Sub PlacePin

Set CurrentLib = SchServer.GetCurrentSchDocument
If CurrentLib is Nothing Then Exit Sub
If CurrentLib.ObjectID <> eSchLib Then Exit Sub

Set SchComponent = SchServer.SchObjectFactory(eSchComponent, eCreate_Default)
'Set up parameters for the library component.
SchComponent.CurrentPartID = 1
SchComponent.DisplayMode = 0

'Create pin objects for the new library component.
P1 = SchServer.SchObjectFactory(ePin,eCreate_GlobalCopy)

If P1 is Nothing Then Exit Sub
'Define the pin parameters.
P1.Location = Point(MilsToCoord(250), MilsToCoord( -250 ))
P1.Orientation = eRotate180
P1.PinLength = MilsToCoord(250)
P1.Designator = "1"
P1.Name = "Pin Name"
P1.Electrical = Etype(4)  '4=Passive
P1.OwnerPartId = CurrentLib.CurrentSchComponent.CurrentPartID
P1.OwnerPartDisplayMode = CurrentLib.CurrentSchComponent.DisplayMode

SchComponent.AddSchObject(P1)
CurrentLib.RegisterSchObjectInContainer(P1)

'Send a system notification that a new component has been added to the library.
Call AddStringParameter("Action", "Redraw")
RunProcess("SCH:Zoom")

Call SchServer.RobotManager.SendMessage(nil, c_BroadCast, SCHM_PrimitiveRegistration,_ SCHComponent.I_ObjectAddress)

Set CurrentLib.CurrentSchComponent = SchComponent
'Refresh library.
CurrentLib.GraphicallyInvalidate

End Sub



============================
FYI - Electrical definitions for the pin type:
0=Input
1=I/O
2=Output
3=Open Collector
4=Passive
5=HiZ
6=Open Emitter
7=Power



http://www.tdpcb.com/