• 生成三维模型


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

  • 相关阅读:
    云如何解决安全问题 狼人:
    存储安全 系统的最后一道防线 狼人:
    云安全仍是企业决策者最大担心 狼人:
    骇客宣称已入侵多家认证机构 波及微软、谷歌 狼人:
    盘点云计算服务中的隐患 狼人:
    云服务安全吗?美国政府用实际行动告诉你 狼人:
    微软高层称移动设备越多 对信息安全需更多考量 狼人:
    云计算需要让安全优先 狼人:
    金山网络两月被黑4次 入侵黑客留名挑衅 狼人:
    惠普推出全新企业级安全软件 狼人:
  • 原文地址:https://www.cnblogs.com/wangzuofei/p/2824980.html
Copyright © 2020-2023  润新知