2017-09-17 19 views
0

사각형에 대한 두 개의 매개 변수 (par_l 및 par_h)를 사용하여 동적 블록을 만들었습니다. 왜이 경우에는 아무 일도 일어나지 않을까요? 나는 par_l이 항목을 500으로 확장해야한다고 가정합니다. 기본적으로 나는 100과 100을가집니다. 블록이 프로그램에서 생성되었습니다. C#에서 코드 나는 그것을 조작 할C#에서 동적 블록 작업 (AutoCad 용)

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

      Transaction tr = db.TransactionManager.StartTransaction(); 

        BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite); 
        ed.WriteMessage(bt["prz_podl"]+""); 

        BlockTableRecord btr = tr.GetObject(bt["prz_podl"], OpenMode.ForWrite) as BlockTableRecord; 

        Point3d point = new Point3d(0, 0, 0); 
        BlockReference br = new BlockReference(point, btr.Id); 
        br.BlockTableRecord = btr.Id; 

        DynamicBlockReferencePropertyCollection properties = br.DynamicBlockReferencePropertyCollection; 
        for (int i = 0; i < properties.Count; i++) 
        { 
         DynamicBlockReferenceProperty property = properties[i]; 
         if (property.PropertyName == "par_l") 
         { 
          ed.WriteMessage(property.Value+""); 
          property.Value = 500.0; 
         } 
        } 
        tr.Commit(); 
     } 

답변

2

당신은 어떤 BlockTableRecord에 새로 생성 된 블록 참조를 추가하고 활성 트랜잭션에 추가해야합니다. 또한 거래를 처분해야합니다. 그것을 처분하면 그것으로 열거 나 추가 된 모든 물건을 담그는 일을 처리 할 것입니다.

[CommandMethod("TEST")] 
public void Test() 
{ 
    var doc = AcAp.DocumentManager.MdiActiveDocument; 
    var db = doc.Database; 
    var ed = doc.Editor; 

    using (var tr = db.TransactionManager.StartTransaction()) 
    { 
     var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); 
     // if the bloc table has the block definition 
     if (bt.Has("prz_podl")) 
     { 
      // create a new block reference 
      var br = new BlockReference(Point3d.Origin, bt["prz_podl"]); 

      // add the block reference to the curentSpace and the transaction 
      var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); 
      curSpace.AppendEntity(br); 
      tr.AddNewlyCreatedDBObject(br, true); 

      // set the dynamic property value 
      foreach (DynamicBlockReferenceProperty prop in br.DynamicBlockReferencePropertyCollection) 
      { 
       if (prop.PropertyName == "par_l") 
       { 
        prop.Value = 500.0; 
       } 
      } 
     } 
     // save changes 
     tr.Commit(); 
    } // <- end using: disposing the transaction and all objects opened with it (block table) or added to it (block reference) 
}