5 Replies Latest reply on Jul 27, 2011 6:26 AM by andrew_french

    Update Border Properties with Automation


      I've got a script that runs when a DxDesigner project is opened and it is supposed to update certain properties associated with the sheet border(s).


      The script works only once I've manually changed a property in Dx from the default value built into the library symbol.  If I leave the value unedited the script runs fine and throws no errors but the value is never updated.  Feel like its a bug in the automation implementation but figured I'd post up in here just to have my code checked/verified first.


      EE7.9.1 update 1

      Code is in VB.net  (Haven't figured out how to traverse sheets in C# yet...)



      Private Sub writeData()


      Dim schmObj As ViewDraw.IStringList

      Dim sheetObj As ViewDraw.IStringList

      Dim compObj As ViewDraw.IVdObjs

      Dim comp As ViewDraw.Component

      Dim fail As Boolean = True

      Dim origin As ViewDraw.IVdPoint

      VdApp.Visible = False

      VdApp.AppendOutput("Output", "Updating Border Properties...")


      'Get the collection of schematic in the project

      schmObj = VdApp.SchematicSheetDocuments.GetAvailableSchematics


      'Iterate throught the collection of schematics

      For x = 1 To schmObj.GetCount


           'Get the collection of sheets in the current schematic

           sheetObj = VdApp.SchematicSheetDocuments.GetAvailableSheets(schmObj.GetItem(x))


           'Iterate through the collection of sheets

           For y = 1 To sheetObj.GetCount


                'Open the sheet

                VdApp.SchematicSheetDocuments.Open(schmObj.GetItem(x), sheetObj.GetItem(y))


                'Get the collection of components on the sheet

                compObj = VdApp.Query(ViewDraw.VdObjectTypeMask.VDM_COMP, ViewDraw.VdAllOrSelected.VD_ALL)


                'Iterate through the collection of components

                For z = 1 To compObj.Count

                     comp = compObj.Item(z)


                     'Get the location of the current component

                     'Only care about the border here and it will always have a location of (0,0)

                     origin = comp.GetLocation


                     If origin.X = 0 Then

                          If origin.Y = 0 Then

                               fail = setAttribute(comp, "cad_ident", VdApp.Version, x, y)

                               z = compObj.Count

                          End If

                     End If









      If fail = False Then

           VdApp.AppendOutput("Output", "BorderFill Script completed with errors, Please view the BorderFill log: File -> File Viewer")


           VdApp.AppendOutput("Output", "BorderFill Script completed successfully!")

           writer.WriteLine("BorderFill Script completed successfully!")


      End If

      VdApp.Visible = True


      End Sub


      Private Function setAttribute(ByVal c As ViewDraw.Component, ByVal attrName As String, ByVal attrValue As String, ByVal x As Integer, ByVal y As Integer) As Boolean


      Dim attr As ViewDraw.Attribute

      setAttribute = True



           attr = c.FindAttribute(attrName)

           attr.Value = attrValue

      Catch ex As Exception

           writer.WriteLine("Property '" & attrName & "' FAILED to update on schematic " & x & " sheet " & y)

           setAttribute = False


      End Try


      End Function





        • 1. Re: Update Border Properties with Automation

          Okay so I figured out what was going on here, the code is fine just some quirkiness in Dx causing unneeded grief.  I started by modifying properties on my border symbol in symbol editor.  Then in my already existing Dx project I needed to read in my changes but I wanted the new default values for the properties so I used the replace symbol command and selected the radio button for having the Library values win out.  Once you replace the symbol this way if you look at the properties for the border in the properties window all the values now show up in italics.  When these values are in italics they are not editable via script.  You have to manually change the value then it will no longer be in italics and it is now editable via script.

          • 2. Re: Update Border Properties with Automation



            Try changing your setAttribute function to call AddAttribute on the component if FindAttribute fails to find the attribute.



            • 3. Re: Update Border Properties with Automation

              Okay that works but it doesn't make any sense to me.  The property is defined in the property definition editor and it indeed exists on my border, so why does it behave like its not there and only work with the addattribute command?

              • 4. Re: Update Border Properties with Automation

                Component.FindAttributes only looks at component attributes, not at the underlying symbol attributes.  If you need to look at the symbol attributes, get the SymbolBlock property of the component, and call the FindAttributes method.


                The Properties window shows symbol attribute values in italics, component attribute values in regular font, and instance values with another indicator.  The properties window also shows the symbol and block and instance values when you select a particular property.


                Some confusion could be coming from the terminology used by the automation interface which differs from the terminology used by 2007.x user interface. 



                • 5. Re: Update Border Properties with Automation

                  Sounds like I need to educate myself on what the actual differences between symbol, block, and instance properties are.