10 Replies Latest reply on Nov 30, 2017 8:11 AM by michael_38

    Script : get unplaced components (variant manager)

    michael_38

      Hello,

       

      I made an Excel script to get all components in a schema :

      Private Sub LoadPADSVX()
          Dim vdapp As CVdApp
          Dim vdComp As Object
          Dim schName As String
          Dim i As Integer
          Dim dBquery As Object
      
          Set vdapp = GetObject(, "ViewDraw.Application")
          schName = vdapp.GetProjectData.GetiCDBDesignRootBlock(vdapp.GetActiveDesign)
      
          i = 0
          Set dBquery = vdapp.DesignComponents("", schName, -1, "STD", True)
          For Each vdComp In dBquery
              i = i + 1
                 
              Cells(i, 1).value = PADSVX_getProperty(vdComp, "Ref Designator")
              Cells(i, 2).value = PADSVX_getProperty(vdComp, "Part Number")
              Cells(i, 3).value = PADSVX_getProperty(vdComp, "Property1")
              Cells(i, 4).value = PADSVX_getProperty(vdComp, "Property2")
          Next vdComp
      End Sub
      
      Function PADSVX_getProperty(vdComp As Object, property As String) As String
          Dim oRefSymbolAttrOrg
          Dim oRefAttrOrg
      
          Set oRefAttrOrg = vdComp.FindAttribute(property)
          
          If property = "Ref Designator" Then
              Set oRefSymbolAttrOrg = vdComp.SymbolBlock.FindAttribute(property)
              If oRefSymbolAttrOrg Is Nothing Then
                  PADSVX_getProperty = ""
              Else
                  If oRefAttrOrg Is Nothing Then
                      PADSVX_getProperty = oRefSymbolAttrOrg.value
                  Else
                      If Len(oRefAttrOrg.InstanceValue) > 0 Then
                          PADSVX_getProperty = oRefAttrOrg.InstanceValue
                      Else
                          PADSVX_getProperty = oRefAttrOrg.value
                      End If
                  End If
              End If
          Else
              If oRefAttrOrg Is Nothing Then
                  PADSVX_getProperty = ""
              Else
                  PADSVX_getProperty = oRefAttrOrg.value
              End If
          End If
      End Function
      

       

      Now I would like to add a column in Excel to see unplaced components for the active variant : how must I do (What is the property name ?) ?

      => the active variant is the variant selected when you press button "Create Variant/Function Schematics" in the variant manager

       

      In a variant, a component could be placed or unplaced or replace. Now I would like add a new state (state "rework") : How can I do it ?

       

      Where can I found a detailed description for Dx designer scripting API ?

        • 1. Re: Script : get unplaced components (variant manager)
          Patrick.Cashman

          Here are the routines I use the get similar information:

           

          Not exactly what you need but you should be able to make some headway using similar methods.

           

                'global variables

               Public vmcompmods As MGCVARIANTGUI.VMComponentModifications

               Public unplaced As New ArrayList

               Public replaced As New Dictionary(Of String, String)

               Public vmdoc

               Public vmapp

           

                'load

               Public Sub VM_load()

                   Addins = app.Addins     'this can be dxapp or pcbapp

                   addinObj = Addins.item("Variant Manager")

                   addinObj.visible = True

                   vmapp = addinObj.Control.VariantGUIApplication

                   vmdoc = vmapp.VMDocument

               End Sub

           

           

               Sub start()

                   vars = vmdoc.variants

                   For Each var In vars

                       load_unplaced_replaced(var)

                   Next

               End Sub

           

           

               Public Sub load_unplaced_replaced(var As MGCVARIANTGUI.IMGCVMVariant)

                   'Set up lists of the unplaced and replaced components

                   unplaced.Clear()

                   replaced.Clear()

           

                   vmcompmods = vmdoc.ComponentModifications(var.Name) 'gets all the component modifications associated with the variant

           

                   For Each vmcompmod In vmcompmods

                       If vmcompmod.Operation = 0 Then

                           'do nothing

                           Debug.Print("component " & vmcompmod.Component.Name & " has cmcompmod.operation = 0")

                       End If

                       If vmcompmod.Operation = 1 Then 'selects out the unplaced components

                           If vmcompmod.variant.Name = var.Name Then 'select only those that are part of the active variant

                               unplaced.Add(vmcompmod.Component.Name) 'adds the unplaced components to the unplaced arraylist

                           End If

                       End If

                       If vmcompmod.Operation = 2 Then 'selects out the replaced components

                           If vmcompmod.variant.Name = var.Name Then 'select only those that are part of the active variant

                               replaced.Add(vmcompmod.Component.Name, vmcompmod.NewPartNumber)

                           End If

                       End If

                   Next

               End Sub

           

          1 of 1 people found this helpful
          • 2. Re: Script : get unplaced components (variant manager)
            michael_38

            Ok, I thank you

             

            In schema, is there a component property to know if it is placed (it will be easier) ?

            • 3. Re: Script : get unplaced components (variant manager)
              michael_38

              Are you sure that this line are usefull ?

              If vmcompmod.variant.Name = var.Name Then 'select only those that are part of the active variant

              • 4. Re: Script : get unplaced components (variant manager)
                Patrick.Cashman

                No it's not.  I use the script in a slightly different way and modified it for the purposes of this example.  I don't actually pass in var, but get var.name from a control on my form.  Don't worry about that.

                 

                The main point is to show how to connect to vmapp and vmdoc, then how to use the VMComponentModifications to get placed and replaced components.

                • 5. Re: Script : get unplaced components (variant manager)
                  michael_38

                  I thank you, my program operate

                   

                  Documentation is aviable here : C:\MentorGraphics\PADSVX.2.2\docs\pdfdocs\

                  => files eevm_auto.pdf and dxdesigner_auto.pdf

                  • 7. Re: Script : get unplaced components (variant manager)
                    michael_38

                    Hello,

                    To get all components, I use : Set dBquery = vdapp.DesignComponents("", schName, -1, "STD", True)

                     

                    - Is it normal that power supply and ground symbols in my schema are  accounted for ?

                    - Is it normal that each gate are accounted for (ie : if a component have 3 gates, component apperas 3 times) ?

                    => Problem it slowed down the component get function

                    • 8. Re: Script : get unplaced components (variant manager)
                      Patrick.Cashman

                      Yes that function picks up power and ground symbols. If you don't want to include them in your process, check for the presence of the refdes property.  If there isn't one, ignore the component.

                       

                      Yes, if there are multiple gates, they are picked up individually.  If you are doing anything that needs to treat multi-gate parts as a single component, you need to get the refdes from each component, make a list and add each gate to it.  I use a dictionary for this, with refdes as key and the value is a list of type viewdraw.component.  Using a dictionary you can add to the list as you go through all the components, but if there is only one gate it still works just as well.  The dictionary structure is quite fast, so it should not slow down your code much at all to collect the components in this manner.

                      • 9. Re: Script : get unplaced components (variant manager)
                        michael_38

                        The dictionary structure is quite fast, so it should not slow down your code much at all to collect the components in this manner.

                        I'm not sure but when there is a multi-gate, gates are listed one after other in the "for each" loop : dictonary aren't required, you can check ref designator of the previous component

                        => to confirm.

                         

                        To check refdes property doesn't slow down significantly because it is communication time between Excel and Dx Designer which is very slow (insert a line in Excel is very fast).

                        • 10. Re: Script : get unplaced components (variant manager)
                          michael_38

                          ... It is why, filtering should be done in the API functions and not in the VBA code