2 Replies Latest reply on Apr 9, 2013 1:26 PM by andrew.french

    Check and set the visibility of an attribute

    gerrythompson

      In the following script I can find all the components which have an attribute called "DNI" and that attribute has a value of "DNI".

      What I would like to do  is determine if the "DNI" attribute is visible and set it visible if it is not.

       

      How do I do this?

       

      Gerry

       

      Sub Main

          fname = ActiveDocument

              If fname = "" Then fname = "Untitled"

          sFilePath = "C:\temp"

          report = sFilePath & "\" & "checkDNI.txt"

          Open report For Output As #1

          'Output report header

          Print #1, "'Check DNI's "; fname; " on "; Now

          Print #1, "'"

          index = 0

          Dim nextComp As Object

          Dim nextAttr As Object

          For Each nextComp In ActiveDocument.Components

              If Not nextComp.Attributes("DNI") Is Nothing Then

                  If Len(nextComp.Attributes("DNI").Value) = "DNI" Then

                      Print #1, nextComp.Name;", ";nextComp.PartType;", ";nextComp.Attributes("DNI").Value

                  End If

              End If

              index =index+1

          Next nextComp

          Print #1

          Print #1, "Checked ";index;" parts on schematic "; fname

          Close #1

          Shell "Notepad " & Chr(34) & report & Chr(34), 1

      End Sub

        • 1. Re: Check and set the visibility of an attribute
          gerrythompson

          I have a version which work for most cases now but it assumes that the DNI attribute is second in the list of visibility attributes which is not always the case.

           

          Sub Main

              fname = ActiveDocument

                  If fname = "" Then fname = "Untitled"

              sFilePath = "C:\temp"

              report = sFilePath & "\" & "checkDNI.txt"

              Open report For Output As #1

              'Output report header

              Print #1, "'Check DNI's "; fname; " on "; Now

              Print #1, "'"

              index = 0

              Dim nextComp As Object

              For Each nextComp In ActiveDocument.Components

                  If Not nextComp.Attributes("DNI") Is Nothing Then

                      If nextComp.Attributes("DNI").Value = "DNI" Then

                          ActiveDocument.Components(nextComp.Name).selected = True

                          RunMacro("G:\Engineering\PwrpcbV9Lib\scripts" & "\makeDNI_Visible.mcr", "makeDNI_Visible")

                          Print #1, nextComp.Name;", ";nextComp.PartType;", ";nextComp.Attributes("DNI").Value

                          ActiveDocument.Components(nextComp.Name).selected = False

                      End If

                  End If

                  index =index+1

              Next nextComp

              Print #1

              Print #1, "Checked ";index;" parts on schematic "; fname

              Close #1

              Shell "Notepad " & Chr(34) & report & Chr(34), 1

          End Sub

           

          Macro:

           

          Application.ExecuteCommand("Query Part Text Visibility")

          DlgQueryPartChangeDisplay.AttrsList.Checked(1) = true

          DlgQueryPartChangeDisplay.Ok.Click()

          • 2. Re: Check and set the visibility of an attribute
            andrew.french

            This is what I do, code is in vb.net

             

            Private Sub writeAttr(ByVal attributeName As String, ByVal value As String, ByVal comp As ViewDraw.Component)

                    'Write the gathered information to the part in DxDesigner

                    Dim attr As ViewDraw.Attribute

                    attr = comp.FindAttribute(attributeName)

             

                    'Create the attribute if it does not exist already

                    If attr Is Nothing Then

                        attr = comp.AddAttribute(attributeName, 0, 0, ViewDraw.VdVisibilityFlag.VDINVISIBLE)

                    End If

             

                    Try

                        attr.Value = value

                    Catch ex As Exception

                        'Setting the value failed do something here

                    End Try

             

             

                End Sub