5 Replies Latest reply on Aug 22, 2013 2:36 AM by ashkolnik

    How do I delete a User Layer

    jwe

      Hallo,

       

      It is indeed possible to create a User Layer, but how do I delete these again?

       

      create a User Layer:

      Set usrLyrObj = pcbDocObj.SetupParameter.PutUserLayer(userLayerNameStr)

       

      delete a User Layer:

      ???

       

      Thanks much!

      Jo

        • 1. Re: How do I delete a User Layer
          Patrick.Cashman

          Public Sub delete_user_layer(ul_name as String, pcbDocObj as MGCPCB.Document)

               Dim uls As MGCPCB.UserLayers

               Dim ul As MGCPCB.UserLayer

           

               uls = pcbDocObj.UserLayers

               For Each ul In uls

                    If ul.Name = ul_name Then

                         ul.Delete

                    End If

               Next

          End Sub

          • 2. Re: How do I delete a User Layer
            Satoru

            Hi,

             

            Dim usrLay as UserLayer

            Set usrLay = pdbDoc.FindUserLayer(strUserLayerName)

            If Not usrLay Is Nothing Then

                Call usrLay.Delete

            End If

             

            Regards,

            Satoru

            1 of 1 people found this helpful
            • 3. Re: How do I delete a User Layer
              jwe

              Hi Patrick & Satoru

               

              thank you for your answers. So I have found the solution.

              Here is the code as vbScript:

               

               

              Dim pcbDocObj                              ' Document object

              Set pcbDocObj = pcbAppObj.ActiveDocument   ' Get the active document

               

              Function DeleteUserLayer(userLayerNameStr)
                  Dim usrLyrObj
                  set usrLyrObj = pcbDocObj.FindUserLayer(userLayerNameStr)

                  If usrLyrObj Is Nothing Then
                     ' It doesn't exist - do nothing.
                  Else

                     ' If it does exists, then delete it now
                     usrLyrObj.delete 

                  End If

              End Function

               

               

              With best regards

              Jo

              • 4. Re: How do I delete a User Layer
                ashkolnik

                Hi JWE ,

                You have a problem with this script cause if you will have a poligon or line on layer that you want to delete script will collapse .

                Thanks.

                • 5. Re: How do I delete a User Layer
                  ashkolnik

                  Hi JWE again ,

                  Here is solution :

                   

                  Sub Delete_layer(layer_name)

                       Dim i : i=1

                       Dim layersObj : Set layersObj = pcbDocObj.UserLayerGfxs(epcbSelectAll,layer_name,False)

                       Dim layerObj : Set layerObj = pcbDocObj.FindUserLayer(layer_name)

                       If layerObj Is Nothing Then

                            Exit Sub

                       End if

                       Set layerObj = layersObj.Item(i)

                       Do until layerObj Is Nothing

                            layerObj.delete

                            i=i+1

                            Set layerObj = layersObj.Item(i)

                       Loop

                       Set layerObj = pcbDocObj.FindUserLayer(layer_name)

                       layerObj.delete

                  End Sub

                   

                  Thanks.