C++ Programmer's Cookbook

{C++ 基础} {C++ 高级} {C#界面,C++核心算法} {设计模式} {C#基础}

Autodesk CAD实体集合另存为小工具

一,使用Autodesk CAD的二次开发技术ObjectARX(依赖与Autodesk CAD)。其中有c++和C#版,这里使用C#版。

二,生成的dll(C#)或arx(c++),必须被拷贝到ACAD的目录下,且在ACAD中使用命令netload或appload加载生成的dll或arx,加载后我们在ACAD中输入我们的命令即可。(下面小程序的命令是SaveDwg

三,小程序的功能是选取ACAD中打开的dwg图纸上的一些内容,然后保存为另一张dwg图纸。

四,c#的代码如下,比较简单,只考虑了简单的情况。

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Collections;

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;

namespace SaveDwg
{
    
public class Program
    
{   
 
        [CommandMethod(
"SaveDwg")]   
        
        
public void SaveDwg()
        
{
            
try
            
{

                Database db 
= HostApplicationServices.WorkingDatabase;

                SelectionSet selectionset;
                ArrayList setList 
= new ArrayList();

                Editor ed 
= Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
                ed.WriteMessage(
"welcome to use the tool, it can save as a dwg file for your selected entities.\n");
                PromptSelectionOptions selectionOptions 
= new PromptSelectionOptions();
                PromptSelectionResult selectionResult;
                selectionResult 
= ed.GetSelection(selectionOptions);
                
if (selectionResult.Status != PromptStatus.OK)
                
{
                    ed.WriteMessage(
"select error, please use command again.\n");
                    
return;
                }

                
else
                
{
                    selectionset 
= selectionResult.Value;
                    
foreach (ObjectId id in selectionset.GetObjectIds())
                    
{
                        DBObject ob 
= id.Open(OpenMode.ForRead);
                        Entity ent 
= ob as Entity;
                        
if (ent != null)
                        
{
                            Entity ent2 
= ent.Clone() as Entity;
                            setList.Add(ent2);
                            ed.WriteMessage(
"copying entity is successful.\n");
                        }
                        
                        ob.Close();
                    }

                }

                ed.WriteMessage(
"select and copy successfully.\n");

                Database Db 
= new Database(truefalse);
                HostApplicationServices.WorkingDatabase 
= Db;
                Autodesk.AutoCAD.DatabaseServices.TransactionManager manager 
= Db.TransactionManager;
                
using (Transaction transaction = manager.StartTransaction())
                
{
                    BlockTable table 
= (BlockTable)manager.GetObject(Db.BlockTableId, OpenMode.ForWrite);
                    BlockTableRecord record 
= (BlockTableRecord)manager.GetObject(Db.CurrentSpaceId, OpenMode.ForWrite);

                    
foreach (Object obj in setList)
                    
{
                        Entity ent 
= obj as Entity;
                        
if (ent != null)
                        
{
                            record.AppendEntity(ent);
                            
//manager.AddNewlyCreatedDBObject(ent,true);
                        }


                    }

                    record.Close();
                    table.Close();
                    transaction.Commit();
                }


                SaveFileDialog dialog 
= new SaveFileDialog();
                
string filePath;
                
if (DialogResult.OK == dialog.ShowDialog())
                
{
                    filePath 
= dialog.FileName;
                    Db.SaveAs(filePath, DwgVersion.Current);
                }

                
            }

            
catch(System.Exception e)
            
{
                MessageBox.Show(
"copy fail");
            }

        }

    }

}


五,记得要reference ObjectARX程序需要的dll哦,如下图:

六,想要脱离AutodeskCAD处理dwg图纸,需要使用ObjectDBX技术,最新版改名为realdwg技术。

posted on 2007-05-24 15:04 梦在天涯 阅读(2963) 评论(7)  编辑 收藏 引用 所属分类: ARX/DBX

评论

# re: Autodesk CAD实体集合另存为小工具 2007-05-24 15:08 梦在天涯

命令是:SaveDwg  回复  更多评论   

# re: Autodesk CAD实体集合另存为小工具 2007-05-25 15:24 ethan

持续关注你的文章   回复  更多评论   

# re: Autodesk CAD实体集合另存为小工具 2008-03-16 19:23

梦在天涯?你好,看了你的关于“Autodesk CAD实体集合另存为小工具”文章很兴趣,因为我做模具设计,经常需要将一个图中的单个图拷贝给别人线割,如果有了你的那个savedwg,工作为方便好多,但是我又不会C++,能否将编译后的arx文件发给我,另外,如果能给个视频教程,本人将更感激!谢谢了!我的邮箱是:guoling0412@163.com  回复  更多评论   

# re: Autodesk CAD实体集合另存为小工具 2012-01-06 12:45 RoseMorton25

A lot of specialists argue that <a href="http://goodfinance-blog.com/topics/personal-loans">personal loans</a> aid a lot of people to live their own way, just because they are able to feel free to buy needed stuff. Furthermore, a lot of banks offer commercial loan for different classes of people.   回复  更多评论   

# re: Autodesk CAD实体集合另存为小工具 2012-01-13 08:13 essay paper

You can ask if that is a fair to buy essay papers. I claim that's a natural stuff to use academic writing corporations to reach your goal.   回复  更多评论   

# re: Autodesk CAD实体集合另存为小工具 2012-01-13 08:15 Research paper references

Do you know people who can help with Research paper made easy accomplishing? I will surely pay cash for such a help.   回复  更多评论   

# re: Autodesk CAD实体集合另存为小工具 2013-07-31 09:21 visit this website

Want to buy CV? Have no idea where to buy resume paper? Select this site where you can find resume templates. Our certified resume writers will assure you that buying resume can bring job seekers career success!  回复  更多评论   

# re: Autodesk CAD实体集合另存为小工具 2013-07-31 09:52 Web page

Desire to learn about essay writing services? Seeking for trusty organization to get aid from? PremiumQualityEssays rewiew will give you a list of firms from which students may select the most qualified ones to order paper from.  回复  更多评论   


只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


公告

EMail:itech001#126.com

导航

统计

  • 随笔 - 461
  • 文章 - 4
  • 评论 - 746
  • 引用 - 0

常用链接

随笔分类

随笔档案

收藏夹

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

积分与排名

  • 积分 - 1747783
  • 排名 - 5

最新评论

阅读排行榜