8 Replies Latest reply on Jun 19, 2017 7:59 AM by Patrick.Cashman

    xPCB rearrange silcscreens Ref Des on PCB



      i am trying to develop application in c#, for rearrange silcscreens on TOP and BOTTOM of PCB.


      Basically it should be similair to this:

      Assembly and Silkscreen Ref Des rearrange


      I just need iterate through all components and slightly modify their silcs based upon some rules.

      But i can't do that.  I read a lot of articles here about automation here in xPCB. BUt still i can't reach my goal.


      I am using the template which i found here. I think it was developed by user Pattrick Cashman.


      in C# I can't load all silkscreen like this:


      Dim fabLayerTexts As MGCPCB.FabricationLayerTexts  
      fabLayerTexts = pcbDoc.FabricationLayerTexts(MGCPCB.EPcbFabricationType.epcbFabSilkscreen, MGCPCB.EPcbSelectionType.epcbSelectAll, MGCPCB.EPcbSide.epcbSideTopOrBottom, True)  


      And i can't do set their properties.

      I am also reading PCB Automation reference now, there is note that FabricationLayerTexts is property of Component object. But in this reference is it handled with that like with method i think. This is also error which i get in Visual Studio.


      I can read components form PCB and for example read some of their properties, but still i am not able to edit their silcs.


      cmps = (MGCPCB.Components)pcbdoc.Components;
      cmp = cmps[1];
      double x = cmp.AssemblyOriginX;
      double y = cmp.AssemblyOriginY;


      thank you for any help.


        • 1. Re: xPCB rearrange silcscreens Ref Des on PCB



          Check, if you allow "Allow Cell Graphic Edits". In 7.9.4 it is under Edit/Modify. In VX it is may be in Editor Control Panel.


          BR Michi

          • 2. Re: xPCB rearrange silcscreens Ref Des on PCB


            thank you for response, I already have it allowed.



            • 3. Re: xPCB rearrange silcscreens Ref Des on PCB

              Hi Josef,

              I quickly switched to VX2.1 and check my VB-Script. That runs without problems.

              I do nearly the same like you:


              Set fabtxts = docObj.FabricationLayerTexts(epcbFabSilkscreen, epcbSelectAll, epcbSideTopOrBottom, True)  'get a selection of all the fab layer texts


              and later:

              For Each fabtxt In fabtxts 'walk through all the fabrication layer texts


                  If Not fabtxt.Component Is Nothing Then 'if it is not text belonging to a component throw it out.  Like board level texts


                      fabtxt.Component.Selected = True 'select the component

                      Call docObj.ActiveView.SetExtentsToSelection(False, True)     'zoom into the component


                      '..... add your new Position Programming Code here


                      fabtxt.PositionX = PosX                            'fabtxt.Component.CenterX

                      fabtxt.PositionY = PosY + Round(dY,PRECISION)


                  End If





              BR Michi

              1 of 1 people found this helpful
              • 4. Re: xPCB rearrange silcscreens Ref Des on PCB

                Here is an example script like one I use for this kind of operation:


                     Sub adjust_silkscren_text()

                         Dim comps As MGCPCB.Components

                         Dim fabtxt_objs As MGCPCB.FabricationLayerTexts

                         Dim fabtxt_obj As MGCPCB.FabricationLayerText


                         comps = doc.Components(0, 4, 4)    '(all comps, general component type, package cell type)

                         For Each comp In comps

                             'Loop through all the Fab text on the component

                             fabtxt_objs = comp.FabricationLayerTexts

                             For Each fabtxt_obj In fabtxt_objs

                                 If fabtxt_obj.type = 2 Then 'check that the text type is silkscreen

                                     If fabtxt_obj.TextString = comp.RefDes Then 'select out the refdes text


                                         'do your formatting and position here

                                         'use fabtxt_obj.Format.xxxx to set height, orientation, font, etc


                                     End If

                                 End If

                             Next ' End of the Fab Text Loop


                     End Sub

                • 5. Re: xPCB rearrange silcscreens Ref Des on PCB

                  thank you guys, I really appreciate your effort. But those two scripts does not work for me. I don't know, what i am doing bad. in xPCB in scripting menu I created new script and try both of code snippets.  There weren't any syntax error, but i did not see any results. Also Step-ver function does not work, I can only run script with F5.


                  Honestly, i don't like VBS thats why I was asking for some example in C#. Any idea or suggestion?



                  okay, after a lot of attempts I can move Silc text like this:


                  MGCPCB.FabricationLayerTexts topSilcs;
                  MGCPCB.FabricationLayerText topSilc;
                  topSilcs = (MGCPCB.FabricationLayerTexts)pcbdoc.FabricationLayerTexts;
                  MGCPCB.Components cmps;
                  MGCPCB.Component cmp;
                  cmps = (MGCPCB.Components)pcbdoc.Components;
                  cmp = cmps[1];
                  topSilcs = cmp.FabricationLayerTexts;
                  topSilc = topSilcs[1];
                  double d = topSilc.PositionX;
                  topSilc.PositionX += 20;


                  in this way  I can modify X, Y position of RefDes on TOP and BOTTOM side.

                  But I don't know how to modify Angle, rotation


                  I can't see property for that even not in xPCB Automation reference documentation for FabricationLayerTexts.




                  Thank you very much.


                  • 6. Re: xPCB rearrange silcscreens Ref Des on PCB

                    The snippet I posted is from VB.net.  It could be translated to C# with either an IDE such as SharpDevelop or Visual Studio, or a number of online translators (google convert Vb.net to C#.net)


                    Also the bit I posted does not actually do anything.  The part in the middle:


                                             'do your formatting and position here

                                             'use fabtxt_obj.Format.xxxx to set height, orientation, font, etc


                    assumes that you would use the available formatting, move, and locations methods to do what you want with the silkscreen text.  We don't know what you want to do with them or what the rules are that you mentioned in your post above, so there is no way to give an example of this.


                    If you look in the help files for fabricationlayergfx you will find all the methods and properties available to modify the texts, move them, and so on.


                    Also I recently posted availability of a complete starter template for vb.net and VX.2.1 here. If you want the template for VX.1.2, get it here (my last post in that thread). With the subroutine above, the automation template, and some looking through the help files, you should be able to do what you want.  If you want C#, I have a VX.1.2 version template you can get here.




                    Just saw your latest edit - use the .format property to change font, height, orientation, etc.

                    1 of 1 people found this helpful
                    • 7. Re: xPCB rearrange silcscreens Ref Des on PCB

                      Hello Patrick,


                      thank you for your answer, led me to my solution.

                      I just wanted to modify X, Y , angle of choosen silk screen.

                      I know, that you first script "do nothing".  In your sample I omitted the format property. Sorry.


                      this working also in C#


                      topSilc.Format.Orientation += 2;


                      By the way, as i wrote in my first comment i was using your template, i think.




                      • 8. Re: xPCB rearrange silcscreens Ref Des on PCB

                        Excellent   Glad you got it working.