Print Page | Close Window

Altium Special Strings

Printed From: PCB Libraries Forum
Category: PCB Footprint Expert
Forum Name: Product Suggestions
Forum Description: request new features
URL: https://www.PCBLibraries.com/forum/forum_posts.asp?TID=1634
Printed Date: 25 Nov 2024 at 3:34am


Topic: Altium Special Strings
Posted By: gcary
Subject: Altium Special Strings
Date Posted: 04 Apr 2015 at 12:54am
In Altium there are special strings that can be added to a footprint.  In particular there are two I would like to see added.  They are ".Comment" and ".Designator".  I would envision a check box for each one, and the state of the check would be included in the user preferences for Altium output.  If checked, then the special text string would be included in the footprint, otherwise it would be omitted. Here is a video that describes it:

Altium design secret 11: How to add comments and designators to specific layers:
http://www.newelectronics.co.uk/electronics-videos/altium-design-secret-11-how-to-add-comments-and-designators-to-specific-layers/47001/" rel="nofollow - http://www.newelectronics.co.uk/electronics-videos/altium-design-secret-11-how-to-add-comments-and-designators-to-specific-layers/47001/

Here is the Altium documentation for Special Strings on a PCB:
http://techdocs.altium.com/display/ADRR/PCB_Obj-String%28%28String%29%29_AD" rel="nofollow - http://techdocs.altium.com/display/ADRR/PCB_Obj-String%28%28String%29%29_AD

Thanks,

Greg



Replies:
Posted By: gcary
Date Posted: 04 Apr 2015 at 3:05am
I just thought of a much better option, and much easier for you to implement.  I forgot that adding text isn't as simple as adding a text string.  You have to set the width, height, position, etc.  So instead of you doing that, you could have an option to call a user-defined procedure.  I just tested it and it works great.  Adding this will allow the user to do practically anything they want to after the component has been built.

You would have a check box that would allow the user to enable the user-defined script or not.  If the box is checked, you would add the following line at the end of your script that creates the component:

PCBLibrariesUserScript(NewPCBLibComp);

In Altium, the user will need to create a script project that has the script in it.  The script project needs to be global.  To do that, simply go to DXP ยป Preferences.  Then choose Scripting System, and then Global Projects.  Add the project and then your script will be able to call it.

The user-defined script would look something like this:

Procedure PCBLibrariesUserScript(NewPCBLibComp : IPCB_LibComponent);
Var
    TextObj : IPCB_Text;

Begin
    // Create text object for .Designator
    TextObj := PCBServer.PCBObjectFactory(eTextObject, eNoDimension, eCreate_Default);
    TextObj.UseTTFonts := True;
    TextObj.Layer := eMechanical5;
    TextObj.Text := '.Designator';
    TextObj.Size := MilsToCoord(40);

    NewPCBLibComp.AddPCBObject(TextObj);
    PCBServer.SendMessageToRobots(NewPCBLibComp.I_ObjectAddress,c_Broadcast,PCBM_BoardRegisteration,TextObj.I_ObjectAddress);
End;


I think this would be a great addition because of its simplicity and its power.

Thanks,

Greg


Posted By: sacherjj
Date Posted: 07 Apr 2015 at 11:38am
I am in the process of starting a clean DBlib for Altium using PCBLibraries.  I was just trying to figure out the easiest method adding the .Designator objects.  This really helps with output documentation. 

I have been trying to figure out if it is possible to get currently selected component in a PCBLib, but I'm not finding any way.  I was trying to slightly modify your script so I could run it on the selected IPCB_LibComponent as a work around.

It looks like the only way would be iterating through all in a library and adding.  But that only works cleanly once.  It might be possible to iterate through the objects and make sure there is no TextObj with .Text of '.Designator'.  Not very clean, but it might work.

Edit: Oh, and I should have said that I think an option to call a user script would be great.  This would be a good testing ground of optional scripting that might make it back into the Library Export as an optional Altium functionality.  (Like I would love to see .Designator exist.)


