1 2 First Previous 18 Replies Latest reply on Nov 22, 2013 10:50 AM by andrew.french

    Get Schematic Components in Variant Manger Mode

    fuba

      Hello Community,

       

      I like to query a Schematic handled in the DxDesigner, for "active" components.

      With active components, I mean the Parts which are not crossed out (see my attachment).

       

      The Red Cross in the attached file, is made by the Variant Manager.

       

      I know that I can pull a complete BOM, with the on Board Tools from DxDesigner, but

      what I want, is a BOM of the Crossed Out parts.

       

      I have a tool/script running which gets all components listed on a sheet, a selection, or ...

      but I am not able to judge with code, if it is a red crossed part or not.

       

      In/With the Variants manager I have the option, to delete those red crossed components.

      Then my tool/script will work, but that's not what I want.

       

      So, If you have any help for me regarding scripting around the variant manager, or how to

      get the "Crossed Out" parts, I am very happy.

       

      Thanks in advance.

       

      Stefan

        • 1. Re: Get Schematic Components in Variant Manger Mode
          andrew.french

          posting to subscribe to thread, also interested in automation and the variant manager.

          • 2. Re: Get Schematic Components in Variant Manger Mode
            Patrick.Cashman

            Here's how you do it:

             

            Before we begin:

             

            1. I use VB.net.  This code is not directly transferrable to vbscript, but it should give you the idea of what to do.

            2. Because of vb.net, I use a lot of functionality not available in vbscript (or if it is I don't know how to do it).  Arraylists, dictionaries, modules, etc.

            3. I declare a lot of variables globally, as they are potentially accessed by many parts of an application.  If you do not see a variable declaration, assume it to be declared at the class or module level somewhere else.

             

            Now:

             

            Step 1: Load the Variant manager:

             

            Public Sub VM_load()

            progID = "MGCVARIANTGUI.MGCVariantGUICtrl.1"

            addinName = "Variant Manager"

            associatedScript = ""

            addinPlacement = 0

            shortcutKey = ""

            addinObj = launchAddin(progID, addinName, associatedScript, addinPlacement, shortcutKey)

            Addins = app.Addins

            addinObj = Addins.item("Variant Manager")

            addinObj.visible = true          ' is there a way to access VM without raising the VM application window?

            vmapp = addinObj.Control.VariantGUIApplication

                    vmdoc = vmapp.VMDocument

            End Sub

             

             

            Step 2:

             

            In some other routine, call the VM_Load sub.  In my case, I populate a listbox with all the variants. This allows the user to choose which variant to use for BOM export or whatever:

             

            Sub load_VM()

             

            Dim var As MGCVARIANTGUI.IMGCVMVariant

            Dim vars As MGCVARIANTGUI.IMGCVMVariants

            Dim schms As ViewDraw.IStringList

            Dim sheets As ViewDraw.IStringList

             

            'make sure there is a sheet open

            view = app.ActiveView

            If view Is Nothing Then

            schms = app.SchematicSheetDocuments.GetAvailableSchematics

            sheets = app.SchematicSheetDocuments.GetAvailableSheets(schms.GetItem(1))

            app.SchematicSheetDocuments.open(schms.GetItem(1), sheets.GetItem(1))

            End If

             

            view = app.ActiveView

             

            VM_load()

            vars = vmdoc.variants

             

            For Each var In vars

            lst_variants.Items.Remove(var.Name)

            Next

             

            For Each var In vars

            lst_variants.Items.Add(var.Name)

            Next

            lbl_status.Text = "Select a Variant to export"

             

            End Sub

             

            Step 3:

             

            As a separate step, run the following.  It populates an arraylist (replaced) and one dictionary (replaced).  One with unplaced parts and one with replaced parts.  These arraylists can be used later on to query a particular component as being unchanged, removed (unplaced), or having a different part number (replaced).

             

            Public Sub load_unplaced_replaced()

            Dim tsb As New StringBuilder

            Dim n as Integer

             

            vars = vmdoc.variants

            var = vars.Item(Main_Form.lst_variants.SelectedIndex + 1)'variants are 1 based, not zero

             

             

            'Set up lists of the unplaced and replaced components

            unplaced.Clear

            replaced.Clear

            vmcomps = vmdoc.components(var.Name)'gets all the components associated with the variant

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

             

             

            n = 0

            For Each vmcompmod In vmcompmods

            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

            n = n + 1

            Next

            End Sub

             

             

            Now I use the following to get all design components (without visiting each sheet).

             

            design_name = app.GetProjectData.GetiCDBDesignRootBlock(app.GetActiveDesign())

            scomps = nothing

            scomps = app.DesignComponents("", design_name, "-1", , False)          'gets all the components in the design

             

            Cycle through scomps using a for/each loop and do whatever comparison you want against the unplaced/replaced lists.

             

            That's the basics of it.  Of course there is a ton more that can be done around this, but that should get you started on the right track.

            1 of 1 people found this helpful
            • 3. Re: Get Schematic Components in Variant Manger Mode
              andrew.french

              Its going to be a little while till I can look at this in more detail, but wanted to thank you Patrick for taking the time to make such a detailed post!

              • 4. Re: Get Schematic Components in Variant Manger Mode
                fuba

                Dear Patrick,

                 

                thanks for this first detailed answer. I will go through and check.

                I also come back on this and give an answer, but this will take some time, due to other workload I have at the moment.

                 

                Thanks so far, and bye

                 

                Stefan

                • 5. Re: Get Schematic Components in Variant Manger Mode
                  fuba

                  Dear Patrick,

                   

                  I have started checking out your code. I am also using VB.Net, thats fine.

                   

                  I have another question regarding the "launchAddIn" funcrtion you are calling.

                   

                  ** Where is it implemented ?

                  ** Do I need a special reference to ??? which DLL ? or ...

                   

                  The rest seams good so far.

                   

                  Thanks again

                   

                  Stefan

                  • 6. Re: Get Schematic Components in Variant Manger Mode
                    Patrick.Cashman

                    Sorry, I forgot to include that.  There is also another function needed, which I'm including as well.

                     

                    Function launchAddin(progID, localName, associatedScript, defaultPlacement, shortcutKey)

                    Dim toolBarMenu as Boolean

                    Dim quiet as Boolean

                    Dim groupName As String

                     

                    Addins = app.Addins

                     

                    toolBarMenu = False

                    quiet = True

                    groupName = ""

                     

                    launchAddin = alreadyLoaded(localName)

                    If launchAddin Is Nothing Then

                    launchAddin = Addins.Add(progID, localName, associatedScript, defaultPlacement, shortcutKey, groupName, quiet, toolbarMenu)

                    If launchAddin Is Nothing Then

                    Msgbox(progID & " Addin not created.")

                    End If

                    End If

                     

                    return launchaddin

                     

                    End Function

                     

                     

                    Function alreadyLoaded(localName)

                    alreadyLoaded = Nothing

                    Dim ain

                    For Each ain In Addins

                    If ain.Name = localName Then

                    alreadyLoaded = ain

                    Exit For

                    End If

                    Next

                     

                    Return alreadyLoaded

                     

                    End Function

                     

                     

                    If if seems that the logic of these functions is convoluted, I agree.  I cobbled them together from some examples in the Mentor help, which were not made for vb.net and which I could barely follow as it was. There are a lot of the switches and other parameters that are not described anywhere, so I'm constantly having to guess what is needed and what is not.  I debug relentlessly until it works, but often I do not fully understand how or why it works.

                     

                    On a somewhat related note, I have currently having a very hard time with the Variant Manager automation in Expedition.  I can load it and work with it, but it seems to not want to close correctly.  If I make a hook into it with automation, then close the Expedition session without closing the automation tool, I get a "Pure Virtual Function Call" error message.  I've tried every way I can think of to shut down the Variant Manager using its provided functions, all to no avail. If any of you are using the Variant Manager in Expedition, you will no doubt run across the same problem.

                    • 7. Re: Get Schematic Components in Variant Manger Mode
                      fuba

                      Dear Patrick,

                       

                      thanks for the valueable Information.

                      I found the same solution in the meanwhile, by searching all Mentor vbs example Scripts on My Computer.

                       

                      But anyway, you have been a great help, and I will also check your latest Code Snippets/Functions.

                       

                      Thanks so far.

                       

                      I will extend you code a little, iaw.: a few more object definitions, I have also figured out in the meanwhile,

                      which makes coding easier and post it in a few days here, maybe this helps you a little to get in deeper,

                      or someone else.

                       

                      So, thanks again & Bye

                       

                      Stefan

                      • 8. Re: Get Schematic Components in Variant Manger Mode
                        fuba

                        Hi Patrick,

                         

                        do you have also a solution, how to get to the Parts defined in the Functions ?

                        I have tried it they way you do it with the variants, but no success so far.

                         

                        Thanks again

                         

                        regards Stefan

                        • 9. Re: Get Schematic Components in Variant Manger Mode
                          Patrick.Cashman

                          I think what you are talking about is this part:

                           

                          design_name = app.GetProjectData.GetiCDBDesignRootBlock(app.GetActiveDesign())

                          scomps = nothing

                          scomps = app.DesignComponents("", design_name, "-1", , False)          'gets all the components in the design

                           

                           

                          Here's an example of how to use it; The idea is to get a collection of all the parts, then use a for/each loop to cycle through them.  The for/each loop then has a reference to each individual part in turn, and you can do whatever you need to with each part. 

                           

                           

                          Public Sub load_all_comps()

                           

                          Dim attr As ViewDraw.Attribute

                          Dim tmp, ref As String

                          Dim n As Integer

                          Dim scomp  As ViewDraw.Component

                           

                           

                          design_name = app.GetProjectData.GetiCDBDesignRootBlock(app.GetActiveDesign())

                          scomps = nothing

                          scomps = app.DesignComponents("", design_name, "-1", , False)          'gets all the components in the design

                           

                          all_comps.Clear

                          'load up all_comps dictionary with key = refdes and value = pcb footprint

                          For Each scomp In scomps

                          If scomp.Refdes = "" Then GoTo next_scomp1

                          ref = scomp.Refdes.ToString & vbcrlf

                          attr = scomp.FindAttribute("PCB Footprint")

                          tmp = ""

                          If Not attr Is Nothing Then

                          tmp = attr.Value.ToString

                          End If

                           

                          if not all_comps.ContainsKey(scomp.Refdes.ToString) then

                          all_comps.Add(scomp.Refdes.ToString, tmp)

                          End If

                          next_scomp1:

                          Next

                          End Sub

                           

                           

                          If this is not what you are looking for then I don't understand your question.  Hope this helps. 

                           

                          Just to be clear, the information about each part in the variant manager does not have a full part definition with all the part properties. All it has the information about the variant modifications to the part - no change, uninstalled, part number replaced, etc. That's why I have stored all that in separate lists, yet still refer to the actual component to get any property values I need from it.

                          • 10. Re: Get Schematic Components in Variant Manger Mode
                            fuba

                            Hi,

                             

                            well I am not quite shure. To explain my question more in Detail.

                            The Variant Manager holds the Variants. Variants consist of functions.

                            and functions consist of parts (Caps, Resistors,... whatever).

                             

                            You solution above tells which Part (Cap, Resistor, ...) is part of which variant.

                            I look now for the Parts and the Functions described above.

                             

                            I think It should also be possible to iterate through all Functions,

                            like going through all Variants.

                             

                            Thanks

                             

                            Stefan

                            • 11. Re: Get Schematic Components in Variant Manger Mode
                              Patrick.Cashman

                              I've never used the Functions.  I suggest you check the help under Variant Manager Automation Reference > VMDocument Object.  There is some information in there about them.

                              • 12. Re: Get Schematic Components in Variant Manger Mode
                                fuba

                                Hi,

                                 

                                here like promised in my post above, but a little delayed, a complete

                                Vb.Net Project in Mirosoft Visual Studio Express 2008,based on the Code

                                by Patrick.Cashman, but extended a little by a few more Object declarations,

                                which make programming a little easier due to mor Intelli Sense Support.

                                 

                                It needs an open Dx-Designer, a loaded Schematic with Variants in it.

                                After Pressing the button it takes a while, dependant on the Size of the Schematic and Variants.

                                Please wait until a Message Box appears, telling you that it is ready now.

                                 

                                The Program is pretty simple so far (no Background Workers, additional parallel threads, ...)

                                 

                                Have fun with that,

                                 

                                and

                                 

                                Bye

                                 

                                Stefan

                                • 13. Re: Get Schematic Components in Variant Manger Mode
                                  fuba

                                  Hi Patrick,

                                   

                                  I just added a Test App, containing your code, and my Extensions.

                                  Please feel free to use, or ...

                                   

                                  Thanks again for the good help.

                                   

                                  Bye Stefan

                                  • 14. Re: Get Schematic Components in Variant Manger Mode
                                    andrew.french

                                    Hey guys,

                                     

                                    All I want to do is check the schematic if there are any variants and if there are just grab their name(s).  Is all this necessary for that or does anyone know a more straight forward way of accomplishing this?  Like maybe a text file that exists that you could parse for this info or something else?  Seems very convaluded for something that should be easy.

                                    1 2 First Previous