博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
生成三维模型
阅读量:5942 次
发布时间:2019-06-19

本文共 3622 字,大约阅读时间需要 12 分钟。

在autocad使用代码生成三维模型

[CommandMethod("cww")]

        public void CreateWedge()
        {
            // Get the current document and database, and start a transaction
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;
            Editor ed = acDoc.Editor;
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // 以只读方式打开块表记录   Open the Block table record for read
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                             OpenMode.ForRead) as BlockTable;

                // 以写方式打开模型空间块表记录   Open the Block table record Model space for write

                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                OpenMode.ForWrite) as BlockTableRecord;
                //插入点
                PromptPointOptions point = new PromptPointOptions("\n请选择插入点");
                PromptPointResult originPoint;
                originPoint = ed.GetPoint(point);
                Point3d origin = originPoint.Value;

                // Create a 3D solid wedge

                Solid3d acSol3D = new Solid3d();
                acSol3D.RecordHistory = true;
                //acSol3D.SetDatabaseDefaults();
                //acSol3D.CreateWedge(10, 15, 20);
                //acSol3D.CreateSphere(12.0);
                //acSol3D.CreateBox(100, 100, 100);
                acSol3D.CreateSphere(50);
                //acSol3D.CreateExtensionDictionary();
                // Position the center of the 3D solid at (5,5,0)
                acSol3D.TransformBy(Matrix3d.Displacement(origin -
                                                          Point3d.Origin));

                // 添加新对象到块表记录和事务中   Add the new object to the block table record and the transaction

                acBlkTblRec.AppendEntity(acSol3D);
                acTrans.AddNewlyCreatedDBObject(acSol3D, true);

                Solid3d acSol3D2 = new Solid3d();

                acSol3D2.RecordHistory = true;
                //acSol3D2.SetDatabaseDefaults();
                //acSol3D.CreateWedge(10, 15, 20);
                //acSol3D.CreateSphere(12.0);
                acSol3D2.CreateBox(500, 500, 100);
                // Position the center of the 3D solid at (5,5,0)
                acSol3D2.TransformBy(Matrix3d.Displacement(origin -
                                                          Point3d.Origin));

                // 添加新对象到块表记录和事务中   Add the new object to the block table record and the transaction

                acBlkTblRec.AppendEntity(acSol3D2);
                acTrans.AddNewlyCreatedDBObject(acSol3D2, true);

                Solid3d acSol3D3 = new Solid3d();

                acSol3D3.SetDatabaseDefaults();
                //acSol3D.CreateWedge(10, 15, 20);
                //acSol3D.CreateSphere(12.0);
                acSol3D3.CreateBox(500, 500, 100);
                // Position the center of the 3D solid at (5,5,0)
                acSol3D3.TransformBy(Matrix3d.Displacement(new Point3d(origin.X+500,origin.Y+500,origin.Z+500) -
                                                          Point3d.Origin));

                // 添加新对象到块表记录和事务中   Add the new object to the block table record and the transaction

                acBlkTblRec.AppendEntity(acSol3D3);
                acTrans.AddNewlyCreatedDBObject(acSol3D3, true);

                Solid3d acSol3D4 = new Solid3d();

                acSol3D4.SetDatabaseDefaults();
                //acSol3D.CreateWedge(10, 15, 20);
                //acSol3D.CreateSphere(12.0);
                acSol3D4.CreateBox(500, 500, 100);
                // Position the center of the 3D solid at (5,5,0)
                acSol3D4.TransformBy(Matrix3d.Displacement(new Point3d(origin.X + 500, origin.Y + 500, origin.Z + 100) -
                                                          Point3d.Origin));

                // 添加新对象到块表记录和事务中   Add the new object to the block table record and the transaction

                acBlkTblRec.AppendEntity(acSol3D4);
                acTrans.AddNewlyCreatedDBObject(acSol3D4, true);

                Solid3d acSol3D5 = new Solid3d();

                acSol3D5.SetDatabaseDefaults();
                //acSol3D.CreateWedge(10, 15, 20);
                //acSol3D.CreateSphere(12.0);
                acSol3D5.CreateBox(100, 500, 900);
                acSol3D5.Color = Autodesk.AutoCAD.Colors.Color.FromColor(System.Drawing.Color.DarkBlue);
                // Position the center of the 3D solid at (5,5,0)
                acSol3D5.TransformBy(Matrix3d.Displacement(new Point3d(origin.X + 300, origin.Y, origin.Z+400) -
                                                          Point3d.Origin));

                // 添加新对象到块表记录和事务中   Add the new object to the block table record and the transaction

                acBlkTblRec.AppendEntity(acSol3D5);
                acTrans.AddNewlyCreatedDBObject(acSol3D5, true);

                acTrans.Commit();

            }
        }

转载于:https://www.cnblogs.com/wangzuofei/archive/2012/12/19/2824980.html

你可能感兴趣的文章
OpenXml操作Word的一些操作总结.无word组件生成word.
查看>>
WPF模板
查看>>
java.lang.ClassCastException: sun.proxy.$Proxy11 cannot be cast to分析
查看>>
加载ConversationListActivity以及延迟的使用
查看>>
Extjs4.2 Grid搜索Ext.ux.grid.feature.Searching的使用
查看>>
GTK、KDE、Gnome、XWindows 图形界面
查看>>
hdu1231-最大连续子序列
查看>>
TMG阵列部署选择
查看>>
Repeater 控件 当数据源没有数据的时候显示 暂无数据 的两种方式
查看>>
大型网站的架构设计图分享-转
查看>>
Lambda应用设计模式
查看>>
const成员函数
查看>>
9.15游戏化体验的原则初探
查看>>
(function(){...}())与(function(){...})()
查看>>
css实现气泡框效果
查看>>
【原创】已知四个坐标点求其两条直线交点坐标
查看>>
request 路径随笔
查看>>
Adaptive Backgrounds – jQuery 自适应背景插件
查看>>
手把手教你 用 wpf 制作metro ProgressRing (Windows8 等待动画)
查看>>
编码原则:“防御式编程”再次让我快乐
查看>>