[ARX]如何在ARX或者COM中设置CAD的支持路径呢?
IAcadPreperties里有一个函数SETObjectarxPath但是我不知道,怎么用,希望大家提点意见或者例子
VBA中很好设置,但是我在ARX中就是有问题,也不知道怎么回事 ARX不能直接作
只能通过COM作
我对COM不了解,sorry 把你的代码贴出来看看。
我前两天在本版发布一个“使用VC通过OLE控制AutoCAD”的实例,你可以先参考一下。
另外,你是想做打包程序吧,我这两日也正在研究这方面内容,不过我是直接用InstallShield来做的,其实比VC还简单。等做完之后准备和大家共享一下。 确实,我是想做打包程序,但是没办法用COM实现,后来想了一个别的办法,尽管有点复杂,但是也是一种解决方法,我把代码贴出来,希望对大家有借鉴作用: BOOL CFCCHApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
CString arxPath;
arxPath=this->m_pszHelpFilePath; /*关键是这里,我找不出别的函数来得到EXE程序的路径,所以就用这个函数来得到帮助文件的路径,实际上,帮助文件没有,但是路径有用,所以,把帮助文件名减掉,就可以得到EXE文件的路径,这样的话,就可以不设置支持路径了*/
arxPath=arxPath.Left(arxPath.GetLength()-8);
IAcadApplication IAcadApp;
// IAcadPreferencesFiles IAcadPreFiles;
IAcadMenuGroup *pMenu;
BOOL bRet = IAcadApp.CreateDispatch(_T("AutoCAD.Application"));
if(bRet)
{
IAcadApp.SetVisible(TRUE);
IAcadApp.LoadArx(arxPath+"cugsetcadtitle.arx");
IAcadApp.LoadDVB(arxPath+"dvb\\XM_0000MenuSelect.dvb");
IAcadApp.LoadDVB(arxPath+"dvb\\FQ_0000MenuSelect.dvb");
}
else
{
AfxMessageBox("没有正确安装AutoCAD 2002,\r\n请核对后运行",MB_ICONERROR | MB_OK);
return FALSE;
}
return FALSE;
}
另外,我上面可以在CAD启动的时候自动加载ARX和VBA,但是我到现在也没找出来,如何利用COM来实现自动加载自定义的菜单,各位指点指点 arxPath=this->m_pszHelpFilePath; /*关键是这里,我找不出别的函数来得到EXE程序的路径,所以就用这个函数来得到帮助文件的路径,实际上,帮助文件没有,但是路径有用,所以,把帮助文件名减掉,就可以得到EXE文件的路径,这样的话,就可以不设置支持路径了*/
////////////////////////////////////////////////
上面你是要得到什么路径?
我原来是将安装路径写到註册表
同时安装的时候生成快捷方式,
在快捷方式中添加支持路径,
其它设置用profiles设置。。。。。。 写到注册表中有个问题:如果移动了文件夹后,程序就不正常了
我上面可以实现无论文件夹在哪里,都可以正常运行 参考(COM): // 读取Config.ini文件,配置AutoCAD
void acadConfig()
{
// 取得ARX模块路径
int len = GetModuleFileName(_hdllInstance, appFullPath, MAX_PATH);
CString appPath = appFullPath;
appPath = appPath.Left(appPath.ReverseFind('\\'));
CString strConfFilePath = appPath + "\\config.ini";
CFileFind finder;
if ( finder.FindFile(strConfFilePath, 0) == FALSE)
return;
IAcadApplication * pAcad = NULL;
LPDISPATCH pDisp = NULL;
if (!getApplication(&pDisp))
{
pAcad->Release();
return;
}
HRESULT hr = S_OK;
hr = pDisp->QueryInterface(IID_IAcadApplication, (LPVOID*)&pAcad);
if (FAILED(hr))
return;
IAcadPreferences * pPrefs = NULL;
IAcadPreferencesFiles * pPrefsFiles = NULL;
pAcad->get_Preferences(&pPrefs);
pPrefs->get_Files(&pPrefsFiles);
BSTR bstrTemp;
pPrefsFiles->get_SupportPath(&bstrTemp);
USES_CONVERSION;
CComBSTR cbstrTemp = (CComBSTR) bstrTemp;
CString strSupportPath = OLE2T(cbstrTemp);
// 读取INI文件中的信息,配置AutoCAD
// 添加支持路径
CString strBuf;
int count = 0;
count = GetPrivateProfileString("PATH", "path1", "NONE", strBuf.GetBuffer(MAX_PATH), MAX_PATH, strConfFilePath);
strBuf.ReleaseBuffer();
CString path1 = appPath + "\\" + strBuf;
if (strSupportPath.Find(path1) == -1)
{
strSupportPath = path1 + ";" + strSupportPath;
bstrTemp = T2OLE(strSupportPath);
pPrefsFiles->put_SupportPath(bstrTemp);
}
count = GetPrivateProfileString("PATH", "path2", "NONE", strBuf.GetBuffer(MAX_PATH), MAX_PATH, strConfFilePath);
strBuf.ReleaseBuffer();
CString path2 = appPath + "\\" + strBuf;
if (strSupportPath.Find(path2) == -1)
{
strSupportPath = path2 + ";" + strSupportPath;
bstrTemp = T2OLE(strSupportPath);
pPrefsFiles->put_SupportPath(bstrTemp);
}
// 设置其它信息
return;
}
//*********************
pPrefsFiles->put_SupportPath(bstrTemp);
这段程序可以在 'ObjectARX工作日志' 中找到. config.ini文件不在AutoCAD目录下可以吗? 你完全不用考虑ini文件,看一看pPrefsFiles->put_SupportPath(bstrTemp);这里怎么添加路径就可以了. 我试试,有了结果告诉大伙 还有一个问题,希望王斑竹指点指点:CAD启动的时候如何自动加载自定义的菜单文件?我现在用的是acedCommand(),能够有别的方法?我看了你的程序日志,有这种方法,但我觉得比较杂,希望你能精练给个示例,谢谢了
页:
[1]