明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: bai_cai101

如何自动新建一个DWG并置为当前!

  [复制链接]
 楼主| 发表于 2005-11-20 16:05:00 | 显示全部楼层

我顶!!问题解决不了我就不让它沉下去了!!板主!帮帮我了!????

 楼主| 发表于 2005-12-8 16:04:00 | 显示全部楼层

我顶!!!

发表于 2005-12-12 13:53:00 | 显示全部楼层
//找到新建文件
AcApDocument* pDoc=NULL;
AcApDocumentIterator* pDocIter;
pDocIter = acDocManager->newAcApDocumentIterator();
for ( ; !pDocIter->done(); pDocIter->step())
{
   if( !strcmp(pDocIter->document()->fileName(), "新建文件名") )
   {
       pDoc = pDocIter->document();
    break;
    }
}
delete pDocIter;
//设成活动文档
if( pDOC)
    acDocManager->activateDocument(pDoc);
发表于 2005-12-22 17:40:00 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
 楼主| 发表于 2006-1-6 08:18:00 | 显示全部楼层

我试了,怎么不行啊!我用的是VC6。0,ARX2000,编译通过,但在CAD2002中运行却没有一点反应!!!WHY??

发表于 2006-1-10 21:04:00 | 显示全部楼层

AcDbDatabase(

bool buildDefaultDrawing = true,

bool noDocument = false);

buildDefaultDrawing Boolean specifying whether or not to build an empty object
noDocument Boolean specifying whether or not to associate this database to the current document
第二个参数
发表于 2006-1-19 16:02:00 | 显示全部楼层

现在工作时间没法上网,偶然路过,发现这个问题居然让老弟如此伤神,实在不忍,特整理一个工程贴上来供参考,其实这个工程也没什么特别的,下面是创建该工程的过程。希望你能结合老金的文章好好理解,因为我再来看这个帖子的几率不大…

(1)使用ObjectARX向导创建一个新工程;
(2)注册一个命令NewDoc,其实现函数为:
void ZffTempNewDoc()
{
 static char pData[] ="acad.dwt";
 acDocManager->executeInApplicationContext(CreateDoc, (void *)pData);
}
(3)将下面的函数复制到ZffTempNewDoc函数的前面:
void CreateDoc( void *pData)
{
 AcApDocument* pDoc = acDocManager->curDocument();
 if (acDocManager->isApplicationContext())
 {
  acDocManager->appContextNewDocument((const char *)pData);
 }
 else
 {
  acutPrintf("\nERROR To Create Doc!\n"); // 这一行老金有个笔误,后一个引号用了中文的,我已经改过来了
 }
}
(4)编译链接程序,启动AutoCAD 2002,执行NewDoc命令即可创建一个新文件,没有对话框的出现。

本帖子中包含更多资源

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

x
发表于 2006-2-6 13:42:00 | 显示全部楼层
//
// ObjectARX defined commands, created by  [2005-5-17], ,

#include "StdAfx.h"
#include "StdArx.h"
#include "dbsymtb.h"
#include "dbents.h"

//-----------------------------------------------------------------------------
// This is command 'NEWDOC, by  [2005-5-17], ,
void ACADnewdoc()
{
#ifdef OARXWIZDEBUG
 acutPrintf ("\nOARXWIZDEBUG - ACADnewdoc() called.");
#endif // OARXWIZDEBUG

 // TODO: Implement the command
 static char pData[] ="acad.dwt";
 acDocManager->executeInApplicationContext(CreateDoc, (void *)pData);

 AcDbDatabase *pdb =acdbHostApplicationServices()->workingDatabase();

 AcDbBlockTable *pBtbl;
    pdb->getSymbolTable(pBtbl, AcDb::kForRead);

    AcDbBlockTableRecord *pBtblRcd;
    pBtbl->getAt(ACDB_MODEL_SPACE, pBtblRcd,
        AcDb::kForWrite);
    pBtbl->close();

    AcDbCircle *pCir1 = new AcDbCircle(AcGePoint3d(1,1,1),
                                       AcGeVector3d(0,0,1),
                                       1.0),
               *pCir2 = new AcDbCircle(AcGePoint3d(4,4,4),
                                       AcGeVector3d(0,0,1),
                                       2.0);
    pBtblRcd->appendAcDbEntity(pCir1);
    pCir1->close();
   
    pBtblRcd->appendAcDbEntity(pCir2);
    pCir2->close();
    pBtblRcd->close();

}

