General API Question

General API Question

Anonymous
Not applicable
787 Views
4 Replies
Message 1 of 5

General API Question

Anonymous
Not applicable

I'm going through a lot of the documentation and trying to understand things before I attempt anything very serious and I am having a hard time grasping exactly how everything works. It seems that several of the examples utilize the following classes to access AutoCAD:

 

AutoCAD::IAcadApplication *pAcad;
AutoCAD::IAcadDocument *pDoc;
AutoCAD::IAcadDatabase *pDb;

 

But there is little to no documentation on them. In fact, there is not a single reference to IAcadDocument in any of the documentation. Am I just missing it? What are these used for?

 

It also appears that most of the other samples use the following classes to interact with AutoCAD:

 

AcApDocument* pDoc;

AcDbDatabase* pDb;

 

 

The actual plugin that I am wiriting is going to be exporting a drawing to a WMF, but I'm not sure which of the above approaches I should take. The only function that I can find to do it is the AutoCAD::IAcadDocument.Export(). Is this the best way to perform this operation? Any help would be appreciated, Thanks!

0 Likes
Accepted solutions (1)
788 Views
4 Replies
Replies (4)
Message 2 of 5

owenwengerd
Advisor
Advisor
Those are just pointers to COM interfaces, so you'll want documentation for the underlying COM interfaces (probably in the VBA section of the developer reference). The Export() function is probably your best bet.
--
Owen Wengerd
ManuSoft
0 Likes
Message 3 of 5

Anonymous
Not applicable

Thanks, that makes sense. The problem with the export function is that it requires a IAcadSelectionSet. I can't find anyway to create one. It seems that it would be useful to call

 

acedSSGet(_T("_A"), NULL, NULL, filter, m_ss);

 

but all that would give me would be a ads_name and I'm not sure how I could create a IAcadSelectionSet from that.

0 Likes
Message 4 of 5

Alexander.Rivilis
Mentor
Mentor
Accepted solution

Sample:

IAcadSelectionSet *GetOrCreateSelectionSet(IAcadSelectionSets *pSelSets, BSTR Name)
{
  try {
    IAcadSelectionSet *pSet = NULL;
    if (pSelSets->Add(Name,&pSet) == S_OK) {
      return pSet;
    } else if (pSelSets->Item(_variant_t(Name),&pSet) == S_OK) {
      return pSet;
    } else return NULL;
  } catch(...) {
    return NULL;
  }
  return NULL;
}
int ExportToFile(const wstring &filename, const wstring &ext)
{
  HRESULT hr;
  try
  {
    IAcadApplication *pAppAcad = (IAcadApplication *)acedGetAcadWinApp()->GetIDispatch(TRUE);
    if (pAppAcad) {
      IAcadDocument *pAcadDoc = NULL; 
      if (pAppAcad->get_ActiveDocument(&pAcadDoc) == S_OK) {
        IAcadSelectionSets *pSelSets = NULL;
        if (pAcadDoc->get_SelectionSets(&pSelSets) == S_OK) {
          IAcadSelectionSet *pSet = NULL;
          if ((pSet = GetOrCreateSelectionSet(pSelSets,_bstr_t("$$PLOTSET$$"))) != NULL) {
            pSet->Clear();
            if (FAILED(hr = pSet->Select(acSelectionSetAll,vtMissing,vtMissing,vtMissing,vtMissing))) throw(_com_error(hr)) ;
            if (FAILED(hr = pAcadDoc->Export(_bstr_t(filename.c_str()),_bstr_t(ext.c_str()),pSet))) throw(_com_error(hr)) ;
            pSet->Release();
          } else return 0;
          pSelSets->Release();
        }
        pAcadDoc->Release();
      }
      pAppAcad->Release();
    }
  }
  catch (...)
  {
    return 0;
  }
  return 1;
}

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 5 of 5

Anonymous
Not applicable

Thanks a lot! This was a huge help and clearly set me on the right direction. Thanks again.

0 Likes