AutoCAD .Net 获取用户输入——GetString

GetString用于让用户输入字符串,示例用法如下:

Document doc = Application.DocumentManager.MdiActiveDocument;
PromptStringOptions options = new PromptStringOptions("\n请输入字符串: ");
options.AllowSpaces = true;
PromptResult result = doc.Editor.GetString(options);
switch (result.Status)
{
    case PromptStatus.OK:
        doc.Editor.WriteMessage("\n" + result.StringResult);
        break;

    case PromptStatus.Cancel:
        doc.Editor.WriteMessage("\n用户取消了输入");
        break;

    default:
        break;
}

AllowSpaces 指定可以输入空格,否则用户按空格键就相当于按下Enter键。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在CAD中绘制二维码,您可以使用以下步骤: 1. 在CAD中创建一个新的图层,用于绘制二维码。 2. 使用CAD .NET API中的Line对象绘制二维码的线条。 3. 通过调用Graphics.DrawLines方法将线条绘制到CAD中。 4. 通过二维码生成库将文本转换为二维码,然后将其分解为线条并将其绘制到CAD中。 以下是一个示例代码,用于在CAD中绘制二维码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.Runtime; using ZXing; using ZXing.Common; namespace CadQRCode { public class QRCode { [CommandMethod("DrawQRCode")] public void DrawQRCode() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; // Prompt the user to enter the text to encode PromptStringOptions pso = new PromptStringOptions("\nEnter the text to encode: "); PromptResult pr = doc.Editor.GetString(pso); if (pr.Status != PromptStatus.OK) { return; } // Generate the QR code from the entered text BarcodeWriter writer = new BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = new EncodingOptions { Height = 200, Width = 200, Margin = 0 } }; BitMatrix bitMatrix = writer.Encode(pr.StringResult); // Create a new layer for the QR code using (Transaction trans = db.TransactionManager.StartTransaction()) { LayerTable lt = (LayerTable)trans.GetObject(db.LayerTableId, OpenMode.ForRead); ObjectId layerId; if (!lt.Has("QRCode")) { LayerTableRecord ltr = new LayerTableRecord { Name = "QRCode", Color = Color.FromColorIndex(ColorMethod.ByAci, 1) }; layerId = lt.Add(ltr); trans.AddNewlyCreatedDBObject(ltr, true); } else { layerId = lt["QRCode"]; } // Create a new Polyline object to hold the lines of the QR code Polyline qrCode = new Polyline(); qrCode.Layer = layerId; // Loop through the rows and columns of the bit matrix to create the lines of the QR code for (int y = 0; y < bitMatrix.Height; y++) { for (int x = 0; x < bitMatrix.Width; x++) { if (bitMatrix[x, y]) { qrCode.AddVertexAt(qrCode.NumberOfVertices, new Point2d(x, y), 0, 0, 0); } } } // Add the polyline to the drawing BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); btr.AppendEntity(qrCode); trans.AddNewlyCreatedDBObject(qrCode, true); trans.Commit(); } } } } 此代码使用ZXing库生成二维码,并使用Polyline对象将其绘制到CAD中。请注意,此代码使用了一个名为“QRCode”的新图层来存储绘制的线条。如果您希望绘制到不同的图层,请更改代码中的图层名称。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值