CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

示例注释对象创建

2023-1-1 04:27| 发布者: admin| 查看: 331| 评论: 0|来自: AutoCAD

下面的代码示例实现了许多可用于注释缩放的重要函数。有关更多信息,请查看 ObjectARX 参考指南。

void CAnnotationApp::adskAnnotationScalingaddAnnoEnt()
{
 AcGePoint3d insPnt;
 // pick a point on screen for the object
 int res = acedGetPoint(NULL, _T("\nPick point for object : "), asDblArray(insPnt));
 // if ok
if (res == RTNORM)
  {
    Acad::ErrorStatus es;
    // lets carry out the process to try and create a custom scale of 1:22
    // first, get the current drawing
    AcDbDatabase *dwg = curDoc()->database();
    
    // create my annotation scale object, may as well set it to the current scale in case my scale is already set
    AcDbAnnotationScale *myAnnotationScale = dwg->cannoscale();
    // also create one on the stack so we don't have to worry about deleting it later (addContext makes a copy of the passed pointer)
    AcDbAnnotationScale scale; 
    // what scale are we set too?
    AcDbAnnotationScale *curScale = dwg->cannoscale();
    AcString curScaleName;
    // get the name of the scale
    curScale->getName(curScaleName);
    // if we are not already set to my 1:22 scale then we need to add it
    if (_tcscmp(curScaleName, _T("MyScale 1:22")))
    {
      // next get the objectContextManager
      AcDbObjectContextManager *contextManager = dwg-
>objectContextManager();      // if ok
      if (contextManager)
      {
        // now get the Annotation Scaling context collection (named ACDB_ANNOTATIONSCALES_COLLECTION)
        AcDbObjectContextCollection* const contextCollection = contextManager->contextCollection(ACDB_ANNOTATIONSCALES_COLLECTION);
        // if ok
        if (contextCollection) 
        {
          // if it doesn't exist, then lets set it up
          myAnnotationScale = &scale;
          myAnnotationScale->setName(_T("MyScale 1:22"));
          myAnnotationScale->setPaperUnits(1);
          myAnnotationScale->setDrawingUnits(22);          
          // lets check to see if we already have this scale context in the context manager
          bool alreadyHasContext = contextCollection->hasContext(_T("MyScale 1:22"));
          // if not
          if (!alreadyHasContext)
          {
            // add the new context
            es = contextCollection->addContext(myAnnotationScale);
          }
          // now set the current dwg annotation scale to the newly created scale context 1:22, not a requirement
          es = dwg->setCannoscale(myAnnotationScale);
        }
      }
    }
    // next, create a new instance of my custom object, this is derived from AcDbText so that means the 
    // Annotation Context framework is already implemented for us
    AcDbObjectPointer<asdkMyAnnotativeObject> ent;
    ent.create();
    // set the properties for it
    ent->setDatabaseDefaults();
    ent->setPosition(insPnt);
    // set the AcDbText height, because we are derived from AcDbText
    // the Annotation framework is already in place
    ent->setHeight(1);
    ent->setTextString(_T("AcDbText Derived Annotative Text - Scales automatically"));
    // now set my own Text height, this will show how to utilise the Annotation
    // framework - see the worldDraw/viewportDraw of the custom entity
    ent->setMyTextHeight(1);
    ent->setMyTextString(_T("My Custom Object Text - code implemented to handle scaling Framework"));
    // now add to the current space, open it for write
    AcDbBlockTableRecordPointer curSpace(curDoc()->database()->currentSpaceId(), AcDb::kForWrite);
    // if ok
    if (curSpace.openStatus() == Acad::eOk)
      curSpace->appendAcDbEntity(ent);
    // now add to the entity
    AcDbAnnotativeObjectPE *annotationPE = ACRX_PE_PTR(ent, AcDbAnnotativeObjectPE);
    // if ok
    if (annotationPE)
    {
      // now get the Object Context PEX
      AcDbObjectContextInterface *objectContextInterface = ACRX_PE_PTR(ent, AcDbObjectContextInterface);
      // if ok
      if (objectContextInterface) 
      {
        // set it to be annotative
        es = annotationPE->setAnnotative(ent, true);
        // add My scale context to the list of contexts        es = objectContextInterface->addContext(ent, *myAnnotationScale);
      }
      // all done!
    }
  }
}

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 13:18

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部