C#该如何生成下图红色的圆底方顶样子的模型呢
我用BodyFromLoft函数生成的元素是下面样子的,不知道BodyFromLoft这个函数是否能实现我想要的效果。
我写了个函数简单演示了一下如何创建需要的基本体,您可以参考一下:
public static void CreateRectToCirc(double rectA, double rectB, double length, double circRadi) { double uorPerMe = Session.Instance.GetActiveDgnModel().GetModelInfo().UorPerMeter; DgnBoxDetail dgnBoxDeta = new DgnBoxDetail(new DPoint3d(circRadi * uorPerMe, 0, 0), new DPoint3d(-rectA/2*uorPerMe, -rectB / 2 * uorPerMe, length * uorPerMe), DVector3d.UnitX, DVector3d.UnitY, 0, 0, rectA * uorPerMe, rectB * uorPerMe, true); SolidPrimitive solidPri = SolidPrimitive.CreateDgnBox(dgnBoxDeta); Element eleSolid = DraftingElementSchema.ToElement(Session.Instance.GetActiveDgnModel(), solidPri, null); eleSolid.AddToModel(); dgnBoxDeta = new DgnBoxDetail(new DPoint3d(-circRadi * uorPerMe, 0, 0), new DPoint3d(-rectA / 2 * uorPerMe, -rectB / 2 * uorPerMe, length * uorPerMe), DVector3d.UnitX, DVector3d.UnitY, 0, 0, rectA * uorPerMe, rectB * uorPerMe, true); solidPri = SolidPrimitive.CreateDgnBox(dgnBoxDeta); eleSolid = DraftingElementSchema.ToElement(Session.Instance.GetActiveDgnModel(), solidPri, null); eleSolid.AddToModel(); dgnBoxDeta = new DgnBoxDetail(new DPoint3d(0, circRadi * uorPerMe,0), new DPoint3d(-rectA / 2 * uorPerMe, -rectB / 2 * uorPerMe, length * uorPerMe), DVector3d.UnitX, DVector3d.UnitY, 0, 0, rectA * uorPerMe, rectB * uorPerMe, true); solidPri = SolidPrimitive.CreateDgnBox(dgnBoxDeta); eleSolid = DraftingElementSchema.ToElement(Session.Instance.GetActiveDgnModel(), solidPri, null); eleSolid.AddToModel(); dgnBoxDeta = new DgnBoxDetail(new DPoint3d(0, -circRadi * uorPerMe, 0), new DPoint3d(-rectA / 2 * uorPerMe, -rectB / 2 * uorPerMe, length * uorPerMe), DVector3d.UnitX, DVector3d.UnitY, 0, 0, rectA * uorPerMe, rectB * uorPerMe, true); solidPri = SolidPrimitive.CreateDgnBox(dgnBoxDeta); eleSolid = DraftingElementSchema.ToElement(Session.Instance.GetActiveDgnModel(), solidPri, null); eleSolid.AddToModel(); DgnConeDetail dgnConeDeta = new DgnConeDetail(DPoint3d.Zero, new DPoint3d(-rectA / 2 * uorPerMe, -rectB / 2 * uorPerMe, length * uorPerMe), DVector3d.UnitX, DVector3d.UnitY, circRadi * uorPerMe, 0, true); solidPri = SolidPrimitive.CreateDgnCone(dgnConeDeta); eleSolid = DraftingElementSchema.ToElement(Session.Instance.GetActiveDgnModel(), solidPri, null); eleSolid.AddToModel(); dgnConeDeta = new DgnConeDetail(DPoint3d.Zero, new DPoint3d(rectA / 2 * uorPerMe, rectB / 2 * uorPerMe, length * uorPerMe), DVector3d.UnitX, DVector3d.UnitY, circRadi * uorPerMe, 0, true); solidPri = SolidPrimitive.CreateDgnCone(dgnConeDeta); eleSolid = DraftingElementSchema.ToElement(Session.Instance.GetActiveDgnModel(), solidPri, null); eleSolid.AddToModel(); dgnConeDeta = new DgnConeDetail(DPoint3d.Zero, new DPoint3d(-rectA / 2 * uorPerMe, rectB / 2 * uorPerMe, length * uorPerMe), DVector3d.UnitX, DVector3d.UnitY, circRadi * uorPerMe, 0, true); solidPri = SolidPrimitive.CreateDgnCone(dgnConeDeta); eleSolid = DraftingElementSchema.ToElement(Session.Instance.GetActiveDgnModel(), solidPri, null); eleSolid.AddToModel(); dgnConeDeta = new DgnConeDetail(DPoint3d.Zero, new DPoint3d(rectA / 2 * uorPerMe, -rectB / 2 * uorPerMe, length * uorPerMe), DVector3d.UnitX, DVector3d.UnitY, circRadi * uorPerMe, 0, true); solidPri = SolidPrimitive.CreateDgnCone(dgnConeDeta); eleSolid = DraftingElementSchema.ToElement(Session.Instance.GetActiveDgnModel(), solidPri, null); eleSolid.AddToModel(); }
Answer Verified By: Dongyu Zhao
5340.dgn
我用老师的代码生成了一个圆接方, 然后手动画了个包围着这个圆接方的立方体,依然不能剪切。
报错显示:“The Feature: "Difference #3" cannot be created with current settings and geometry.”。这是为什么呢
剪切干什么?画出来的基本体您做个union不就是您想要的目标模型了嘛
我的最终目标模型是褐色和灰色的那个元素,是通过立方体剪切一个方接圆得到的。
先将所有的基本体union成一个整体再去做剪切。
郭老师,反馈个问题,这段代码Union后,在形体内有可能会出现一个“空洞”。用外部的实体布尔减这个形体,就可能会出现一个“孤岛”。程序需要针对这个可能的情况提前做处理。
对,确实会出现,这种情况就得特殊处理了。