- 积分
- 123
- 明经币
- 个
- 注册时间
- 2017-1-12
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.Civil.ApplicationServices;
using Autodesk.Civil.DatabaseServices;
using Autodesk.Civil.DatabaseServices.Styles;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Windows;
using Autodesk.Civil;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Collections;
using System.Text.RegularExpressions;
using System.Security;
using System.Drawing.Printing;
using Autodesk.AutoCAD.PlottingServices;
using Autodesk.AutoCAD.Interop;
using System.Drawing.Drawing2D;
using Autodesk.AutoCAD.LayerManager;
using DotNetARX;
//需要添加对cad com组件引用
using Autodesk.AutoCAD.Interop.Common; //需要添加对cad com组件引用
using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using System.Management;
namespace ShenlongdhCadSystem
{
public class AutocadEntity
{
#region 创建道路3d模型
public static string EntityTinSurface()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityOptions opt = new PromptEntityOptions("\n选择一个曲面");
opt.SetRejectMessage("对象必须是一个曲面\n");
opt.AddAllowedClass(typeof(TinSurface), false);
TinSurface align = null;
using (Transaction trans = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
{
ObjectId alignID = ed.GetEntity(opt).ObjectId;
if (alignID.Database != null)
{
align = trans.GetObject(alignID, OpenMode.ForRead) as TinSurface;
alignID_1 = alignID;
}
}
return align.Name;
}
public static string EntityAlignment()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityOptions opt = new PromptEntityOptions("\n选择一个路线");
opt.SetRejectMessage("对象必须是一个路线\n");
opt.AddAllowedClass(typeof(Alignment), false);
Alignment align = null;
using (Transaction trans = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
{
ObjectId alignID = ed.GetEntity(opt).ObjectId;
if (alignID.Database != null)
{
align = trans.GetObject(alignID, OpenMode.ForRead) as Alignment;
}
}
return align.Name;
}
public static string EntityProfile()
{
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityOptions opt = new PromptEntityOptions("\n选择纵断面设计线");
opt.SetRejectMessage("对象必须是一个纵断面设计线\n");
opt.AddAllowedClass(typeof(Profile), false);
Profile align = null;
using (Transaction trans = Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
{
ObjectId alignID = ed.GetEntity(opt).ObjectId;
if (alignID.Database != null)
{
align = trans.GetObject(alignID, OpenMode.ForRead) as Profile;
}
}
return align.Name;
}
/// <summary>
/// 创建装配
/// </summary>
/// <param name="assemblyName">装配名称</param>
public static void RodCrossection(string assemblyName)
{
SelectTfbgParameter();
//在非模态下打开模型空间前要解锁
DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
// Point3d location = point3d();//
Database db = Application.DocumentManager.MdiActiveDocument.Database;
CivilDocument civilDoc = CivilApplication.ActiveDocument;
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
using (Transaction acTrans = acDoc.TransactionManager.StartTransaction())
{
//string atcFilePath = @"C:\Users\Administrator\AppData\Roaming\Autodesk\C3D 2014\chs\Support\ToolPalette\Palettes\Assemblies - Metric.atc";
String atcFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Autodesk\C3D 2014\chs\Support\ToolPalette\Palettes\Assemblies - Metric.atc";
string itemId = "D3216842-CBB4-4F66-AD83-7428F91746AF";
Point3d location = ed.GetPoint("选择导入装配位置\n").Value;
ObjectId assemblyId3 = civilDoc.AssemblyCollection.ImportAssembly(assemblyName, atcFilePath, itemId, location);
////////////////
Assembly assembly = acTrans.GetObject(assemblyId3, OpenMode.ForWrite) as Assembly;
foreach (var ss in civilDoc.SubassemblyCollection)
{
Subassembly subassembly = acTrans.GetObject(ss, OpenMode.ForWrite) as Subassembly;
if (subassembly.Name.Equals("LaneSuperelevationAOR - (Left)"))//左侧行车道
{
#region MyRegion
foreach (var psd in subassembly.ParamsDouble)
{
if (psd.DisplayName == "12409") //半幅路基宽度
psd.Value = Thenewfileoperations.Lujik / 2.0;
else
if (psd.DisplayName == "12481") //路拱坡度
psd.Value = Thenewfileoperations.Lujianhp;
}
#endregion
}
else
if (subassembly.Name.Equals("LaneSuperelevationAOR - (Right)"))//右侧行车道
{
#region MyRegion
foreach (var psd in subassembly.ParamsDouble)
{
if (psd.DisplayName == "12409") //半幅路基宽度
psd.Value = Thenewfileoperations.Lujik / 2.0;
else
if (psd.DisplayName == "12481") //路拱坡度
psd.Value = Thenewfileoperations.Lujianhp;
}
#endregion
}
else
if (subassembly.Name.Equals("BasicSideSlopeCutDitch - (Left)"))//左侧路基边坡
{
#region MyRegion
foreach (var psd in subassembly.ParamsDouble)
{
if (psd.DisplayName == "813") //挖方边坡坡度
{
if (Wfpd == 0)
psd.Value = 1;
else
psd.Value = 1.0 / Wfpd;
}
else
if (psd.DisplayName == "815") //填方边坡坡度
{
if (Tfzpd == 0)
psd.Value = 1 / 1.5;
else
psd.Value = 1 / Tfzpd;
}
else
if (psd.DisplayName == "817")//前坡度
psd.Value = 2;
else
if (psd.DisplayName == "823")//后坡度
psd.Value = 2;
else
if (psd.DisplayName == "858")//坡度限制3
psd.Value = 0.25;
else
if (psd.DisplayName == "821")//边沟底部宽度
{
if (Bgdk == 0)
psd.Value = 0.2;
else
psd.Value = Bgdk;
}
else
if (psd.DisplayName == "825")//前边沟深度
{
if (Bgsh == 0 && Bgpd == 0)
psd.Value = 0.2;//沟深度0.4
else
psd.Value = Bgsh * Bgpd;
}
else
if (psd.DisplayName == "819")//前边沟深度
{
if (Bgsh == 0 && Bgpd == 0)
psd.Value = 0.2;//沟深度0.4
else
psd.Value = Bgsh * Bgpd;
}
}
#endregion
}
else
if (subassembly.Name.Equals("BasicSideSlopeCutDitch - (Right)"))//右侧路基边坡
{
#region MyRegion
foreach (var psd in subassembly.ParamsDouble)
{
if (psd.DisplayName == "813") //挖方边坡坡度
{
if (Wfpd == 0)
psd.Value = 1;
else
psd.Value = 1.0 / Wfpd;
}
else
if (psd.DisplayName == "815") //填方边坡坡度
{
if (Tfypd == 0)
psd.Value = 1 / 1.5;
else
psd.Value = 1 / Tfypd;
}
else
if (psd.DisplayName == "817")//前坡度
psd.Value = 2;
else
if (psd.DisplayName == "823")//后坡度
psd.Value = 2;
else
if (psd.DisplayName == "858")//坡度限制3
psd.Value = 0.25;
else
if (psd.DisplayName == "821")//边沟底部宽度
{
if (Bgdk == 0)
psd.Value = 0.2;
else
psd.Value = Bgdk;
}
else
if (psd.DisplayName == "825")//前边沟深度
{
if (Bgsh == 0 && Bgpd == 0)
psd.Value = 0.2;//沟深度0.4
else
psd.Value = Bgsh * Bgpd;
}
else
if (psd.DisplayName == "819")//前边沟深度
{
if (Bgsh == 0 && Bgpd == 0)
psd.Value = 0.2;//沟深度0.4
else
psd.Value = Bgsh * Bgpd;
}
}
#endregion
}
}
acTrans.Commit();
}
docLock.Dispose();
}
static ObjectId alignID_1;
/// <summary>
/// 创建道路
/// </summary>
/// <param name="Rodname">道路名称</param>
/// <param name="assemblyName">装配名称</param>
public static void CmdCreateCorridor(string Rodname, string assemblyName)
{
//在非模态下打开模型空间前要解锁
DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Database db = Application.DocumentManager.MdiActiveDocument.Database;
CivilDocument civilDoc = CivilApplication.ActiveDocument;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
ObjectId styleId = TinSurface.Create(HostApplicationServices.WorkingDatabase, "surfaceName");
//创建一个新的道路模型ID
ObjectId newCorridorId = civilDoc.CorridorCollection.Add(Rodname);
Corridor corridor = trans.GetObject(newCorridorId, OpenMode.ForWrite) as Corridor;
//获取当前打开第一条路线ID
//ObjectId alignmentId = civilDoc.GetAlignmentIds()[0];
//Alignment alignment = trans.GetObject(alignmentId, OpenMode.ForRead) as Alignment;
///////////////
ObjectId alignmentId = new ObjectId();
Alignment alignment = null;
foreach (ObjectId surfaceId in civilDoc.GetAlignmentIds())
{
alignmentId = surfaceId;
alignment = trans.GetObject(surfaceId, OpenMode.ForRead) as Alignment;
if (alignment.Name == Rod3dmy.alignment)
break;
}
//获取道路纵断面ID
ObjectId profileId = alignment.GetProfileIds()[0];
foreach (ObjectId surfaceId in alignment.GetProfileIds())
{
profileId = surfaceId;
Autodesk.Civil.DatabaseServices.Entity entity = trans.GetObject(surfaceId, OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.Entity;
if (entity.Name == Rod3dmy.ZdmProfile)
break;
}
TinSurface surface = trans.GetObject(styleId, OpenMode.ForRead) as TinSurface;
// 创建基线
Baseline baseline = corridor.Baselines.Add("New Baseline", alignmentId, profileId);
//添加道路曲面
corridor.CorridorSurfaces.Add(Rod3dmy.TriangulateSurface);
//添加装配
baseline.BaselineRegions.Add("ccc", assemblyName);
foreach (ObjectId surfaceId in civilDoc.GetSurfaceIds())//删除非指定的曲面
{
Autodesk.Civil.DatabaseServices.Surface surf = trans.GetObject(surfaceId, OpenMode.ForRead) as Autodesk.Civil.DatabaseServices.Surface;
if (surf.Name != Rod3dmy.TriangulateSurface)
{
surf.UpgradeOpen();
surf.Erase();
}
}
SubassemblyTargetInfoCollection subtargetinfocoll = corridor.GetTargets();
for (int i = 0; i < subtargetinfocoll.Count; i++)
{
SubassemblyTargetInfo subassemblytargetinfo = subtargetinfocoll[i];
if (subassemblytargetinfo.TargetType == SubassemblyLogicalNameType.Surface)
{
//ObjectIdCollection ids = new ObjectIdCollection();
//ids.Add(alignID_1);
//subassemblytargetinfo.TargetIds = ids;
subassemblytargetinfo.TargetIds = civilDoc.GetSurfaceIds();
}
}
//更新目标信息
corridor.SetTargets(subtargetinfocoll);
corridor.Rebuild();
trans.Commit();
}
docLock.Dispose();
}
#endregion
}
}
|
评分
-
查看全部评分
|