2017-01-22 1 views
-1

이미 실행중인 AutoCAD 인스턴스에서 cirle을 그려 기존 도면에 추가하려고합니다.C에서 AutoCAD의 원 그리기

그럴 수 있습니까? 가장 쉬운 방법은 무엇입니까?

들으

답변

0

이 C에서 아무것도 찾을 수 없습니다하지만 여기 Developer Guide에서 C# 예제 : 그것은 복잡 할 수 있습니다 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++ 및 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 이미 실행중인 인스턴스"를 언급 한 바와 같이, 당신이 일반적으로 액티브 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()); 
    } 
}