开发者

AutoCad XData vanishing issue

开发者 https://www.devze.com 2023-01-18 19:22 出处:网络
I have a C# application that interfaces with AutoCad. It\'s job is to rip through all of the entities on a model and find the ones that apply to what we\'re doing by looking for the presence of specif

I have a C# application that interfaces with AutoCad. It's job is to rip through all of the entities on a model and find the ones that apply to what we're doing by looking for the presence of specific XData tags.

The problem is when the drafters move a block to any layer that is marked as "invisible" (i.e. turn layer off) then the xdata is not discoverable via the usual loop:

foreach (AcadEntity ent in ACAD.ActiveDocument.ModelSpace)
{
    ... get xData from the entity.
}

I've tried t开发者_Python百科urning the layer on again using the following code:

ACAD.ActiveDocument.Layers.Item("HIDDENLAYER").LayerOn = true;
ACAD.Update();
foreach...

... but the xData doesn't seem to come back with it. It is as though moving it to an invisible layer stripped the XData from the object. That would be bad.

Is there a "proper" way to get the XData from items on invisible layers?

Thanks.


I can't reproduce this in AutoCAD (Map) 2012. What version of AutoCAD are you using?

What's are you actually doing inside ... get xData from the entity.? I did this:

    static AcadApplication ACAD
    {
        get
        {
            return
                Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication as AcadApplication;
        }
    }

    [CommandMethod("tlo")]
    public static void TestLayerOff()
    {
        foreach (AcadEntity ent in ACAD.ActiveDocument.ModelSpace)
        {
            //... get xData from the entity.
            object xdata, xdataType;
            ent.GetXData("MyRegisteredAppName", out xdataType, out xdata);
            //... read and spit out the xdata to the command line to see what we got
        }
    }

It worked after I turned off the layer my xdata'ed entities were on. It also worked after I moved them to a different layer that was off. Is there a step to reproduce that I'm missing? What exactly are "the drafters" doing when they "move a block"?

Also, if you're concerned that the xdata is going away for real, use the XDLIST command to view it directly in AutoCAD.

Finally, I'll throw out a general recommendation to get away from the COM stuff and use the native C# API, which will do everything you're trying to do here.


For now, the answer has become "Don't move this item to a hidden layer." Instead, I'm marking the layer as hidden by default before I place the XData, and that seems to be working fine. I'm not sure how the XData vanishes, but for now, this is working for me.

I'm still curious if anyone has any suggestions as to how the XData goes away.


Xdata is volatile. If you ATTSYNC a block it goes away. This may not be related to your specific problem but it is a solid reason to not rely on Xdata.

0

精彩评论

暂无评论...
验证码 换一张
取 消