Posted By: gcary
Date Posted: 07 Apr 2015 at 1:05pm
I'm glad you like the idea of a user script.  It would be a great addition because it gives the user the ability to do whatever they want automatically as each footprint is generated.  And the good part from the PCBLibraries side is that it is very simple to implement.

I love DBLib's.  I struggled for quite a while when I first got Altium Designer, trying to figure out which is the best format for libraries.  I'm really glad I settled on DBLibs.  All of my components are in that format.  It makes it so much easier to manage the footprints and schematic symbols.

The night I posted that first message in this thread I also tried to modify an existing component.  I could not get it to work.  The functions work fine when you create a new component, but not when you try to modify and existing component.  I have been planning on posting a question in the Altium forum, but I haven't had time to do it yet.  Here is the file I plan to post for those guys to look at:

Procedure AddTextToNewFootprint;
Var
    CurrentLib  : IPCB_Library;
    View        : IServerDocumentView;
    Document    : IServerDocument;
    Footprint   : IPCB_LibComponent;
    TextObj     : IPCB_Text;
Begin
    If PCBServer = Nil Then Exit;

    CurrentLib := PcbServer.GetCurrentPCBLibrary;
    If CurrentLib = Nil Then Exit;

    View := Client.GetCurrentView;
    Document := View.OwnerDocument;
    Document.Modified := True;

    CurrentLib.Board.LayerIsDisplayed[ILayer.MechanicalLayer(6)] := true;

    PCBServer.PreProcess;

    Try
        Footprint := PCBServer.CreatePCBLibComp;
        Footprint.Name := 'NewFootprint';

        TextObj := PCBServer.PCBObjectFactory(eTextObject,  eNoDimension,  eCreate_Default);
        PCBServer.SendMessageToRobots(TextObj.I_ObjectAddress, c_Broadcast, PCBM_BeginModify, c_NoEventData);

        TextObj.UseTTFonts := True;
        TextObj.Layer := ILayer.MechanicalLayer(6);
        TextObj.Text  := '.Designator';
        TextObj.Size  :=  MilsToCoord(40);
        Footprint.AddPCBObject(TextObj);

        PCBServer.SendMessageToRobots(TextObj.I_ObjectAddress, c_Broadcast, PCBM_EndModify, c_NoEventData);
        PCBServer.SendMessageToRobots(Footprint.I_ObjectAddress, c_Broadcast, PCBM_BoardRegisteration, TextObj.I_ObjectAddress);

        CurrentLib.RegisterComponent(Footprint);
        CurrentLib.CurrentComponent := Footprint;
    Finally
        PCBServer.PostProcess;
    End;

    CurrentLib.Board.ViewManager_FullUpdate;
    Client.SendMessage('PCB:Zoom', 'Action=All' , 255, Client.CurrentView);
End;


Procedure AddTextToExistingFootprint;
Var
    CurrentLib  : IPCB_Library;
    View        : IServerDocumentView;
    Document    : IServerDocument;
    Footprint   : IPCB_LibComponent;
    TextObj     : IPCB_Text;
Begin
    If PCBServer = Nil Then Exit;

    CurrentLib := PcbServer.GetCurrentPCBLibrary;
    If CurrentLib = Nil Then Exit;

    View := Client.GetCurrentView;
    Document := View.OwnerDocument;
    Document.Modified := True;

    CurrentLib.Board.LayerIsDisplayed[ILayer.MechanicalLayer(6)] := true;

    PCBServer.PreProcess;

    Try
        Footprint := CurrentLib.CurrentComponent;
        Footprint.BeginModify;

        TextObj := PCBServer.PCBObjectFactory(eTextObject,  eNoDimension,  eCreate_Default);
        PCBServer.SendMessageToRobots(TextObj.I_ObjectAddress, c_Broadcast, PCBM_BeginModify, c_NoEventData);

        TextObj.UseTTFonts := True;
        TextObj.Layer := ILayer.MechanicalLayer(6);
        TextObj.Text  := '.Designator';
        TextObj.Size  :=  MilsToCoord(40);
        Footprint.AddPCBObject(TextObj);

        PCBServer.SendMessageToRobots(TextObj.I_ObjectAddress, c_Broadcast, PCBM_EndModify, c_NoEventData);
        PCBServer.SendMessageToRobots(Footprint.I_ObjectAddress, c_Broadcast, PCBM_BoardRegisteration, TextObj.I_ObjectAddress);
        Footprint.EndModify;
    Finally
        PCBServer.PostProcess;
    End;

    CurrentLib.Board.ViewManager_FullUpdate;
    Client.SendMessage('PCB:Zoom', 'Action=All' , 255, Client.CurrentView);
