Create Associative Dimensions with .NET

Create Associative Dimensions with .NET

danielmollerX5W2N
Contributor Contributor
434 Views
5 Replies
Message 1 of 6

Create Associative Dimensions with .NET

danielmollerX5W2N
Contributor
Contributor

10 years have passed since the last question asked about this. 

Is there any news about it?
I can create dimensions via .NET, in short, like this

 

AlignedDimension dimension = new AlignedDimension();    
//set properties  ... 
//...
//... end set properties    
blockTableRecord.AppendEntity(dimension)   
transaction.AddNewlyCreatedDBObject(dimension, true)

 

How can I make this dimmension associative? Say associate it to the segment of a Polyline.   
Either via setting properties, creating association objects or just calling commands from the editor...

0 Likes
435 Views
5 Replies
Replies (5)
Message 2 of 6

daniel_cadext
Advisor
Advisor

You have to create a AcDbDimAssoc object. Here’s a sample in Python

def PyRxCmd_pydimassoc():
    try:
        pt1 = Ge.Point3d(0, 0, 0)
        pt2 = Ge.Point3d(15, 0, 0)
        pt3 = Ge.Point3d(5, 5, 0)

        db = Db.curDb()
        model = Db.BlockTableRecord(db.modelSpaceId(), Db.OpenMode.kForWrite)

        line = Db.Line(pt1, pt2)
        line.setDatabaseDefaults()
        lineid = model.appendAcDbEntity(line)
        line.close()

        dim = Db.AlignedDimension(pt1, pt2, pt3)
        dim.setDatabaseDefaults()
        dimId = model.appendAcDbEntity(dim)
        dim.close()

        ref1 = Db.OsnapPointRef(pt1)
        ref1.setOsnapType(Db.OsnapType.kOsnapStart)
        ref1.setIdPath(lineid, Db.SubentType.kEdgeSubentType, 0)

        ref2 = Db.OsnapPointRef(pt2)
        ref2.setOsnapType(Db.OsnapType.kOsnapEnd)
        ref2.setIdPath(lineid, Db.SubentType.kEdgeSubentType, 0)

        dimAssoc = Db.DimAssoc()
        dimAssoc.setDimObjId(dimId)
        dimAssoc.setPointRef(Db.DimAssocPointType.kXline1Point, ref1)
        dimAssoc.setPointRef(Db.DimAssocPointType.kXline2Point, ref2)
        dimAssoc.updateDimension()

        dimAssoc.post(dimId)
        # or
        # Db.Core.postDimAssoc(dimId,dimAssoc)

    except Exception as err:
        traceback.print_exception(err)


def PyRxCmd_pydimassocread():
    try:
        res = Ed.Editor.entSel("\nPick a dim", Db.Dimension.desc())
        if res[0] != Ed.PromptStatus.eOk:
            return

        # acdbGetDimAssocId
        assocId = Db.Core.getDimAssocId(res[1])
        dimAssoc = Db.DimAssoc(assocId)

        # added dimAssoc.osnapPointRef so we don't need to cast in Python
        ref1 = dimAssoc.osnapPointRef(Db.DimAssocPointType.kXline1Point)
        ref2 = dimAssoc.osnapPointRef(Db.DimAssocPointType.kXline2Point)

        print(ref1.point(), ref2.point())

    except Exception as err:
        traceback.print_exception(err)


def PyRxCmd_pyremdimassoc():
    try:
        res = Ed.Editor.entSel("\nPick a dim", Db.Dimension.desc())
        if res[0] != Ed.PromptStatus.eOk:
            return

        # acdbGetDimAssocId
        assocId = Db.Core.getDimAssocId(res[1])
        dimAssoc = Db.DimAssoc(assocId, Db.OpenMode.ForWrite)

        dimAssoc.removeAssociativity()

    except Exception as err:
        traceback.print_exception(err)
Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
Message 3 of 6

danielmollerX5W2N
Contributor
Contributor

This is not .NET, though. This class is not available. 

0 Likes
Message 4 of 6

daniel_cadext
Advisor
Advisor

Holycow! Very sorry about that, I just assumed AcDbDimAssoc was wrapped in .NET.

I see AssocDependency classes, not sure if that’s related

 

 

 

 

Python for AutoCAD, Python wrappers for ARX https://github.com/CEXT-Dan/PyRx
0 Likes
Message 5 of 6

khodulieucuong
Contributor
Contributor
var dim = tr.GetObject(id, OpenMode.ForWrite) as Dimension;
var dic = dim.ExtensionDictionary;
if (!dic.IsNull)
{
    var extDict = tr.GetObject(dim.ExtensionDictionary, OpenMode.ForWrite) as DBDictionary;                            
    var dimAssocId = extDict.GetAt("ACAD_DIMASSOC");
    if(extDict.Contains(dimAssocId))
    {
        extDict.Remove(dimAssocId); // remove association
    }  
}
Message 6 of 6

khodulieucuong
Contributor
Contributor

 AcadApp.SetSystemVariable("DIMASSOC", 1); // associate dimension

0 Likes