void CreateDoc( void *pData)
{
 AcApDocument* pDoc = acDocManager->curDocument();
 if(acDocManager->isApplicationContext())
 {
  acDocManager->appContextNewDocument((const char *)pData);
 }
 else
  acutPrintf("\nERROR To Create Doc!\n");
}



----------------------------------------------
QQ:224310836,bai_cai101@163.com!欢迎交流!!

----------------------------------------------------------------

上述代码执行后,圆并未画在新建出来的DWG文挡上,而画在了前一个DWG文挡上,这样新建的DWG并不是当前的WorkingDatabase

发表于 2006-2-6 13:59:00 | 显示全部楼层
//
// ObjectARX defined commands, created by  [2005-5-17], ,

#include "StdAfx.h"
#include "StdArx.h"
#include "dbsymtb.h"
#include "dbents.h"

//-----------------------------------------------------------------------------
// This is command 'NEWDOC, by  [2005-5-17], ,
void ACADnewdoc()
{
#ifdef OARXWIZDEBUG
 acutPrintf ("\nOARXWIZDEBUG - ACADnewdoc() called.");
#endif // OARXWIZDEBUG

 // TODO: Implement the command
 static char pData[] ="acad.dwt";
 acDocManager->executeInApplicationContext(CreateDoc, (void *)pData);

 AcDbDatabase *pdb =acdbHostApplicationServices()->workingDatabase();

 AcDbBlockTable *pBtbl;
    pdb->getSymbolTable(pBtbl, AcDb::kForRead);

    AcDbBlockTableRecord *pBtblRcd;
    pBtbl->getAt(ACDB_MODEL_SPACE, pBtblRcd,
        AcDb::kForWrite);
    pBtbl->close();

    AcDbCircle *pCir1 = new AcDbCircle(AcGePoint3d(1,1,1),
                                       AcGeVector3d(0,0,1),
                                       1.0),
               *pCir2 = new AcDbCircle(AcGePoint3d(4,4,4),
                                       AcGeVector3d(0,0,1),
                                       2.0);
    pBtblRcd->appendAcDbEntity(pCir1);
    pCir1->close();
   
    pBtblRcd->appendAcDbEntity(pCir2);
    pCir2->close();
    pBtblRcd->close();

}

void CreateDoc( void *pData)
{
 AcApDocument* pDoc = acDocManager->curDocument();
 if(acDocManager->isApplicationContext())
 {
  acDocManager->appContextNewDocument((const char *)pData);
 }
 else
  acutPrintf("\nERROR To Create Doc!\n");
}



----------------------------------------------
QQ:224310836,bai_cai101@163.com!欢迎交流!!

---------------------------------------------------------------------

该例新建的DWG文挡不是当前的WorkingDatabase的指针,而是前一个。希望作者

或哪位高手解决一下这个问题。

发表于 2007-8-15 11:28:00 | 显示全部楼层
Try
            Dim cadApp As AcadApplication = GetObject(, "AutoCAD.Application.17")
            Dim olDb As Database = HostApplicationServices.WorkingDatabase
            Dim db As Database = New Database(True, False)
            HostApplicationServices.WorkingDatabase = db
            Dim trans As Transaction = db.TransactionManager.StartTransaction()
            Dim bt As BlockTable = trans.GetObject(db.BlockTableId, OpenMode.ForWrite)
            Dim br As Circle = CreateCircle(db, bt)
            db.SaveAs("d:\ff.dwg", DwgVersion.AC1015)
            HostApplicationServices.WorkingDatabase = olDb
            trans.Commit()
            trans.Dispose()
            Dim cadDoc As AcadDocument = cadApp.Documents.Open("d:\ff.dwg")
            cadDoc.WindowState = Common.AcWindowState.acMax
            cadDoc.Application.ZoomExtents()
        Catch ex As Exception

        End Try
    End Sub
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 04:24 , Processed in 0.196328 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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