Author Topic: Get Selected Layouts  (Read 2997 times)

0 Members and 1 Guest are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Get Selected Layouts
« on: July 30, 2009, 07:28:29 PM »
This is a question posted on another forum I am a member of, and it has stumped me, so I thought I'd see if you guys knew something  :-)

How can one retrieve a list of the selected layouts in a drawing?

i.e. if the user has ctrl-clicked on multiple layout tabs, how does one get a list of those selected?

Thanks,

Lee

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Get Selected Layouts
« Reply #1 on: July 30, 2009, 09:31:31 PM »
I think in Arx, one might use  bool getTabSelected() const; , I did not see a way to do this with lisp

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Get Selected Layouts
« Reply #2 on: July 30, 2009, 10:14:02 PM »
Code: [Select]
(setq layout (dos_multilist "Select Layouts" "Select layouts" (layoutlist)))
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Get Selected Layouts
« Reply #3 on: July 30, 2009, 11:46:03 PM »
Well since you're learning C++/Arx, here is a sample for you. (attached ARX for 2007)
the function is (crpselectedlayouts)

Code: [Select]
static int ads_crpselectedlayouts(void)
 {

  // this is our "list" we will return to lisp.
  // we need to keep a copy of the head of the list
  // and add to the tail.
  struct resbuf *pRbHead = acutNewRb(RTLB);
  struct resbuf *pRbTail = pRbHead;

  // get the database.
  AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();

  // open the layout dictionary.
  // a smart pointer will manage our pointer for us.
  AcDbDictionaryPointer pLayouts(pDb->layoutDictionaryId(),AcDb::kForRead);

  // create a new iterator.
  // we need to delete this or LEAK!!!
  AcDbDictionaryIterator *pDictIt = pLayouts->newIterator();

  //iterate the dictionary looking for layouts that are selected
  for(;!pDictIt->done();pDictIt->next())
  {

   // another smart pointer.
   AcDbObjectPointer<AcDbLayout> pLayout(pDictIt->objectId(),AcDb::kForRead);

   // if it's selected add it to our resbuf (list).
   if(pLayout->getTabSelected())
   {
    TCHAR *pszLayoutName;

    // the Arx docs say do not free pszLayoutName.
    pLayout->getLayoutName(pszLayoutName);

    // add new to the end of the list.
    pRbTail = pRbTail->rbnext = acutBuildList(RTSTR,pszLayoutName,0);
   }
  }

  // return the list to lisp, AutoCAD will make a copy.
  // so we will need to free the memory or LEAK!!!
  acedRetList(pRbHead->rbnext);

  //clean up our iterator
  delete pDictIt;

  // free up the list
  if(pRbHead != NULL)
  {
   acutRelRb(pRbHead);
   pRbHead = NULL;
  }
  return (RSRSLT) ;
 }

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Get Selected Layouts
« Reply #4 on: July 31, 2009, 01:27:55 AM »
Another method for lisp.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8691
  • AKA Daniel
Re: Get Selected Layouts
« Reply #5 on: July 31, 2009, 01:41:43 AM »

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Get Selected Layouts
« Reply #6 on: July 31, 2009, 06:35:27 AM »
Thanks for your replies guys.

I thought that this might be a task beyond the immediate capabilities of LISP - nice solution Alan, that would be a good work-around.

> Daniel,

Thanks for your reply, yes, I am learning C++, but I only started learning about 2 days ago :P  I have no idea how your code works... I think it will take some time for me to get to your standard...

Thanks,

Lee