11 Replies Latest reply on Nov 5, 2010 7:11 AM by frank.henne

    Add/delete attributes via script - Problem with Query(VDM_COMP, VD_SELECTED)

    joerg.schmidt

      Hello,

       

      i like to add/delete the property Assembled to selected components. For this purpose i use the following script:

      OptionExplicit

      'Get DXapp-object
      Dim DXapp
      Set DXapp = GetObject (,"ViewDraw.Application")
      '
      'Change property
      Dim objComp, objAttribute
      Dim x,y
      ForEach objCompIn DXapp.Query(VDM_COMP, VD_SELECTED)
          If objComp.FindAttribute("Assembled") IsNothingThen
              
              If objComp.FindAttribute("Part Label") IsNothingThen
                  x=objComp.GetLocation().X+50
                  y=objComp.GetLocation().Y+50
              Else
                  'Get x/y of part label
                  x=objComp.FindAttribute("Part Label").GetLocation().X
                  y=objComp.FindAttribute("Part Label").GetLocation().Y
                  'Create offset
                  x=x-5
                  y=y-18
              EndIf
              'Add attribute
              objComp.AddBatchAttributes("3 0 Assembled=NB")
              objComp.FindAttribute("Assembled").SetLocation x,y
      'With multi-selection via Selection Box script generates here a runtime error
          Else
              'Delete attribute
              objComp.FindAttribute("Assembled").delete()
          EndIf
      Next


      If I select only 1 (LMB-Click) or add more components with Cntrl+(LMB-Click) then the code works and attachs/deletes the property to/from the component.

      It also works if I use the selection filter (only pins deactivated) + Selection box.

      But when I use the Selection Box (selection  filter: pins activated) and select 1 or more components

      the script generates a runtime error and the property will be attached to the pin of the component and not to the component itself.

      Therefore I get with every script execution another property "Assembled" added.

      I have made screenshots for both situations.

       

      Thanks for your help in advance

       

      Joerg


        • 1. Re: Add/delete attributes via script - Problem with Query(VDM_COMP, VD_SELECTED)
          robert_davies

          I can't answer your question, but did you know there is an Automation Forum within communities that might be more appropriate for these kinds of questions.

           

          http://communities.mentor.com/community/pcb/automation_scripting

           

          In the meantime I'm sure somebody will answer this post.

          Rob

          • 2. Re: Add/delete attributes via script - Problem with Query(VDM_COMP, VD_SELECTED)
            john_dube

            Hi Joerg,

             

            Are you running the script outside of DxDesigner, with mgcscript or cscript?  It appears so, from the call to GetObject.  If so, the VDM_COMP and VD_SELECTED enum values are not defined, you need to define them or use mgcscript and call Scripting.AddTypeLibrary("ViewDraw.Application").

             

            If you are running the script inside DxDesigner, the enum values are loaded, you can use the pre-defined variable called Application instead of calling GetObject.

             

            Not sure if this is related, but you are calling the Query method on the Application object, this will perform the query against all open sheets, not just the active sheet.   If you want to just modify selected components on the sheet that is currently being edited, then call the Query method on the ActiveView property of the Application object instead. 

             

            Hope this helps,

             

            John

            • 3. Re: Add/delete attributes via script - Problem with Query(VDM_COMP, VD_SELECTED)
              joerg.schmidt

              Hi John,

               

              thanks for your help.

              The script is running inside DxDesigner, therfore VDM_COMP and VD_SELECTED is defined.

              I have used your information and changed it a little bit.

              The query uses now the active view (but i doesn't matter I think)

              OptionExplicit

              'Change property
              Dim objComp, objAttribute
              Dim x,y
              ForEach objCompIn Application.ActiveView.Query(VDM_COMP, VD_SELECTED)
                  If objComp.FindAttribute("Assembled") IsNothingThen
                      
                      If objComp.FindAttribute("Part Label") IsNothingThen
                          x=objComp.GetLocation().X+50
                          y=objComp.GetLocation().Y+50
                      Else
                          'Get x/y of part label
                          x=objComp.FindAttribute("Part Label").GetLocation().X
                          y=objComp.FindAttribute("Part Label").GetLocation().Y
                          'Create offset
                          x=x-5
                          y=y-18
                      EndIf
                      'Add attribute
                      objComp.AddBatchAttributes("3 0 Assembled=NB")
                      objComp.FindAttribute("Assembled").SetLocation x,y
                  Else
                      'Delete attribute
                      objComp.FindAttribute("Assembled").delete()
                  EndIf
              Next

               

              ...the problem is still the same. If I select the components directly with LMB the script works.

              but when I use the Selection Box (Selection filter: Pins are selected) the script fails and attaches the property with every execution to the component-pin.

              How can i "remove" the pins from my "query-collection"?

               

              Thanks,

               

              Joerg 

              • 4. Re: Add/delete attributes via script - Problem with Query(VDM_COMP, VD_SELECTED)
                john_dube

                I don't understand why you would be getting pins when you passed VDM_COMP to the Query method, but you could check the Type property of the objComp variable to make sure it is a component:

                 

                For Each objComp In Application.ActiveView.Query(VDM_COMP, VD_SELECTED)

                       If objComp.Type = VDTS_COMPONENT Then

                         If objComp.FindAttribute("Assembled") Is Nothing Then

                ...

                 

                John

                • 5. Re: Add/delete attributes via script - Problem with Query(VDM_COMP, VD_SELECTED)
                  joerg.schmidt

                  Hi John,

                   

                  i had the same idea and have already tried it.

                  The following code doesn't work either...

                   

                  OptionExplicit

                  'Change property
                  Dim objComp, objAttribute
                  Dim x,y
                  ForEach objCompIn Application.ActiveView.Query(VDM_COMP, VD_SELECTED)
                      If objComp.Type = VDTS_COMPONENTThen
                          If objComp.FindAttribute("Assembled") IsNothingThen
                              
                              If objComp.FindAttribute("Part Label") IsNothingThen
                                  x=objComp.GetLocation().X+50
                                  y=objComp.GetLocation().Y+50
                              Else
                                  'Get x/y of part label
                                  x=objComp.FindAttribute("Part Label").GetLocation().X
                                  y=objComp.FindAttribute("Part Label").GetLocation().Y
                                  'Create offset
                                  x=x-5
                                  y=y-18
                              EndIf
                              'Add attribute
                              objComp.AddBatchAttributes("3 0 Assembled=NB")
                              objComp.FindAttribute("Assembled").SetLocation x,y
                          Else
                              'Delete attribute
                              objComp.FindAttribute("Assembled").delete()
                          EndIf
                      EndIf
                  Next    

                   

                  Maybe you have another suggestion? I don't understand the behavior of the script.

                  If i use the selection filter and disable the pins, i can select as many components as i like and it works.

                  As soon as the pins are selected it doesn't work.

                   

                  very strange....

                   

                  Joerg

                  • 6. Re: Add/delete attributes via script - Problem with Query(VDM_COMP, VD_SELECTED)
                    dirk_from_munich

                    Did you try the multiple selection with only "Symbol" selected in the Select Filter?

                    • 7. Re: Add/delete attributes via script - Problem with Query(VDM_COMP, VD_SELECTED)
                      joerg.schmidt

                      Hi dirk,

                       

                      thanks for your help.

                      If I use the select filter and choose only symbols, then the script works.

                      But as soon as I enable the Pins in the select filter too, the script fails.

                       

                      But I don't like to uncheck the pins in the select filter every time i use my script.

                       

                      Joerg

                      • 8. Re: Add/delete attributes via script - Problem with Query(VDM_COMP, VD_SELECTED)
                        john_dube

                        Hi Joerg,

                         

                        Is that the entire script?  Is it possible that VDM_COMP is incorrectly defined somewhere else in the script?

                         

                        I have not been able to reproduce the behavior of View.Query returning pins when VDM_COMP is passed in, and it is even stranger that the Type property of a pin would be VDTS_COMPONENT.

                         

                        I think it is time to file a service request.

                         

                        John

                        • 9. Re: Add/delete attributes via script - Problem with Query(VDM_COMP, VD_SELECTED)
                          dirk_from_munich

                          I could reproduce it. I selected 4 symbols and the collection only shows 4 components. But: the property was added to the pins instead of the symbol, as Joerg mentioned. I think, this could be easily verified. For my understanding, this is a bug and Joerg should write a SR, as you recommend, John.

                          • 10. Re: Add/delete attributes via script - Problem with Query(VDM_COMP, VD_SELECTED)
                            joerg.schmidt

                            Hi John, hi Dirk,

                             

                            thanks for your help! I have started a SR.

                            I will post the result here.

                             

                            Joerg

                            • 11. Re: Add/delete attributes via script - Problem with Query(VDM_COMP, VD_SELECTED)
                              frank.henne

                              FYI: I've opened SR on 21.Oct and the only answer till now is DR 725794.

                               

                              I bothered someone else at Mentor who helps me a lot with DxD and I got the link to this discussion.

                               

                              Frank