找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1108|回复: 1

[每日一码] ARX打印窗口内容到DWF文件

[复制链接]

已领礼包: 40个

财富等级: 招财进宝

发表于 2017-2-15 00:11:26 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

Issue

I want to Window plot a drawing to DWF, I'm using COM to plot the DWF but how do I setup the Plot Settings so that it plots using a couple of Window coordinates?


Solution

In ObjectARX you need to use the AcDbPlotSettingsValidator class to setup the Plot. Here is some code which shows you what to do. Note this is using the Window coordinates as the extents of the drawing. This is purely for test purposes - if you want to plot the extents then use setPlotType (pLayout, AcDbPlotSettings::kExtents). There is also a Visual LISP example following the ObjectARX code.

#import "acax19ENU.tlb" no_namespace
#include "acaplmgr.h"
static void ASDKTS66871_PlotWindow_COM_testPlot(void)
{
  // Use ActiveX interface to get the application object
  IAcadApplicationPtr pAcad = acedGetAcadWinApp()->GetIDispatch(FALSE);
 
  //get the path to plotter configuration
  _bstr_t szPrinterPath;
  szPrinterPath = pAcad->Preferences->GetFiles()->GetPrinterConfigPath() + _bstr_t("\\DWF6 ePlot.pc3");
  // get the current database
  AcDbDatabase *curDocDB = acdbHostApplicationServices()->workingDatabase();
  // get a pointer to the layout manager
  AcApLayoutManager *pLayoutManager = (AcApLayoutManager *)acdbHostApplicationServices()->layoutManager();
  const ACHAR *layoutName = pLayoutManager->findActiveLayout (true);
  // get the current layout
  AcDbLayout *pLayout = pLayoutManager->findLayoutNamed (layoutName, true);
  // if we got it ok
  if (pLayout != NULL)
  {
    Acad::ErrorStatus es;
    // get the plotsetttings class
    AcDbPlotSettingsValidator *pPlotSettingsValidator = acdbHostApplicationServices()->plotSettingsValidator();
    // if we got it ok
    if (pPlotSettingsValidator != NULL)
    {
      // Refresh the layout lists in order to use it
      pPlotSettingsValidator->refreshLists (pLayout);
      // change the current layout plotter
      es = pPlotSettingsValidator->setPlotCfgName (pLayout, szPrinterPath); 
      // set the window to plot as the extents of the drawing
      es = pPlotSettingsValidator->setPlotWindowArea (pLayout,
        curDocDB->extmin ().x,
        curDocDB->extmin ().y,
        curDocDB->extmax ().x,
        curDocDB->extmax ().y);
      // set the orgin
      es = pPlotSettingsValidator->setPlotOrigin (pLayout,
        curDocDB->extmin ().x,
        curDocDB->extmin ().y);
      // set to plot centred
      es = pPlotSettingsValidator->setPlotCentered (pLayout, true);
      // setup the plot type to window
      es = pPlotSettingsValidator->setPlotType (pLayout, AcDbPlotSettings::kWindow);
      // set the scale
      es = pPlotSettingsValidator->setStdScaleType (pLayout, AcDbPlotSettings::StdScaleType::kScaleToFit);
 
      // we have to close the layout here because the last parameter of
      // findLayoutNamed is true, leave layout open
      pLayout->close ();
    }
  }
 
 
  // get the current document
  IAcadDocumentPtr pDoc = pAcad->GetActiveDocument();
  // create a plot object
  IAcadPlotPtr pPlot = pDoc->GetPlot();
  // lets plot
  pPlot->PlotToFile("c:\\test.dwf", szPrinterPath);
}


Note: You do not necessarily need to use COM to plot. Instead you can use ObjectARX functions. A good sample ships with the ObjectARX 2009 SDK. ( ..\ObjectARX 2009\samples\editor\AsdkPlotAPI )

同功能VLISP代码见:http://bbs.xdcad.net/thread-707150-1-1.html
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-4-17 04:16 , Processed in 0.237708 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表