.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Flip State Names

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
BrentBurgess1980
858 Views, 2 Replies

Flip State Names

Hi All,

 

DynamicBlockReferencePropertyCollection dynPropColl = bref.DynamicBlockReferencePropertyCollection;
                        foreach(DynamicBlockReferenceProperty prop in dynPropColl)
                            {
                            object[] values = prop.GetAllowedValues();

The allowable values you can select from are 1 or 0 (makes sense), but is there any exposed/other way to show the "displayed" allowed values that are shown in the properties palette? My initial thought is that there isn't anything, given the properties in DynamicBlockReferenceProperty. Happy to be proven wrong though.

 Flip State.JPG

 

Cheers,

 

Brent

2 REPLIES 2
Message 2 of 3

Using the API DynamicBlockReferencePropertyCollection to access list of flip states is the only recommended way to access flip state names.

There is method which is undocumented or unsupported to access the visibility state of dynamic blocks. Similarly, flip states can be accessed as shown below(modified code from the blog):

http://adndevblog.typepad.com/autocad/2012/05/accessing-visible-entities-in-a-dynamic-block.html
(Please note, it is not recommended to extract information from extension dictionary ACAD_ENCHANCEDBLOCK and API used in this implementation may change with out notice and hence is not supported)

 

[CommandMethod("DynablockFlipStates")]
public void DynablockFlipStates()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;
    PromptResult pr = ed.GetString("\nEnter block name: ");
    if (pr.Status != PromptStatus.OK)
        return;
    using (Transaction Tx = db.TransactionManager.StartTransaction())
    {
        BlockTable bt = Tx.GetObject(
            db.BlockTableId,
            OpenMode.ForRead) as BlockTable;

        if (!bt.Has(pr.StringResult))
        {
            ed.WriteMessage("\nBlock doesn't exist :(");
            return;
        }
        BlockTableRecord btr = Tx.GetObject(
            bt[pr.StringResult],
            OpenMode.ForRead)
                as BlockTableRecord;
        if (!btr.IsDynamicBlock)
        {
            ed.WriteMessage("\nNot a dynamic block :(");
            return;
        }

        if (btr.ExtensionDictionary == null)
        {
            ed.WriteMessage("\nNo ExtensionDictionary :(");
            return;
        }

        DBDictionary dico = Tx.GetObject(
            btr.ExtensionDictionary,
            OpenMode.ForRead)
                as DBDictionary;


        if (!dico.Contains("ACAD_ENHANCEDBLOCK"))
        {
            ed.WriteMessage(
                "\nACAD_ENHANCEDBLOCK Entry not found :(");
            return;
        }

        ObjectId graphId = dico.GetAt("ACAD_ENHANCEDBLOCK");
        System.Collections.Generic.List<object> parameterIds =
            acdbEntGetObjects(graphId, 360);

        foreach (object parameterId in parameterIds)
        {
            ObjectId id = (ObjectId)parameterId;
            if (id.ObjectClass.Name ==
                "AcDbBlockFlipParameter")
            {
                System.Collections.Generic.List<TypedValue>
                    flipParam = acdbEntGetTypedVals(id);
                System.Collections.Generic.List<TypedValue>.Enumerator enumerator =
                    flipParam.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    ed.WriteMessage("\n    - " + enumerator.Current.TypeCode.ToString() + ",");
                    try
                    {
                        string str = (string)enumerator.Current.Value;
                        ed.WriteMessage("\n . string value : " + str);
                    }
                    catch
                    {
                    }
                }
                break;
            }
        }
        Tx.Commit();
    }
}
public struct ads_name
{
    public IntPtr a;
    public IntPtr b;
};

[DllImport("accore.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr acdbEntGet(long[] objName);

[DllImport("acdb23.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint =
            "?acdbGetAdsName@@YA?AW4ErrorStatus@Acad@@AEAY01_JVAcDbObjectId@@@Z")]
static extern ErrorStatus acdbGetAdsName64(long[] objName, ObjectId id);

private System.Collections.Generic.List<object>
    acdbEntGetObjects(ObjectId id, short dxfcode)
{

    System.Collections.Generic.List<object> result =
        new System.Collections.Generic.List<object>();

    long[] name = new long[] { 0, 0 };
    ErrorStatus res = acdbGetAdsName64(name, id);

    ResultBuffer rb = new ResultBuffer();
    Autodesk.AutoCAD.Runtime.Interop.AttachUnmanagedObject(
        rb, acdbEntGet(name), true);
    ResultBufferEnumerator iter = rb.GetEnumerator();
    while (iter.MoveNext())
    {
        TypedValue typedValue = (TypedValue)iter.Current;
        if (typedValue.TypeCode == dxfcode)
        {
            result.Add(typedValue.Value);
        }
    }
    return result;
}

private System.Collections.Generic.List<TypedValue>
    acdbEntGetTypedVals(ObjectId id)
{
    System.Collections.Generic.List<TypedValue> result =
        new System.Collections.Generic.List<TypedValue>();
    long[] name = new long[] { 0, 0 };
    ErrorStatus res = acdbGetAdsName64(name, id);
    ResultBuffer rb = new ResultBuffer();
    Autodesk.AutoCAD.Runtime.Interop.AttachUnmanagedObject(
        rb, acdbEntGet(name), true);
    ResultBufferEnumerator iter = rb.GetEnumerator();
    while (iter.MoveNext())
    {
        result.Add((TypedValue)iter.Current);
    }
    return result;
}

 

Message 3 of 3

Thanks for the information. Will take advice on board re support etc

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report