sixhit@163.com 发表于 2018-7-28 15:49:26

打印问题 获得打印机列表后CAD崩溃

本帖最后由 sixhit@163.com 于 2018-7-28 15:59 编辑

运行网上找到的这段代码void fSetPlotMedia(),想通过这段代码获得打印机和相应纸张。运行后,能够正常选择打印机和纸张,但是之后就引起CAD 致命错误。有高手能指点一下问题出在哪儿吗?


void fSetPlotMedia()
{
        AcApLayoutManager *pLayMan = NULL;
        pLayMan = (AcApLayoutManager *)
                acdbHostApplicationServices()->layoutManager();
        //get the active layout
        AcDbLayout *pLayout = pLayMan->findLayoutNamed(
                pLayMan->findActiveLayout(TRUE),TRUE);

        //get the PlotSettingsValidator
        AcDbPlotSettingsValidator *pPSV =NULL;
        pPSV = acdbHostApplicationServices()->plotSettingsValidator();
        //refresh the Plot Config list
        pPSV->refreshLists(pLayout);

        //get all the Plot Configurations
        AcArray<const ACHAR *> mDeviceList;
        pPSV->plotDeviceList(mDeviceList);

        acutPrintf(_T("\nPlot Configuration List :"));
        int nLength = mDeviceList.length();

        for(int nCtr = 0;nCtr<nLength ;nCtr++)
        {
                acutPrintf(_T("\n %i) - %s"),(nCtr + 1), mDeviceList.at(nCtr));
        }

        //get the user input for listing the Media Names
        int nSel;
        int mRes =RTNONE;

        while(RTNORM != mRes)
        {
                acedInitGet((RSG_NONULL + RSG_NONEG + RSG_NOZERO),NULL);
                mRes = acedGetInt(_T("\nSelect the Plot Configuration number: "),
                        &nSel);
                if (nSel > nLength)
                {
                        acutPrintf(_T("\nEnter a number between 1 to %i"),nLength);
                        mRes = RTNONE;
                }
        }

        //select the selected Plot configuration
        pPSV->setPlotCfgName(pLayout,mDeviceList.at(--nSel));
        //list all the paper sizes in the given Plot configuration
        AcArray<const ACHAR *> mMediaList;
        const ACHAR *pLocaleName;
        pPSV->canonicalMediaNameList(pLayout,mMediaList);

        acutPrintf(_T("\nMedia list for Plot Configuration - %s:"),
                mDeviceList.at(nSel));

        nLength = mMediaList.length();
        int nCtr ;
        for(nCtr = 0;nCtr<nLength ;nCtr++)
        {
                //get the localename
                pPSV->getLocaleMediaName(pLayout,mMediaList.at(nCtr),pLocaleName);
                acutPrintf(_T("\n %i)\n   Name:%s \n   Locale Name: %s "),
                        (nCtr + 1),mMediaList.at(nCtr),pLocaleName);
        }
        mRes =RTNONE;
        while(RTNORM != mRes)
        {
                acedInitGet((RSG_NONULL + RSG_NONEG + RSG_NOZERO),NULL);
                mRes = acedGetInt(
                        _T("\nSelect the Media by entering the number: "),
                        &nSel);

                if (nSel > nLength)
                {
                        acutPrintf(_T("\nEnter a number between 1 to %i"),nLength);
                        mRes = RTNONE;
                }
        }
        //set selected Media for the layout
        pPSV->setCanonicalMediaName(pLayout,mMediaList.at(--nSel));
        pLayout->close();
}


上传的截图顺序反了,只好把代码重新粘上来。见谅。

llp0420 发表于 2018-8-1 16:32:43

看不懂 哈哈哈哈IIII
页: [1]
查看完整版本: 打印问题 获得打印机列表后CAD崩溃