12 Replies Latest reply on Sep 6, 2018 2:28 PM by andrew_french

    Reading properties from Dx project using a script

    hannu.tikkanen

      I would like to use project properties to save some information, but I don't find a mechanism to access those via automation. In the example screen shot I have added a property to the CORPORATE project.  How do I read the property value using automation (Visual Studio 2017 or other)?

      dxprop.png

       

      Hannu Tikkanen

        • 1. Re: Reading properties from Dx project using a script
          peter_festesen

          Terve Hannu !

          your name sounds Finnish ;-)

           

          Please start by looking here i the Community - a serach for DxDEsigner component poroperties here gives me quite some hits, like this for example.

          FindAttribute "DNP" of components DxDesigner Script

           

          Otherwise, let us know what you are trying to do in more detail - your task (all components, just a selected component), what you have tried already an so on.

           

          /Peter

          • 2. Re: Reading properties from Dx project using a script
            hannu.tikkanen

            Thanks for the answer. I have read all discussions in the community. I know how to read component properties but my question is how to read project level properties. Like in the screen shot - the property is attached in the "CORPORATE" schematic, not in any of the components.

            • 3. Re: Reading properties from Dx project using a script
              peter_festesen

              Sorry, Hannu - my mistake.
              From your screenshot it looks like it is assigned to the Root Block Schematic, just to clarify. I had not noticed that before. The hierarchy goes Project (Lesson32), then board (or boards), also Lesson32, then Root Block 'CORPORATE', so I would guess you have to look for properties at the root block level...

               

              /P

              • 4. Re: Reading properties from Dx project using a script
                hannu.tikkanen

                Some testing..I have the following piece of code of VB in VS2017. ViewDraw is marked in the references.

                For some reason VS doesn't accept the collections "VDapp.ActiveView.Query(ViewDraw.VdObjectTypeMask.VDM_COMP, ViewDraw.VdAllOrSelected.VD_ALL)" and "ocComp.Attributes".

                The code is supposed to show all block "csheet" properties using msgbox.

                 

                Public Function GetDxProperty(ByRef VDapp As ViewDraw.Application)

                Try

                            Dim oBlock As ViewDraw.Block

                            Dim ocComp As ViewDraw.Component

                            Dim ocAttr As ViewDraw.Attribute

                            For Each ocComp In VDapp.ActiveView.Query(ViewDraw.VdObjectTypeMask.VDM_COMP, ViewDraw.VdAllOrSelected.VD_ALL)

                                oBlock = ocComp.SymbolBlock

                                If oBlock.GetName("FULL_PATH_NAME") = "csheet" Then

                                    MsgBox("Found Match")

                                   For Each ocAttr In ocComp.Attributes

                                        MsgBox(ocAttr.TextString) ' Or use ocAttr.Name for property name, ocAttr.Value for property value

                                    Next

                                    Exit For

                                End If

                            Next

                            Return True

                        Catch ex As System.Exception

                            MsgBox("Error: " & ex.Message & " in function 'GetDxProperty'.")

                        End Try

                End Function

                 

                Most likely it is something simple but I just can't find it. I would really appreciate any help.

                • 5. Re: Reading properties from Dx project using a script
                  peter_festesen

                  I will have to look into this in more detail (and first translate to vbscript, since I don't do Visual Studio)

                   

                  BUT

                   

                  at first glance it looks as if your are finding components that have name=Csheet - this would give you component objects of Schematic symbol if I am not mistaken.

                  What happens if you omit the code that checks for 'csheet' and just chuck out the text to a file or to the output window. ? This just to find out if ANY of the objects in the oComp collection show the 'ProjectNum' property...

                  • 6. Re: Reading properties from Dx project using a script
                    hannu.tikkanen

                    I truncated the code to just:

                    Dim oBlock As ViewDraw.Block

                    Dim ocComp As ViewDraw.Component

                    Dim ocAttr As ViewDraw.Attribute

                    For Each ocComp In VDapp.ActiveView.Query(ViewDraw.VdObjectTypeMask.VDM_COMP, ViewDraw.VdAllOrSelected.VD_ALL)

                    Next

                     

                    The error in VS is:

                    Error BC32023 Expression is of type 'IVdObjs', which is not a collection type.

                    It seems that the VDapp.ActiveView.Query doesn't return a collection which is expected by VS.

                    • 7. Re: Reading properties from Dx project using a script
                      peter_festesen

                      Hmm - I don't see Vdapp declared...

                      • 8. Re: Reading properties from Dx project using a script
                        hannu.tikkanen

                        Right, but it was initiated elsewhere and passed to the function. It seems to work ok.

                         

                        Hannu Tikkanen

                        • 9. Re: Reading properties from Dx project using a script
                          hannu.tikkanen

                          Came to the conclusion that ViewDraw scripting is not Visual Studio compatible unless proven otherwise. The next sample code works in for example Microsoft Word VBA but it doesn't work in Visual Studio 2017 (error on row "For Each…":

                           

                          Private Sub CommandButton1_Click()

                              Dim VDapp As ViewDraw.Application

                              Dim ocComp As ViewDraw.Component

                              Dim i As Integer

                              Set VDapp = GetObject(, "ViewDraw.Application")

                              MsgBox (VDapp.FullName)

                              For Each ocComp In VDapp.ActiveView.Query(ViewDraw.VdObjectTypeMask.VDM_COMP, ViewDraw.VdAllOrSelected.VD_ALL)

                                  i = i + 1

                              Next

                              Set VDapp = Nothing

                              MsgBox

                          End Sub

                           

                          I hope somebody can prove the conclusion to be wrong...

                          • 10. Re: Reading properties from Dx project using a script
                            andrew_french

                            I use VS and I've never been able to get foreach to work in the designer automation however the method below works for me.

                             

                            Dim compObj As ViewDraw.IVdObjs

                            Dim comp As ViewDraw.Component

                             

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

                             

                            for x = 1 to compObj.Count

                                 comp = compObj.Item[x]

                                 //do something with comp

                            next

                            • 11. Re: Reading properties from Dx project using a script
                              hannu.tikkanen

                              Thank you for the tip. I tried it right away and it works!

                               

                              The other thing that I didn't find out was how to define a collection of objects in ViewDraw, it is different from PADS Layout, so this was also a valuable piece of information (ViewDraw.IVdObjs). 

                              • 12. Re: Reading properties from Dx project using a script
                                andrew_french

                                yeah I'm not even sure at this point how I figured IVdObjs even existed, intellisense doesn't even recognize it.  I'm pretty sure I saw it on these forums buried somewhere so I try to help others out when I can. Glad its working for you now!