TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Lee Mac on July 30, 2009, 07:28:29 PM

Title: Get Selected Layouts
Post by: Lee Mac 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
Title: Re: Get Selected Layouts
Post by: It's Alive! 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
Title: Re: Get Selected Layouts
Post by: CAB on July 30, 2009, 10:14:02 PM
Code: [Select]
(setq layout (dos_multilist "Select Layouts" "Select layouts" (layoutlist)))
Title: Re: Get Selected Layouts
Post by: It's Alive! 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) ;
 }
Title: Re: Get Selected Layouts
Post by: CAB on July 31, 2009, 01:27:55 AM
Another method for lisp.
Title: Re: Get Selected Layouts
Post by: It's Alive! on July 31, 2009, 01:41:43 AM
added to the tool box
http://www.theswamp.org/index.php?topic=21875.0

Title: Re: Get Selected Layouts
Post by: Lee Mac 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