Jump to content

Dynamic Block and associated with it dimensions


Rojek

Recommended Posts

Hello

 

I've dug the internet for some information about this isue but i didn't find any reasonable solution. Please help

Here is the problem:

 

I have a dynamic block (Bore_Hole named, it's attached to post), it has few dynamic properties, including moving. The move properties should move relevant horizontal lines, vertical dimension should show distance from horizontal line to the top of block. Every thing works fine if I'll insert this block manualy, the problem arises when i'm changing dynamic properties programicly, lines are moved properly but the dimension stays as default.

 

That's my code:

 

using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
[assembly: CommandClass(typeof(InsertingBlock.MyCommands))]
namespace InsertingBlock
{
   public class MyCommands
   {
       [CommandMethod("iblock")]
       public void MyCommand() 
       {
           Document doc = Application.DocumentManager.MdiActiveDocument;
           Database db = doc.Database;
           Editor ed = doc.Editor;
           Transaction tr = db.TransactionManager.StartTransaction();
           string NazwaBloku = "Bore_Hole";
           using (tr)
           {
               
               BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
               BlockTableRecord btr = new BlockTableRecord();
               if (!bt.Has(NazwaBloku))
               {
                   ed.WriteMessage("\n Blok o nazwie Bore_HOle nie istnieje");
               }
               else
               {
                   bt.UpgradeOpen();
                   BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[blockTableRecord.ModelSpace], OpenMode.ForWrite);
                   ObjectId blockId = bt[NazwaBloku];
                   ed.WriteMessage("\nblockId" + blockId.ToString());
                  
                   Point3d pt = new Point3d(0, 0, 0);
                   BlockReference br = new BlockReference(pt, blockId);

                   ms.AppendEntity(br);

                   DynamicBlockReferencePropertyCollection pc = br.DynamicBlockReferencePropertyCollection;
                   foreach (DynamicBlockReferenceProperty prop in pc)
                   {
                       if (prop.PropertyName.ToUpper() == "VISIBILITY1")
                       {
                           ed.WriteMessage("\nIstnieje taka właściwość");
                           prop.Value = "2";
                       }
                       if (prop.PropertyName.ToUpper() == "D1")
                       {
                           double length = 2.5;
                           prop.Value = length;
                       }
                       
                       ed.WriteMessage("\nProperty:\"{0}\":{1}", prop.PropertyName, prop.UnitsType);
                       if (prop.Description != "")
                       {
                           ed.WriteMessage("\nDescription: {0}", prop.Description);
                       }
                       if (prop.ReadOnly)
                       {
                           ed.WriteMessage("read only");
                       }
                       bool first = true;
                       foreach (object value in prop.GetAllowedValues())
                       {
                           ed.WriteMessage(first ? "\n  Allowed values: [" : ", ");
                           ed.WriteMessage("\"{0}\"", value);
                           first = false;
                       }
                       if (!first) ed.WriteMessage("]");
                       ed.WriteMessage("\n  Current value: \"{0}\"\n", prop.Value);
                   }
                   tr.AddNewlyCreatedDBObject(br, true);
               }
               tr.Commit();
           }
       }  
   }
}

 

I'm using VS 2008 and autocad2010.

Bore_Hole block.dwg

Just after adding block.jpg

After clik on dynamic move - proper display.jpg

Edited by Rojek
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...