2017-01-22 21 views
-1

すでに実行中のAutoCADのインスタンスにCirleを描画して、既存の図面に追加しようとしています。AutoCADの円をCから作成する

これは可能ですか?最も簡単な方法は何ですか?

Thxを

答えて

0

はCで何かを見つけることが、ここDeveloper GuideからC#​​の例ですできませんでした:

using Autodesk.AutoCAD.Runtime; 
using Autodesk.AutoCAD.ApplicationServices; 
using Autodesk.AutoCAD.DatabaseServices; 
using Autodesk.AutoCAD.Geometry; 

[CommandMethod("AddCircle")] 
public static void AddCircle() 
{ 
    // Get the current document and database 
    Document acDoc = Application.DocumentManager.MdiActiveDocument; 
    Database acCurDb = acDoc.Database; 

    // Start a transaction 
    using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) 
    { 
     // Open the Block table for read 
     BlockTable acBlkTbl; 
     acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, 
            OpenMode.ForRead) as BlockTable; 

     // Open the Block table record Model space for write 
     BlockTableRecord acBlkTblRec; 
     acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], 
             OpenMode.ForWrite) as BlockTableRecord; 

     // Create a circle that is at 2,3 with a radius of 4.25 
     Circle acCirc = new Circle(); 
     acCirc.SetDatabaseDefaults(); 
     acCirc.Center = new Point3d(2, 3, 0); 
     acCirc.Radius = 4.25; 

     // Add the new object to the block table record and the transaction 
     acBlkTblRec.AppendEntity(acCirc); 
     acTrans.AddNewlyCreatedDBObject(acCirc, true); 

     // Save the new object to the database 
     acTrans.Commit(); 
    } 
} 
0

純粋なCでは、それは、とても幸運を複雑にすることができます。 しかし、あなたはC++とARXはこれを試して使用している場合:

Acad::ErrorStatus AddCircle(AcGePoint3d center , double r , AcDbObjectId& id , AcDbBlockTableRecord* pBlock) 
{ 
    AcDbCircle* pCirEnt = NULL; 
    pCirEnt = new AcDbCircle(); 
    pCirEnt->setCenter(center); 
    pCirEnt->setRadius(r); 
    Acad::ErrorStatus es = Add(pCirEnt , pBlock); 
    es = pCirEnt->close(); 
    id = pCirEnt->objectId(); 
    return es ; 
} 


Acad::ErrorStatus Add(AcDbEntity * pEnt, AcDbBlockTableRecord* Blok) 
{ 
    if (!pEnt) {  
     return Acad::eNullEntityPointer ; 
    } 

    Acad::ErrorStatus es; 
    if (!Blok) 
    { 
     Blok = getModelSpace(AcDb::kForWrite); 
     if (!Blok) return Acad::eInvalidOwnerObject; 
    } 
    if (Blok->isWriteEnabled() == Adesk::kFalse) 
    { 
     AcDbObject* pObj = NULL;  
     es = acdbOpenObject(pObj,Blok->objectId(),AcDb::kForWrite) ; 
     Blok = AcDbBlockTableRecord::cast(pObj); 
    } 
    if ((es = Blok->appendAcDbEntity(pEnt)) != Acad::eOk) // eAlreadyInDb = wcześniej wstawione do innego bloku. 
    { 
     Blok->close(); 
     return es; 
    } 
    Blok->close(); 
    return Acad::eOk; 
} 

AcDbBlockTableRecord* getModelSpace(AcDb::OpenMode mode) 
{ 
    AcDbBlockTableRecord* Blok = NULL; 
    Acad::ErrorStatus es; 
    AcDbDatabase * pDb = acdbHostApplicationServices()->workingDatabase(); 
    if (!pDb) return NULL; 
    AcDbBlockTable* pTbl = NULL; 
    if ((es= pDb->getBlockTable(pTbl, AcDb::kForRead)) != Acad::eOk ) 
     return NULL; 
    if ((es = pTbl->getAt(ACDB_MODEL_SPACE, Blok, mode)) != Acad::eOk) 
    { 
     pTbl->close(); 
     return NULL; 
    } 
    pTbl->close(); 

    return Blok; 
} 
1

あなたは、「AutoCADのの、既に実行中のインスタンス」を述べたように、私はあなたが通常のActiveX COMオートメーション経由して、AutoCADのを自動化したいと仮定しています。 AcadApplicationインターフェイス(ではAcDbまたは.NET Mgd参照を使用できません)を使用する必要があります。

ここには、this blog postのActiveX C++汎用コードサンプルがあります。 acac19enu.tlbの参照に注意してください.19はAutoCADのバージョンを表します。現在のバージョンはAutoCAD 2017(ライブラリバージョン:21)です。

#import "acax19ENU.tlb" no_namespace 
#include <rxmfcapi.h> 
#include <axpnt3d.h> 
void fAddAttribute() 
{ 
    try 
    { 
    // get the ActiveX application object from AutoCAD, inc ref count 
    IAcadApplicationPtr pAcadApp = acedGetAcadWinApp()->GetIDispatch(TRUE); 
    // now get the active doc 
    IAcadDocumentPtr pActiveDoc = pAcadApp->ActiveDocument; 
    IAcadBlockPtr pBlock = NULL; 
    TCHAR *pBlkName = _T("some_block_name"); 
    // create an activex compatible insertion point3d 
    AcAxPoint3d axInsPnt(0,0,0); 
    // now add the block name 
    pBlock = pActiveDoc->Blocks->Add(axInsPnt.asVariantPtr(),_bstr_t(pBlkName)); 
    // now add an Attribute to the block 
    IAcadAttributePtr pAttDef; 
    pAttDef = pBlock->AddAttribute(1.0, (AcAttributeMode)0 , 
     _bstr_t("Type the employee name"), axInsPnt.asVariantPtr(), 
     _bstr_t("empname"),_bstr_t("")); 
    //attribute added 
    } 
    catch(_com_error &es) 
    { 
    acutPrintf(L"\nError : %s", es.ErrorMessage()); 
    } 
} 
関連する問題