.NET

Reply
Contributor
insiaiftiqhar
Posts: 19
Registered: ‎06-21-2012
Message 1 of 3 (226 Views)
Accepted Solution

reading geomeric constraints

226 Views, 2 Replies
11-28-2012 01:55 PM

How do you read geometric constraints from the Assoc2dConstraintGroup in C# or VB?

Hi There,

 

Here is a c# sample that illustrates how to get started:

 

[CommandMethod("DumpConstraints")]
public void DumpConstraints()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
ObjectId networkId = AssocNetwork.GetInstanceFromObject(
db.CurrentSpaceId,
false,
true,
"ACAD_ASSOCNETWORK");
if (networkId == ObjectId.Null)
return;
using (Transaction Tx =
db.TransactionManager.StartTransaction())
{
using (AssocNetwork network =
Tx.GetObject(
networkId,
OpenMode.ForRead, false) as AssocNetwork)
{
foreach (ObjectId actionId in network.GetActions)
{
if (actionId == ObjectId.Null)
continue;
DBObject obj = Tx.GetObject(
actionId,
OpenMode.ForRead);
//ed.WriteMessage("\n - Action: " + obj.ToString().Remove(0, 34));
if (actionId.ObjectClass.IsDerivedFrom(
RXObject.GetClass(
typeof(Assoc2dConstraintGroup))))
{
Assoc2dConstraintGroup group = obj
as Assoc2dConstraintGroup;
foreach(GeometricalConstraint constraint
in group.Constraints)
{
//... do something ...
}
}
}
}
}
}

 

Regards,

Philippe.

ADN Support Specialist
philippe.leefsma
Posts: 662
Registered: ‎06-02-2009
Message 2 of 3 (191 Views)

Re: reading geomeric constraints

12-04-2012 01:10 AM in reply to: insiaiftiqhar

Hi There,

 

Here is a c# sample that illustrates how to get started:

 

[CommandMethod("DumpConstraints")]
public void DumpConstraints()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;

    ObjectId networkId = AssocNetwork.GetInstanceFromObject(
        db.CurrentSpaceId, 
        false, 
        true, 
        "ACAD_ASSOCNETWORK");

    if (networkId == ObjectId.Null)
        return;

    using (Transaction Tx = 
        db.TransactionManager.StartTransaction())
    {
        using (AssocNetwork network = 
            Tx.GetObject(
                networkId, 
                OpenMode.ForRead, false) as AssocNetwork)
        {
            foreach (ObjectId actionId in network.GetActions)
            {
                if (actionId == ObjectId.Null)
                    continue;

                DBObject obj = Tx.GetObject(
                    actionId, 
                    OpenMode.ForRead);

                //ed.WriteMessage("\n - Action: " + obj.ToString().Remove(0, 34));

                if (actionId.ObjectClass.IsDerivedFrom(
                    RXObject.GetClass(
                        typeof(Assoc2dConstraintGroup))))
                {
                    Assoc2dConstraintGroup group = obj 
                        as Assoc2dConstraintGroup;

                    foreach(GeometricalConstraint constraint 
                        in group.Constraints)
                    {
                        //... do something ...
                    }
                }
            }
        }
    }
}

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Contributor
insiaiftiqhar
Posts: 19
Registered: ‎06-21-2012
Message 3 of 3 (174 Views)

Re: reading geomeric constraints

12-04-2012 12:34 PM in reply to: philippe.leefsma

I can't thank you enough for helping me. I had given up and was working on an alternate/not so elegant solution. Thank you SO very much!

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.