solidworks二次开发:在装配体文件中添加零件

 HRESULT retval,status;

 LPMODELDOC pModelDoc;

 LPSLDWORKS m_iSldWorks;

 m_iSldWorks=TheApplication->GetSWApp();//初始化  

retval=m_iSldWorks->get_IActiveDoc(&pModelDoc);  

if(pModelDoc==NULL)  {   

AfxMessageBox(_T("获取活动文档失败"));   

return;  

}  

LPASSEMBLYDOC pAssmDoc;  

retval=pModelDoc->QueryInterface(IID_IAssemblyDoc,(LPVOID*)&pAssmDoc);

 if(pAssmDoc==NULL)  {

  AfxMessageBox(_T("获取指向当前活动装配体文档接口指针失败"));   

return;

 }  

long Errors;

 long Warnings;

 LPMODELDOC2 retval0;  

m_iSldWorks->OpenDoc6(_T("G://1.SLDPRT"),swDocPART,swOpenDocOptions_Silent,(unsigned short )"",&Errors,&Warnings,&retval0);//打开文件在缓冲区

 status = retval0->put_Visible(false );  

LPCOMPONENT2 pComDisp;  

pAssmDoc->AddComponent4(_T("G://1.SLDPRT"),NULL,0,0,0,&pComDisp);  

if(pComDisp==NULL)  {   

AfxMessageBox(_T("添加部件失败"));   

return;  

}  

LPMODELDOC pModel;  

m_iSldWorks->IActivateDoc(_T("装配体1"),&pModel);  //插入另一个零件  

retval=pModelDoc->QueryInterface(IID_IAssemblyDoc,(LPVOID*)&pAssmDoc);  

if(pAssmDoc==NULL)  {   

AfxMessageBox(_T("获取指向当前活动装配体文档接口指针失败"));  

 return;  

}

 LPMODELDOC2 retval1;  

m_iSldWorks->OpenDoc6(_T("G://直槽铰刀新.SLDPRT"),swDocPART,swOpenDocOptions_Silent,(unsigned short *)"",&Errors,&Warnings,&retval1);//打开文件在缓冲区  

status = retval1->put_Visible(false );  

pAssmDoc->AddComponent4(_T("G://直槽铰刀新.SLDPRT"),NULL,0,0,0,&pComDisp);

 if(pComDisp==NULL)  {   

AfxMessageBox(_T("添加部件失败"));  

 return;

 }  

m_iSldWorks->IActivateDoc(_T("装配体1"),&pModel);

你可能感兴趣的:(solidworks二次开发)