lubing 发表于 2010-7-22 14:29:00

[求助]新手求助一个有关块的问题?

我的CAD里有一个图块,请问我要如何跟据这个图块的名称来移动和旋转这个图块呢? 图块的坐标和旋转角度在软件里设定。有相关代码的朋友麻烦贴出来一下。谢谢了。类似我们更改下图中红色方框里的值一样。





lzh741206前辈的代码是可以实现旋转。但有个问题,就是这个块可不可以不用我手动选择。通过块名称来得到这个块




public static void test25()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
PromptEntityOptions opts = new PromptEntityOptions("\n请选择一个块:");
opts.SetRejectMessage("只能选择块参照");
opts.AddAllowedClass(typeof(BlockReference), false);
PromptEntityResult res = ed.GetEntity(opts);
if (res.Status != PromptStatus.OK)
return;
Database db = doc.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockReference bref = tr.GetObject(res.ObjectId, OpenMode.ForWrite) as BlockReference;
bref.Position += new Vector3d(10, 10, 0);
bref.Rotation += 60 * Math.PI / 180;
tr.Commit();
}
}

雪山飞狐_lzh 发表于 2010-7-22 15:57:00

是插入块命令Insert的效果?
最近的问题提的都让人伤脑筋,完全看不懂,汗

lubing 发表于 2010-7-22 16:19:00

不是,是图里面己经有一个块了。我想移动和旋转这个块,移动的坐标和放转的角度通过一个变量来指定。在C#里不知道要怎么实现,所以希望大家帮帮忙。

雪山飞狐_lzh 发表于 2010-7-22 16:41:00


如果只针对块
BlockReference.Position
BlockReference.Rotation

lubing 发表于 2010-7-22 20:13:00

对,我只是针对块。不知道哪位能给些代码?

雪山飞狐_lzh 发表于 2010-7-23 13:57:00

你是要新建还是把现有的图块旋转?

如果是现有的

      
      public static void test25()
      {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            PromptEntityOptions opts = new PromptEntityOptions("\n请选择一个块:");
            opts.SetRejectMessage("只能选择块参照");
            opts.AddAllowedClass(typeof(BlockReference), false);
            PromptEntityResult res = ed.GetEntity(opts);
            if (res.Status != PromptStatus.OK)
                return;
            Database db = doc.Database;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockReference bref = tr.GetObject(res.ObjectId, OpenMode.ForWrite) as BlockReference;
                bref.Position += new Vector3d(10, 10, 0);
                bref.Rotation += 60 * Math.PI / 180;
                tr.Commit();
            }
      }

雪山飞狐_lzh 发表于 2010-7-24 17:19:00

把你的要求说清楚
图块是图形里现有的吗?多个一起旋转?
还是新建一个块并旋转

lubing 发表于 2010-7-24 18:31:00

图块是图形里现有的。只有一个。上面给出的代码是可以用。但需要选择那个图块之后才能旋转。我的目地是不需要选择择它就可以旋转。

雪山飞狐_lzh 发表于 2010-7-24 22:28:00

建议你自己先试着写下,先看看kean专题的选择集部分,以及置顶帖手册的选择集部分
页: [1]
查看完整版本: [求助]新手求助一个有关块的问题?