26 Replies Latest reply: Jun 15, 2012 1:16 AM by Ondrej Vyhlidal RSS

    Questions about Selections

    Ondrej Vyhlidal Community Member

      Hi all,

      I have some unsolved questions about selections, I have panel, ASB, CSB, layoutSelectionBoss and so on:

      1. How is my selection called? What steps I need to do for that?
      2. How to get data from selection? There shlould be defined abstract methods in ASB, and its real implementation in CSB or eg. LayoutSelectionBoss?

      Thank you in advice

        • 1. Re: Questions about Selections
          Manan Joshi Community Member

          In order to create your own selection suites you need to follow the following steps.

           

          1. Create an interface for the selection suite and place it as an AddIn in the IntegratorSuite and the suite boss that you need to extend. Like for layout you could use the kLayoutSuiteBoss.

           

          2. The implementation for the interface added in the IntegratorSuite will be the ASB implementation, the code for this is pretty much templated, refer SDK sample code to have an idea about it.

           

          3. The implementation for the interface added in the other suite boss will be the CSB implementation. Inside this class you can write the code specfic to your needs.

           

          Regading the call on this code and how do you get your code executed, first you will have to get the selection manager interface which is generally obtained from the activeselection but there are other ways too refer the SDK for it. From this selectionmanager interface query the interface of your suite and if your suite is available you can call it's method else you will get a nill pointer.

           

          I think this should make it pretty much clear, for more clarifications refer the SDK samples and the programming guide.

           

          Manan Joshi

           

          - Efficient InDesign Solutions -

          MetaDesign Solutions

          http://metadesignsolutions.com/services/indesign-development.php

          • 2. Re: Questions about Selections
            Ondrej Vyhlidal Community Member

            Thank you for that explanation, it was wery useful

            I have one more question:

            In my LayoutCSB I would like to get SeletionHeight, for this, there is GetSeletionHeight in IGeometrySuite. Am I right?

            So this method should look like that:

            int STSuiteLayoutCSB::SelectionHeight()

            {

              InterfacePtr<IGeometrySuite> mySuite(this, UseDefaultIID());

              return mySuite->GetSelectionHeight();

            }

             

            this will result in problem...

            In IGeometrySuite are these two methods:

            virtual void GetSelectionHeight( Transform::CoordinateSpace boundsSpace, Geometry::BoundsKind boundsKind, Transform::CoordinateSpace measurementSpace, K2Vector<PMReal>& results) const = 0;    

            virtual void GetSelectionHeight( Geometry::BoundsKind boundsKind, Transform::CoordinateSpace measurementSpace, K2Vector<PMReal>& results) const = 0;

             

            Iam a bit confused, how to use these methods, could you please help me here?

            thank you in advice

            • 3. Re: Questions about Selections
              Pickory Community Member

              This might help.

               

                        InterfacePtr<IGeometry> geometry(itemToModify, UseDefaultIID());

                        ASSERT(geometry);

                        if (!geometry) {

                return;

                        }

                        PMMatrix inner2parent = ::InnerToParentMatrix(geometry);

                        PMRect boundsInParentCoords = geometry->GetStrokeBoundingBox(inner2parent);

               

              P.

              • 4. Re: Questions about Selections
                Ondrej Vyhlidal Community Member

                Could you explain this code a little bit, please?

                • 5. Re: Questions about Selections
                  Pickory Community Member

                  Look in TransformUtils.h, the InnerToParentMatrix worked for my application but you might want InnerToPasteboardMatrix. Once you have got your PMRect in the right coordinates you can use the Height from the PMRect.

                  • 6. Re: Questions about Selections
                    Manan Joshi Community Member

                    What exactly do you want, from what i see from Pickory's code is you are trying to get the height of the bounding box of the current selection in the layout. For ex if you have three image boxes selected you need the height of the bounding box that encloses all these image boxes. Kindly clarify so that we can provide better pointers for the solution.

                     

                    Manan Joshi

                     

                    - Efficient InDesign Solutions -

                    MetaDesign Solutions

                    http://metadesignsolutions.com/services/indesign-development.php

                    • 7. Re: Questions about Selections
                      Ondrej Vyhlidal Community Member

                      I want get height, width and position of selected frame on page. I know that every time would be selected only one frame.

                      Right now I have done step one(according to your answer) and now Iam fighting with step two, i found some samples in sdk, so Iam trying to understand what kinds of methods I would need to write in ASB and how would they be implemented in CSB.

                       

                      I thing method in ASB for height of selected item would look like this:

                      void STSuite::GetSelectionHeight(Geometry::BoundsKind boundsKind,  Transform::CoordinateSpace mesurementSpace, K2Vector<PMReal> &result)

                      {

                           CallEach(make_functor(&IGeometrySuite::GetSelectionHeight, boundsKind, mesurementSpace, result), this);

                      }

                      After that I need to write its implementation in CSB. That would be consisted of these steps: get IGeometry InterfacePtr and call method GetSelectionHeight. Am I right?

                      thanks

                      • 8. Re: Questions about Selections
                        Ondrej Vyhlidal Community Member

                        So I have mooved on,

                        Right now I have my method in ISTSuite, in ASB and now I would like to create that method in CSB. Could you help me little bit with its implementation, please? I would like to get height of selected item. I know that this can be obtained from IGeometrySuite, so I will create InterfacePtr on IGeometrySuite and next?

                        Thank you in advice,

                        • 9. Re: Questions about Selections
                          Ondrej Vyhlidal Community Member

                          Finaly, I have code for obtaining width and height working perfectly!! Thanks again

                          I have 2 last questions:

                          1. If I would like to get x coordinate of left top corner of selection, which interface pointer I should get (on which suite?)?

                          2. almost same question, but I would like to get page on which is selected content.

                           

                          Thanks again

                          • 10. Re: Questions about Selections
                            Manan Joshi Community Member

                            if you wrote the code in accordance to what Pickory had hinted then the PMRect itself has the the top() method that will give you the X coordinate of the top left corner

                             

                            And for the 2nd question you will can use the method  "GetOwnerPageUID" in the "ILayoutUtils", but this method will return the UID of the spread if the pageitem does not lie on a page so make a check for that too.

                             

                             

                            Manan Joshi

                             

                            - Efficient InDesign Solutions -

                            MetaDesign Solutions

                            http://metadesignsolutions.com/services/indesign-development.php

                            • 11. Re: Questions about Selections
                              Ondrej Vyhlidal Community Member

                              I was not able to use Pickory's code, because it gave me error.

                              void STSuiteCSB::GetSelectionPositionX(K2Vector<PMReal> &result)

                              {

                                InterfacePtr<IGeometry> iGeometrySuite(this, UseDefaultIID());

                                        if (iGeometrySuite == nil) {

                                ASSERT_FAIL("Error");

                                        }

                                        PMMatrix inner2parent = InnerToParentMatrix(iGeometrySuite);

                                        PMRect boundsInParentCoords = iGeometrySuite->GetStrokeBoundingBox(inner2parent);

                               

                              }

                               

                              I know that InnerToParentMatrix is a method from TransformUtils.h, but when I use #include "TransformUtils.h" I get following error:

                              Undefined symbols:

                                "typeinfo for ISTSuite", referenced from:

                                    typeinfo for CPMUnknown<ISTSuite>in STSuiteASB.o

                              ld: symbol(s) not found

                              collect2: ld returned 1 exit status

                               

                              When I dont include header for utils, i cant call InnerToParent...

                              • 12. Re: Questions about Selections
                                Manan Joshi Community Member

                                i think you need to write ::InnerToParentMatrix instead of InnerToParentMatrix.

                                 

                                Manan Joshi

                                • 13. Re: Questions about Selections
                                  Ondrej Vyhlidal Community Member

                                  I have been trying all possible combinations and still got errors...

                                   

                                  Regarding point 2.

                                  I have:

                                  Utils<ILayoutUtils> iLayoutUtils; that is easy, right now I would like to call its method GetOwnerPageUID as you mentioned earlier, but first argument (as it is in documentation) is const IHierarchy *pageItemHier. I Have tried to do this:

                                  iLayoutUtils->GetOwnerPageUID(IHierarchy::QueryChild(0), kFalse); Iam wondering how to call this method ...


                                  • 14. Re: Questions about Selections
                                    Manan Joshi Community Member

                                    You should call it like

                                    iLayoutUtils->GetOwnerPageUID(IHierarchy, kFalse);

                                     

                                    Where IHierarchy is the interface of the pageitem, if you use querychild then you are moving into the pageitem like for ex in to the image in a pageitem.

                                     

                                    Manan Joshi

                                     

                                    - Efficient InDesign Solutions -

                                    MetaDesign Solutions

                                    http://metadesignsolutions.com/services/indesign-development.php


                                    • 15. Re: Questions about Selections
                                      Ondrej Vyhlidal Community Member

                                      Very nice explanation, Thank you a lot!

                                      • 16. Re: Questions about Selections
                                        Ondrej Vyhlidal Community Member

                                        Hi Manan,

                                        I have tried to do this:

                                        InterfacePtr<IHierarchy> iHierarchy;

                                         

                                        UID abcc = iLayoutUtils->GetOwnerPageUID(iHierarchy, kFalse);

                                                                      resu = abcc.Get();

                                                                      cout << resu;

                                         

                                        but the result is 0, even if I have sected frame on page 4 ...

                                        any ideas??

                                        thx

                                        • 17. Re: Questions about Selections
                                          Manan Joshi Community Member

                                          This works for me fine, maybe the interface that you are sending is not correct. UID 0 represents the document if i remember correctly. See the code that you are using to get the IHierarchy interface.

                                           

                                           

                                          Manan Joshi

                                           

                                          - Efficient InDesign Solutions -

                                          MetaDesign Solutions

                                          http://metadesignsolutions.com/services/indesign-development.php

                                          • 18. Re: Questions about Selections
                                            Ondrej Vyhlidal Community Member

                                            Iam using this piece of code: 

                                            InterfacePtr<IHierarchy> iHierarchy;

                                             

                                            dont know, how to get this interface pointer ...

                                            • 19. Re: Questions about Selections
                                              Manan Joshi Community Member

                                              This would return a null interface as you did not query the interface from any boss class, you need to get this interface from the selected pageitem's boss class.

                                               

                                              Manan Joshi

                                               

                                              - Efficient InDesign Solutions -

                                              MetaDesign Solutions

                                              http://metadesignsolutions.com/services/indesign-development.php

                                              • 20. Re: Questions about Selections
                                                Ondrej Vyhlidal Community Member

                                                Ok, the selection would be some frame, so what is the best boss to get interface pointer? What about selection manager?

                                                SelectionManager* iSelectionManager = iSelectionUtils->GetActiveSelection();

                                                 

                                                                    if (iSelectionManager != nil)

                                                                    {

                                                                              InterfacePtr<ISTSuite> mySuite(iSelectionManager, UseDefaultIID());

                                                                              InterfacePtr<IHierarchy> iHierarchy(iSelectionManager, UseDefaultIID());

                                                or is there anything that iam missing?

                                                • 21. Re: Questions about Selections
                                                  Manan Joshi Community Member

                                                  If you are writing this code inside the CSB method then you can query for "ILayoutTarget" interface that has "GetUIDList" method which will give you the UIDList of the selected page item. From this you can get the UIDRef of the selected pageitem, which can be quried to get the correct iHierarchy interface.

                                                   

                                                  If you are writing this code outside CSB method then write a method in the CSB to get the UIDRef of the selected page item and do as before.

                                                  Hope this is not very confusing.

                                                   

                                                  Manan Joshi

                                                   

                                                  - Efficient InDesign Solutions -

                                                  MetaDesign Solutions

                                                  http://metadesignsolutions.com/services/indesign-development.php

                                                  • 22. Re: Questions about Selections
                                                    Ondrej Vyhlidal Community Member

                                                    I have this:

                                                    void STSuiteCSB::GetSelectionPage(K2Vector<PMReal> &result)

                                                    {

                                                      InterfacePtr<IGeometry> iGeometrySuite(this, UseDefaultIID());

                                                              if (iGeometrySuite == nil) {

                                                      ASSERT_FAIL("Error");

                                                              }

                                                     

                                                      InterfacePtr<ILayoutTarget> iTarget(this, UseDefaultIID());

                                                              if (iTarget == nil) {

                                                      ASSERT_FAIL("Error in iTarget");

                                                      cout << "Error in iTarget";

                                                              }

                                                      UIDList selectionList = iTarget->GetUIDList(kStripStandoffs , kDontStripIfParentLocked);

                                                              UIDRef item = selectionList.GetRef(0);

                                                      cout << "Number of items in seleciton list:";

                                                              cout << selectionList.Length() + "\n";

                                                     

                                                      InterfacePtr<IHierarchy> iHierarchy(item, UseDefaultIID());

                                                     

                                                    }

                                                     

                                                    from this i cannot get anything useful ...

                                                    • 23. Re: Questions about Selections
                                                      Manan Joshi Community Member

                                                      This works for me fine, don't you get the correct no of selected items? What is the result of GetPageUID. You could also check the boss class of the IHierarchy interface you are using to be sure that it is indeed of the pageitem.

                                                       

                                                      Manan Joshi

                                                      • 24. Re: Questions about Selections
                                                        Ondrej Vyhlidal Community Member

                                                        No I dont get any number of selected items, I could select as much items as i want and still get nothing ... list.Length() returns nothing..

                                                        • 25. Re: Questions about Selections
                                                          Ondrej Vyhlidal Community Member

                                                          Hi I found out that, I have in item list fRefCount 3 see following picture:

                                                           

                                                          Screen Shot 2012-02-16 at 9.46.43 AM.png

                                                          I would like to know, what that mean? does it mean, that i have 3 items on page?

                                                          • 26. Re: Questions about Selections
                                                            Ondrej Vyhlidal Community Member

                                                            Hi all,

                                                            Iam sorry for opening this thread again, but I finally have some time to rollback to this issue with getting page of selected item(frame). I know how the system should work, but I am not albe to get everything working, I have something wrong in implementation. I was searching thru google for some tutorial or some sample project, but no luck at all, does anyone knows about some material where I should learn about this??

                                                             

                                                            What I want to do - when user click on button in my plugin I want to show him, on which page is selected frame. Everytime there always will be only one frame selected not more. About my implementation, as I wrote before I have SuiteCSB, SuiteASB, SuiteLayoutCSB and the ButtonAction.cpp files. I would like to call from ButtonAction method on interface, getPage. Method get page must be defined in SuiteCSB and its implementation should be in SuiteLayoutCSB?? How does the definition of this method should look like??

                                                             

                                                            Thank you all in advice