如何编程控制动态块的参数、动作

见到论坛上有过不少动态块动作控制的问题。呵呵。其实使用objectarx.net是可以操作动态块参数、动作的。嘿嘿。
先看看我的效果图,两个简单例子:【1.开关的可见性参数;2.开关的跨度距离参数(对应有拉伸动作)】 

 怎么实现,很简单。
直接修改动态块的属性值即可。 


  [CommandMethod(
"SetDynamicValue")]
        
public void SetDynamicValue()
        
{
            Editor ed 
= AsApp.DocumentManager.MdiActiveDocument.Editor;
            
try
            
{
                ObjectId blrid 
= ObjectId.Null;
                PromptEntityOptions peo 
= new PromptEntityOptions("选择动态块");
                PromptEntityResult per 
= ed.GetEntity(peo);
                
if (per.Status == PromptStatus.OK)
                
{
                    blrid 
= per.ObjectId;
                }

                
else return;
                Database db 
= HostApplicationServices.WorkingDatabase;
                
using (Transaction tra = db.TransactionManager.StartTransaction())
                
{
                    Entity ent 
= (Entity)tra.GetObject(blrid, OpenMode.ForWrite);
                    
if (ent is BlockReference)
                    
{
                        BlockReference blr 
= ent as BlockReference;
                        
if (blr.IsDynamicBlock)
                        
{
                            
foreach (DynamicBlockReferenceProperty dbrp in blr.DynamicBlockReferencePropertyCollection)
                            
{
                                
if (dbrp.PropertyName == "可见性")
                                
{
                                    
if (dbrp.Value.ToString() == "断开")
                                        dbrp.Value 
= "闭合";
                                    
else
                                        dbrp.Value 
= "断开";
                                }

                                
if (dbrp.PropertyName == "距离")
                                
{
                                    dbrp.Value 
= Convert.ToDouble(dbrp.Value.ToString()) + 5;
                                }

                            }

                        }

                    }

                    tra.Commit();
                }

            }

            
catch (System.Exception exc)
            
{
                ed.WriteMessage(
"Error:" + exc.Message + exc.StackTrace);
            }

        }

 

 

 

posted on 2009-11-24 07:37  jdmei520  阅读(1851)  评论(2编辑  收藏  举报

导航