明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 585|回复: 0

[【IFoxCAD】] 绘制方柱-JIG应用

  [复制链接]
发表于 2024-8-5 11:45:32 | 显示全部楼层 |阅读模式
本帖最后由 wang2006zhi 于 2024-8-6 13:07 编辑

/// <summary>
/// 绘制方柱
/// </summary>
[CommandMethod("W_HZFZ"
)]
public static void ColuDraw()
{
    if (!Env.Editor.GetPoint(out Point3d point1, "选择方柱的第一个角点"))
        return;
    var pt1 = point1.Ucs2Wcs();
  
    using var tr = new DBTrans();
    var layerId = InfoDicLayer[ETypeName.砼柱].MakeLayer();
    var txtTypeId = MakeEntity.MakeTxtStyle();
   
    var pline = new Polyline();
    pline.SetDatabaseDefaults();
    pline.AddVertexAt(0, pt1.Point2d(), 0, 0, 0);
    pline.AddVertexAt(1, pt1.Point2d(), 0, 0, 0);
    pline.AddVertexAt(2, pt1.Point2d(), 0, 0, 0);
    pline.AddVertexAt(3, pt1.Point2d(), 0, 0, 0);
    pline.Closed = true;
    pline.ConstantWidth = 5;
    pline.LayerId = layerId;
   
    var dbtextTempX = new DBText();
    dbtextTempX.SetDatabaseDefaults();
    dbtextTempX.Height = AppX.InfoSysValue.基本字高 * AppX.InfoSysValue.制图系数 * 0.5;
    dbtextTempX.WidthFactor = 0.6;
    dbtextTempX.TextStyleId = txtTypeId;
    dbtextTempX.LayerId = layerId;

    var pt2 = new Point2d();
   
    using var jig1 = new JigEx((mpw, _) =>
    {
        var vec = mpw - pt1;
        var vecXn = vec.Convert2d().GetNormal();
        var length = vec.Length.ToRound(InfoSysValue.方柱模数);
        pt2 = pt1.Point2d() + length * vecXn;
        pline.SetPointAt(1,pt2);
        
        dbtextTempX.TextString = length.ToString("F3");
        dbtextTempX.Position = pt1 + 0.5 * vec;
        dbtextTempX.Rotation = vecXn.Angle.AngleFormat();
    });
    jig1.DatabaseEntityDraw(wd =>
    {
        wd.Geometry.Draw(pline);
        wd.Geometry.Draw(dbtextTempX);
    });
    jig1.SetOptions(pt1,msg: "\n  选择方柱的第二个点");
    var ppr1 = Env.Editor.Drag(jig1);
    if (ppr1.Status != PromptStatus.OK)
        return;
   
    var dbtextTempY = new DBText();
    dbtextTempY.SetDatabaseDefaults();
    dbtextTempY.Height = AppX.InfoSysValue.基本字高 * AppX.InfoSysValue.制图系数 * 0.5;
    dbtextTempY.WidthFactor = 0.6;
    dbtextTempY.TextStyleId = txtTypeId;
    dbtextTempY.LayerId = layerId;
   
    using var jig2 = new JigEx((mpw, _) =>
    {
        var ptFoot = mpw.GetFootPoint(pt1,pt2.Point3d());
        var vec = mpw - ptFoot;
        var vecYn = vec.Convert2d().GetNormal();
        var length = vec.Length.ToRound(InfoSysValue.方柱模数);
        
        pline.SetPointAt(2, pt2 + length*vecYn);
        pline.SetPointAt(3, pt1.Point2d() + length*vecYn);
        
        dbtextTempY.TextString = length.ToString("F3");
        dbtextTempY.Position = pt1 + 0.5 * vec;
        dbtextTempY.Rotation = vecYn.Angle.AngleFormat();
    });
    jig2.DatabaseEntityDraw(wd =>
    {
        wd.Geometry.Draw(pline);
        wd.Geometry.Draw(dbtextTempY);
    });
    jig2.SetOptions(pt2.Point3d(), msg: "\n  选择方柱的第三个点");
    var ppr2 = Env.Editor.Drag(jig2);
    if (ppr2.Status != PromptStatus.OK)
        return;
    tr.CurrentSpace.AddEntity(pline);


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 03:47 , Processed in 0.172230 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表