zoukankan      html  css  js  c++  java
  • 生成三维模型

    在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();
                }
            }

  • 相关阅读:
    山东第一届省赛1001 Phone Number(字典树)
    HD2222 Keywords Search(AC自动机入门题)
    POJ 1947Rebuilding Roads(树形DP + 01背包)
    zoj 3946 Highway Project(最短路 + 优先队列)
    HDU5672String(尺标法)
    HDU5671Matrix(矩阵行列交换)
    HDU5670Machine(抽象进制)
    用户体验评价
    团队冲刺第二阶段-6
    第十四周学习进度
  • 原文地址:https://www.cnblogs.com/wangzuofei/p/2824980.html
Copyright © 2011-2022 走看看