Attach Property Set in a Object

Attach Property Set in a Object

seabrahenrique
Advocate Advocate
507 Views
2 Replies
Message 1 of 3

Attach Property Set in a Object

seabrahenrique
Advocate
Advocate

Hello guys.

 

I'm trying to write a code to Civil 3D that can add a property set to DBObjects in my Document, and until now i have this:

 

    [CommandMethod("ADDPP")]
    public static void AddPropertySet()
    {

        Database acDBase = Application.DocumentManager.MdiActiveDocument.Database;

        using (var propDic = new DictionaryPropertySetDefinitions(acDBase))
        {
            using (Transaction trans = acDBase.TransactionManager.StartTransaction())
            {
                var propSetDef = new PropertySetDefinition();
                var PropDef = new PropertyDefinition();

                PropDef.Name = "name";
                PropDef.DefaultData = "value";

                propSetDef.Definitions.Add(PropDef);
                propDic.AddNewRecord("test", propSetDef);
                trans.AddNewlyCreatedDBObject(propSetDef, true);

                BlockTable bTb = trans.GetObject(acDBase.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord bTbR = trans.GetObject(bTb["a"], OpenMode.ForWrite) as BlockTableRecord;

                PropertyDataServices.AddPropertySet(bTbR, propSetDef.ObjectId);

                trans.Commit();
            }
        }
    }

 

The code add a PropertySetDefinition in my drawing an also add a Property inside that... But the problem is when i try to attach the PPset in my Object, here:

 

                BlockTable bTb = trans.GetObject(acDBase.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord bTbR = trans.GetObject(bTb["a"], OpenMode.ForWrite) as BlockTableRecord;

                PropertyDataServices.AddPropertySet(bTbR, propSetDef.ObjectId);

 

There is no compile error, but when i check my drawing and my named "a" block, i can't see the property set added here:

seabrahenrique_0-1667517929782.png

 

I don't know where i wrong... Is there something like a "synchronize" to the propertys appears in my block?

 

Thanks again 🙂

0 Likes
Accepted solutions (1)
508 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

I am sure you do know that BlockTableRecord is block definition and is not "visible". WHat you see in the MOdelSpace/Layout PaperSpace are BlockReferences. So, you need to attach PropertySet Data to BlockReferences.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 3

seabrahenrique
Advocate
Advocate

Pretty obvious... Thanks!

 

seabrahenrique_0-1667563753199.png

 

0 Likes