【MSCE C#】老师您好,想问一下,CellHeaderElement怎么变成注释单元,可以响应注释比例的变化

如题

Parents
  • 可能存在两种情况:

    1.创建单元的时候就可以设置成注释单元,这是软件操作的层面。

    2.第二种代码控制的情况,伪码:

    CellHeaderElement che=.....
    AnnotationHandler ah = AnnotationHandler.GetAsAnnotationHandler(che);
    ah.AddAnnotationScale(Session.Instance.GetActiveDgnModelRef);
    ah.AddToModel()

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

    中国市政工程西北设计研究院有限公司武汉分院


    Answer Verified By: nadine z 

Reply
  • 可能存在两种情况:

    1.创建单元的时候就可以设置成注释单元,这是软件操作的层面。

    2.第二种代码控制的情况,伪码:

    CellHeaderElement che=.....
    AnnotationHandler ah = AnnotationHandler.GetAsAnnotationHandler(che);
    ah.AddAnnotationScale(Session.Instance.GetActiveDgnModelRef);
    ah.AddToModel()

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

    中国市政工程西北设计研究院有限公司武汉分院


    Answer Verified By: nadine z 

Children
  • 郑大师,这种方法不可行,获取到的 AnnotationHandler ah 是空值

  • 该答案已经被原发帖人确认,说明答案是正确的。我也这么使用过。推测是您代码的问题。可否贴出您的全部测试代码供我们分析?



  • List<Element> listElems = new List<Element>();
    DgnFile dgnFile = Session.Instance.GetActiveDgnFile();
    DgnModel dgnModel = Session.Instance.GetActiveDgnModel();
    TextBlockProperties txtBlockProp = new TextBlockProperties(dgnModel);
    txtBlockProp.IsViewIndependent = false;
    ParagraphProperties paraProp = new ParagraphProperties(dgnModel);
    DgnTextStyle txtStyle = DgnTextStyle.GetSettings(dgnFile);
    RunProperties runProp = new RunProperties(txtStyle, dgnModel);
    TextBlock txtBlock = new TextBlock(txtBlockProp, paraProp, runProp, dgnModel);
    txtBlock.AppendText("This is a Element");
    TextElement text = (TextElement)TextElement.CreateElement(null, txtBlock);
    listElems.Add(text);
    DPoint3d[] ptArr = new DPoint3d[5];
    ptArr[0] = new DPoint3d(-15 * 10000, -5 * 10000, 0 * 10000);
    ptArr[1] = new DPoint3d(-15 * 10000, 5 * 10000, 0 * 10000);
    ptArr[2] = new DPoint3d(-5 * 10000, 5 * 10000, 0 * 10000);
    ptArr[3] = new DPoint3d(-5 * 10000, -5 * 10000, 0 * 10000);
    ptArr[4] = new DPoint3d(-15 * 10000, -5 * 10000, 0 * 10000);
    ShapeElement shapeEle = new ShapeElement(dgnModel, null, ptArr);
    DPlacementZX dPlaceZX = DPlacementZX.Identity;
    dPlaceZX.Origin = new DPoint3d(-10 * 10000, 0, 0);
    DEllipse3d ellipse = new DEllipse3d(dPlaceZX, 5 * 10000, 5 * 10000, Angle.Zero, Angle.TWOPI);
    EllipseElement elliElem = new EllipseElement(dgnModel, null, ellipse);
    listElems.Add(shapeEle);
    listElems.Add(elliElem);
    DPoint3d ptOri = new DPoint3d();
    DMatrix3d rMatrix = DMatrix3d.Identity;
    DPoint3d ptScale = new DPoint3d(1, 1, 1);
    CellHeaderElement cellHeaderEle = new CellHeaderElement(dgnModel, "CellEle", ptOri, rMatrix, listElems);
    AnnotationHandler ah = AnnotationHandler.GetAsAnnotationHandler(cellHeaderEle);
    if(ah !=null)
    {
    ah.AddAnnotationScale(Session.Instance.GetActiveDgnModelRef());
    ah.AddToModel();
    }

    符老师,这是代码。ah获取的时候是空值

  • 哦,您这种是在线创建的Cell,不是从单元库中调出的Cell。我们需要从单元库中调出的Cell,且该Cell在单元库中的模型属性中需要设置Can be Placed as AnnotationCell为True才能成功转换。目前在线创建的Cell用公开的API还没有找到如何创建成AnnotationCell的办法。可能需要寻求未公开API了。



  • 测试这段代码可以打开这个选项,测试了C++ API是没问题的,可以考虑将元素加入到model后,然后打开这个选项

    void anTest(ElementID id)
    {
    	EditElementHandle eeh(id, ACTIVEMODEL);
    	if(eeh.IsValid())
    	{
    		if(auto handler = dynamic_cast<IAnnotationHandler*>(&eeh.GetHandler()))
    		{
    			auto r = eeh.GetElementRef();
    			handler->AddAnnotationScale(eeh, ACTIVEMODEL);
    			eeh.ReplaceInModel(r);
    		}
    	}
    }

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

    中国市政工程西北设计研究院有限公司武汉分院