End;


Procedure AddTextToBoard;
Var
    View      : IServerDocumentView;
    Document  : IServerDocument;
    TextObj   : IPCB_Text;
    Board     : IPCB_Board;
Begin
    If PCBServer = Nil Then Exit;

    Board := PcbServer.GetCurrentPCBBoard;
    If Board = Nil Then Exit;

    View := Client.GetCurrentView;
    Document := View.OwnerDocument;
    Document.Modified := True;

    Board.LayerIsDisplayed[ILayer.MechanicalLayer(6)] := true;

    PCBServer.PreProcess;

    Try
        TextObj := PCBServer.PCBObjectFactory(eTextObject,  eNoDimension,  eCreate_Default);

        PCBServer.SendMessageToRobots(TextObj.I_ObjectAddress, c_Broadcast, PCBM_BeginModify, c_NoEventData);

        TextObj.UseTTFonts := True;
        TextObj.Layer := ILayer.MechanicalLayer(6);
        TextObj.Text  := 'BoardText';
        TextObj.Size  :=  MilsToCoord(40);
        TextObj.XLocation := MilsToCoord(1500);
        TextObj.YLocation := MilsToCoord(1500);
        Board.AddPCBObject(TextObj);

        PCBServer.SendMessageToRobots(TextObj.I_ObjectAddress, c_Broadcast, PCBM_EndModify, c_NoEventData);
        PCBServer.SendMessageToRobots(Board.I_ObjectAddress, c_Broadcast, PCBM_BoardRegisteration, TextObj.I_ObjectAddress);
    Finally
        PCBServer.PostProcess;
    End;

    Board.ViewManager_FullUpdate;
    Client.SendMessage('PCB:Zoom', 'Action=All' , 255, Client.CurrentView);
End;

End.


You will see the following line is how you access the current library component:
 Footprint := CurrentLib.CurrentComponent;

I'm not an expert in Altium scripting, so I might be doing something wrong.  I am hoping I am missing some magic that allows the object to be editable or something like that.

When you run these scripts, you will find the AddTextToBoard and AddTextToNewFootprint procedures work properly, but the AddTextToExistingFootprint does not.  Notice that the number of primitives shown in the PCB Library window increments after you run the script.  If you get a PCB List, the primitives don't show up.  It isn't just a text issue either.  I tried generating a pad as well without success (though the number of primitives increments as well).  One last point is that I also tried capturing the name of the current footprint, and then using an iterator to march through the components until I found it, and then tried modifying it.  Same results.  At this point the only viable methods would be the user script that I proposed, or to manually add it to each footprint.  The latter is not a terribly bad option since it doesn't take a lot of time to paste it.  It needs a little sizing and position help anyway.  But it sure would be nice to have to automatically generated.

I hope this helps you out.  Maybe you will be able to figure out the magic needed to modify an existing component.

Greg


Posted By: sacherjj
Date Posted: 07 Apr 2015 at 7:34pm
I'll take a look at that script in the morning.  I'm the sole engineer and designer in our company, so I started with an integrated library.  Duplicating schematic items to make a new resistor value.  But, it was all in files so it seemed simpler.  However, compiling started to take forever.

I wish I had switched to DBLib a while ago.  However, now is a good time to get the new designs started in DBLib and migrate the old later.  It is amazing how fast it is to make footprints in this software.  Then adding new resistors is another db row. 

I'm an Altium scripting newbie as well, but a very experienced programmer.  The Pascal feel of Delphi script brings back memories from the mid-90s.  I need to spend some time wrapping my head around the Altium APIs. 



Print Page | Close Window