8 Replies Latest reply on Nov 19, 2014 10:36 PM by syhaunguyen

    AATK - Manufacturing - Move Assy Ref

    kazy

      I'm trying to use the function to move the Assembly Ref text to the center of the part using AATK_V3.0 for EXP2005.3.

      But I got the following Error.

      error-move-assy.bmp

      What should I change or is there any setting ?

       

      Thank you.

        • 1. Re: AATK - Manufacturing - Move Assy Ref
          kazy

          'Option Explicit

           

          '

          ' The example below demonstrates the element manipulations

          ' on a fabrication layer text.

          ' It moves all the assembly text to the origin and changes the height and orientation

          ' ====================================================================

          '

          ' Testing code for the sample

          '

          main

          'MsgBox "Under construction open with VB6.0"

           

          Sub main()

              ' On Error Resume Next

           

              Dim app 'As MGCPCB.Application

              Set app = Application

              'Set app = GetObject(, "MGCPCB.Application")

               

              Dim docObj 'As MGCPCB.Document

           

              Dim fabtxts 'As FabricationLayerTexts

              Dim fabtxt 'As FabricationLayerText

              Dim cnt, ori, dx, dy, pa, x, y, z, sorted, TheArray, Temp

              Dim place 'As PlacementOutline

              Dim places 'As PlacementOutlines

               

              ' collect document object

              Set docObj = GetLicensedDoc(app)

           

              If (docObj Is Nothing) Then Exit Sub

           

              dim size

           

                 size = app.Gui.InputBox("What size text", size, .2)

               'size=.2

              

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

              cnt = fabtxts.Count

          msgbox cnt

           

              Call app.Gui.ProgressBarInitialize(True, "Progess", cnt, 0) 'initialize the progress bar from o to cnt

              cnt = 0

           

              'docObj.TransactionStart (epcbDRCModeDRC) ' make all the moves one single undable action

              app.LockServer 'speed up the process by locking the server

           

              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

                   

                      Set places = docObj.PlacementOutlines(epcbSelectSelected)

           

                      'docObj.ActiveView.SetExtentsToSelection

           

                      For Each place In places  ' find the outside of the component to move the silkscreen text to

                          'pa = place.Geometry.PointsArray

                          pa = place.Geometry.Outline

                      

                          sorted = False

           

                          Do While Not sorted

                              sorted = True

           

                              For x = 0 To UBound(pa, 2) - 1

           

                                  If pa(0, x) > pa(0, x + 1) Then

                                      Temp = pa(0, x + 1)

                                      pa(0, x + 1) = pa(0, x)

                                      pa(0, x) = Temp

                                      sorted = False

                                  End If

           

                              Next

           

                          Loop

                      

                          dx = (pa(0, UBound(pa, 2)) - pa(0, 0)) / 2

                     

                          sorted = False

           

                          Do While Not sorted

                              sorted = True

           

                              For y = 0 To UBound(pa, 2) - 1

           

                                  If pa(1, y) > pa(1, y + 1) Then

                                      Temp = pa(1, y + 1)

                                      pa(1, y + 1) = pa(1, y)

                                      pa(1, y) = Temp

                                      sorted = False

                                  End If

           

                              Next

           

                          Loop

                      

                          dy = (pa(1, UBound(pa, 2)) - pa(1, 0)) / 2

                       

                      Next

                  

                      ori = fabtxt.Component.Orientation

                   

                      fabtxt.Format.VerticalJust = epcbJustifyVCenter

                      fabtxt.Format.HorizontalJust = epcbJustifyHCenter

           

                      If ori = 0 Or ori = 180 Then

                          fabtxt.Format.Orientation(epcbAngleUnitDegrees) = 0 'if the text is rotated at 0 or 180 make it 0

           

                          If fabtxt.Type = epcbFabSilkscreen Then

                              fabtxt.Format.Height(epcbUnitMM) = size

                              Call fabtxt.Move(fabtxt.Component.AssemblyOriginX, fabtxt.Component.AssemblyOriginY + dy) 'Offset in y direction

                       

                          End If

           

                          If fabtxt.Type = epcbFabAssembly Then

                              fabtxt.Format.Height(epcbUnitMM) = size 'dy

                              Call fabtxt.Move(fabtxt.Component.AssemblyOriginX, fabtxt.Component.AssemblyOriginY) ' + dy, epcbUnitMils)

                          End If

                       

                      Else

                          fabtxt.Format.Orientation(epcbAngleUnitDegrees) = 90

           

                          If fabtxt.Type = epcbFabSilkscreen Then

                              fabtxt.Format.Height(epcbUnitMM) = size

                              'Call fabtxt.Move(fabtxt.Component.AssemblyOriginX + dx, fabtxt.Component.AssemblyOriginY, epcbUnitMils)

                              Call fabtxt.Move(fabtxt.Component.AssemblyOriginX + dx, fabtxt.Component.AssemblyOriginY) 'Offset in x direction

                          End If

           

                          If fabtxt.Type = epcbFabAssembly Then

                              fabtxt.Format.Height(epcbUnitMM) = size 'dx

                              'Call fabtxt.Move(fabtxt.Component.AssemblyOriginX + dx, fabtxt.Component.AssemblyOriginY, epcbUnitMils)

                              Call fabtxt.Move(fabtxt.Component.AssemblyOriginX, fabtxt.Component.AssemblyOriginY) ', epcbUnitMils)

                          End If

                       

                      End If

                   

                      app.Gui.ProgressBar (cnt)

                      cnt = cnt + 1

               

                      fabtxt.Component.Selected = False

                  End If

           

              Next

           

              app.UnlockServer 'unlock the server

           

              'docObj.TransactionEnd (True) 'end the make it all one undo

              app.Gui.ProgressBarInitialize (False)

          End Sub

           

          '

          ' This function retrieves an automation license for a document

          '

          ' Returns:

          '   - 'Nothing' if licensing failed .

          '   - A reference to the active document of the application if

          '     licensing succeeded.

          '

          Public Function GetLicensedDoc(app)

              On Error Resume Next

              Dim key, licenseServer, licenseToken, docObj

           

              Set GetLicensedDoc = Nothing

           

              ' collect the active document

              Set docObj = app.ActiveDocument

           

              If (Err) Then

                  Call app.Gui.StatusBarText("No active document: " + Err.Description, epcbStatusFieldError)

                  Exit Function

              End If

           

              ' Ask Expedition’s document for the key

              key = docObj.Validate(0)

           

              ' Get token from license server

              Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")

              licenseToken = licenseServer.GetToken(key)

              Set licenseServer = Nothing

           

              ' Ask the document to validate the license token

              Err.Clear

           

              docObj.Validate (licenseToken)

           

              If (Err) Then

                  Call app.Gui.StatusBarText("No active document license: " + Err.Description, epcbStatusFieldError)

                  Exit Function

              End If

           

              ' everything is OK, return document

              Set GetLicensedDoc = docObj

           

          End Function

           

          • 2. Re: AATK - Manufacturing - Move Assy Ref
            fagrondin

            Hi,

             

            Have you tried changing MGCPCB.application by your application for example :

             

            MGCPCB.



            FablinkXEApplication

             

            or

             

            MGCPCB.

            ExpeditionPCBApplication

             

            Regards

             

            Fred



            • 3. Re: AATK - Manufacturing - Move Assy Ref
              kazy

              Hi Fred,

               

               

              Many thanks for your info!

               

              I've tried as below but I got the same message.

               

               

              Dim app 'As MGCPCB.ExpeditionPCB

              Set app = application 'GetObject(, "MGCPCB.ExpeditionPCB")

               

              I got the modified script from the author

               

              Thank you and Best regards,

              Kazy

               

               

               

               

               

               

               

               

              • 4. Re: AATK - Manufacturing - Move Assy Ref
                ed_smith

                I believe there is an error in the Script. I believe the line:

                 

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

                 

                Should read:

                 

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

                 

                Regards, Ed

                • 5. Re: AATK - Manufacturing - Move Assy Ref
                  kendall_hiles

                  It is the transaction start and end causing the problem not the lockserver commands.

                   

                      'docObj.TransactionStart (epcbDRCModeDRC) ' make all the moves one single undable action
                      app.LockServer 'speed up the process by locking the server

                   

                      app.UnlockServer 'unlock the server

                      'docObj.TransactionEnd (True) 'end the make it all one undo

                   

                   

                  To center the parts take away the Dx and Dy in fact you can make the whole script smaller if you don't care about the part boundries.

                   

                  If ori = 0 Or ori = 180 Then
                                  fabtxt.Format.Orientation(epcbAngleUnitDegrees) = 0 'if the text is rotated at 0 or 180 make it 0

                                  If fabtxt.Type = epcbFabSilkscreen Then
                                      fabtxt.Format.Height(epcbUnitMM) = size
                                      Call fabtxt.Move(fabtxt.Component.AssemblyOriginX, fabtxt.Component.AssemblyOriginY + dy) 'Offset in y direction
                             
                                  End If

                                  If fabtxt.Type = epcbFabAssembly Then
                                      fabtxt.Format.Height(epcbUnitMM) = size 'dy
                                      Call fabtxt.Move(fabtxt.Component.AssemblyOriginX, fabtxt.Component.AssemblyOriginY) ' + dy, epcbUnitMils)
                                  End If
                             
                              Else
                                  fabtxt.Format.Orientation(epcbAngleUnitDegrees) = 90

                                  If fabtxt.Type = epcbFabSilkscreen Then
                                      fabtxt.Format.Height(epcbUnitMM) = size
                                      Call fabtxt.Move(fabtxt.Component.AssemblyOriginX + dx, fabtxt.Component.AssemblyOriginY) 'Offset in x direction
                                  End If

                                  If fabtxt.Type = epcbFabAssembly Then
                                      fabtxt.Format.Height(epcbUnitMM) = size 'dx
                                      Call fabtxt.Move(fabtxt.Component.AssemblyOriginX, fabtxt.Component.AssemblyOriginY) ', epcbUnitMils)
                                  End If
                             
                              End If

                  • 6. Re: AATK - Manufacturing - Move Assy Ref
                    kazy

                    Hi Ed,

                     

                    Thank you for the comment

                    I've modified

                      If Not (fabtxt.Component)

                    but it didn't change the behavior.

                     

                     

                    Best regards,

                    Kazy

                    • 7. Re: AATK - Manufacturing - Move Assy Ref
                      kazy

                      Hi Kendall,

                       

                      Thanks for the Info, it works well after I commented out the two lines

                       

                           'docObj.TransactionStart (epcbDRCModeDRC) ' make all the moves one single undable action
                          app.LockServer 'speed up the process by locking the server

                       

                          app.UnlockServer 'unlock the server

                          'docObj.TransactionEnd (True) 'end the make it all one undo

                       

                      Best regards,

                      Kazy

                      • 8. Re: AATK - Manufacturing - Move Assy Ref
                        syhaunguyen

                        Hi Kazy,

                         

                        It isn't run with EE 7.9.4

                        Please, let me know how to fix it.

                         

                        Best regards,

                        Syhau