乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 49|回复: 7

[编程交流] VB。net:创建圆

[复制链接]

35

主题

97

帖子

62

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
175
发表于 2022-7-6 12:16:47 | 显示全部楼层 |阅读模式
我需要在用户单击的地方创建一个圆,但我需要在用户单击之前,在鼠标指针周围出现一个圆。就像你使用CP命令一样,他可以在点击之前看到这个圆,所以他可以决定把它移动到哪里。
 
它必须是VB。net代码,因为它是更大程序的一部分。任何帮助都将不胜感激。
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 12:26:06 | 显示全部楼层
这个这种活动的净术语是“跳汰”。Kean Walmsley在这里有一些很好的例子。
 
http://through-the-interface.typepad.com/through_the_interface/jigs/
回复

使用道具 举报

35

主题

97

帖子

62

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
175
发表于 2022-7-6 12:39:31 | 显示全部楼层
Thanx SEANT,我认为这就是我需要的,但就我的经验水平而言,这似乎有点复杂。我也在做2d,所以我想我需要一个简化版本。等我有时间的时候再看一眼。
回复

使用道具 举报

15

主题

687

帖子

169

银币

中流砥柱

Rank: 25

铜币
582
发表于 2022-7-6 12:45:22 | 显示全部楼层
你好
 
这里有一个小样本供您执行任务。
它是C#,但可能将其转换为VB将是您理解它的一个好方法。
 
  1. using Autodesk.AutoCAD.ApplicationServices;
  2. using Autodesk.AutoCAD.DatabaseServices;
  3. using Autodesk.AutoCAD.EditorInput;
  4. using Autodesk.AutoCAD.Geometry;
  5. using Autodesk.AutoCAD.Runtime;
  6. namespace CircleJigSample
  7. {
  8.    public class CircleJigClass
  9.    {
  10.        class CircleJig : EntityJig
  11.        {
  12.            Circle m_circle;
  13.            double m_rad;
  14.            Point3d m_center;
  15.            public CircleJig(Circle myCircle)
  16.                : base(myCircle)
  17.            {
  18.                m_circle = myCircle;
  19.                m_rad = m_circle.Radius;
  20.                m_center = m_circle.Center;
  21.            }
  22.            protected override bool Update()
  23.            {
  24.                m_circle.Radius = m_rad;
  25.                return true;
  26.            }
  27.            protected override SamplerStatus Sampler(JigPrompts prompts)
  28.            {
  29.                JigPromptDistanceOptions jpdo = new JigPromptDistanceOptions("\nSpecify the radius: ");
  30.                jpdo.BasePoint = m_center;
  31.                jpdo.UseBasePoint = true;
  32.                jpdo.UserInputControls =
  33.                    UserInputControls.NoNegativeResponseAccepted |
  34.                    UserInputControls.NoZeroResponseAccepted;
  35.                PromptDoubleResult pdr = prompts.AcquireDistance(jpdo);
  36.                if (pdr.Status == PromptStatus.OK)
  37.                {
  38.                    if (pdr.Value == m_rad)
  39.                        return SamplerStatus.NoChange;
  40.                    else
  41.                    {
  42.                        m_rad = pdr.Value;
  43.                        return SamplerStatus.OK;
  44.                    }
  45.                }
  46.                return SamplerStatus.Cancel;
  47.            }
  48.        }
  49.        [CommandMethod("Test")]
  50.        public void Test()
  51.        {
  52.            Document doc = Application.DocumentManager.MdiActiveDocument;
  53.            Database db = doc.Database;
  54.            Editor ed = doc.Editor;
  55.            PromptPointResult ppr = ed.GetPoint("\nSpecify the center: ");
  56.            if (ppr.Status == PromptStatus.OK)
  57.            {
  58.                using (Transaction tr = db.TransactionManager.StartTransaction())
  59.                {
  60.                    Matrix3d ucs = ed.CurrentUserCoordinateSystem;
  61.                    Vector3d ucsNormal = new Vector3d(0.0, 0.0, 1.0).TransformBy(ucs);
  62.                    Point3d center = ppr.Value.TransformBy(ucs);
  63.                    Circle myCircle = new Circle(center, ucsNormal, 1.0);
  64.                    CircleJig jig = new CircleJig(myCircle);
  65.                    PromptResult res = ed.Drag(jig);
  66.                    if (res.Status == PromptStatus.OK)
  67.                    {
  68.                        BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
  69.                        btr.AppendEntity(myCircle);
  70.                        tr.AddNewlyCreatedDBObject(myCircle, true);
  71.                    }
  72.                    tr.Commit();
  73.                }
  74.            }
  75.        }
  76.    }
  77. }
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 12:53:46 | 显示全部楼层
以下是我对Jozi68最初请求的解释(尽管有C#)。
 
事实上,我不确定这个例程是否符合要求,但这个过程似乎很有趣,所以我选择了它。
 
 
编辑:
我包括了一个容差设置,以避免Gile在下面的帖子中提到的错误。
 
如果此代码示例用于小单位比例的图形,则可以将公差从当前的0.001等向量/等点修改为更合适的值。
 
一如既往,请谨慎使用测试代码。
 
  1. using System;
  2. using Autodesk.AutoCAD.ApplicationServices;
  3. using Autodesk.AutoCAD.DatabaseServices;
  4. using Autodesk.AutoCAD.EditorInput;
  5. using Autodesk.AutoCAD.Runtime;
  6. using Autodesk.AutoCAD.Geometry;
  7. [assembly: CommandClass(typeof(CircleJigSample.Commands))]
  8. namespace CircleJigSample
  9. {
  10.    public class Commands
  11.    {
  12.        [CommandMethod("Test2")]
  13.        public void Test()
  14.        {
  15.            Document doc = Application.DocumentManager.MdiActiveDocument;
  16.            Database db = doc.Database;
  17.            Editor ed = doc.Editor;
  18.            Tolerance Tol = new Tolerance(.001, .001);
  19.            Matrix3d ucs = ed.CurrentUserCoordinateSystem;
  20.            Vector3d ucsNormal = ucs.CoordinateSystem3d.Zaxis;
  21.            PromptPointOptions ppo = new PromptPointOptions("Select initial Point: ");
  22.            PromptPointResult ppr = ed.GetPoint(ppo);
  23.            CircleJig jig = new CircleJig(ppr.Value, ucsNormal, .01, Tol);
  24.            PromptResult res = ed.Drag(jig);
  25.            try
  26.            {
  27.                using (Transaction tr = db.TransactionManager.StartTransaction())
  28.                {
  29.                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
  30.                    if (res.Status == PromptStatus.OK)
  31.                    {
  32.                        Circle circ = jig.GetEntity() as Circle;
  33.                        if (circ.Radius <= Tol.EqualVector)
  34.                        {
  35.                            circ.Dispose();
  36.                            return;
  37.                        }
  38.                        circ.SetDatabaseDefaults();
  39.                        btr.AppendEntity(circ);
  40.                        tr.AddNewlyCreatedDBObject(circ, true);
  41.                        CircPlaceJig pjig = new CircPlaceJig(circ, circ.Center, ucs);
  42.                        res = ed.Drag(pjig);
  43.                        if (res.Status == PromptStatus.OK)
  44.                        {
  45.                            Circle newcirc = pjig.GetEntity() as Circle;
  46.                            newcirc.SetDatabaseDefaults();
  47.                            btr.AppendEntity(newcirc);
  48.                            tr.AddNewlyCreatedDBObject(newcirc, true);
  49.                        }
  50.                        circ.Erase();
  51.                    }
  52.                    tr.Commit();
  53.                }
  54.            }
  55.            catch
  56.            {
  57.                ed.WriteMessage("\nError processing circle!");
  58.            }
  59.        }
  60.        class CircleJig : EntityJig
  61.        {
  62.            double m_rad;
  63.            Point3d m_initial;
  64.            Point3d m_center;
  65.            Point3d m_temp;
  66.            Vector3d m_norm;
  67.            Tolerance m_tol;
  68.            public CircleJig(Point3d Initial, Vector3d ucsNormal, Double Rad, Tolerance Tol)
  69.                : base(new Circle(Initial, ucsNormal, Rad))
  70.            {
  71.                m_rad = Rad;
  72.                m_center = Initial;
  73.                m_initial = Initial;
  74.                m_temp = m_center;
  75.                m_norm = ucsNormal;
  76.                m_tol = Tol;
  77.            }
  78.            protected override bool Update()
  79.            {
  80.                ((Circle)base.Entity).Center = m_center;
  81.                ((Circle)base.Entity).Radius = m_rad;
  82.                return true;
  83.            }
  84.            protected override SamplerStatus Sampler(JigPrompts prompts)
  85.            {
  86.                JigPromptPointOptions jpdo = new JigPromptPointOptions("\nSpecify the radius: ");
  87.                jpdo.BasePoint = m_initial;
  88.                jpdo.UseBasePoint = true;
  89.                jpdo.UserInputControls =
  90.                    UserInputControls.NoNegativeResponseAccepted |
  91.                    UserInputControls.NoZeroResponseAccepted;
  92.                PromptPointResult pdr = prompts.AcquirePoint(jpdo);
  93.                if (pdr.Status == PromptStatus.OK)
  94.                {
  95.                    if (pdr.Value == m_temp)
  96.                        return SamplerStatus.NoChange;
  97.                    else
  98.                    {
  99.                        m_temp = pdr.Value;
  100.                        m_center = m_temp;
  101.                        m_rad = (m_initial.GetVectorTo(m_center)).Length;
  102.                        if (m_rad < m_tol.EqualVector) m_rad = m_tol.EqualVector;
  103.                        return SamplerStatus.OK;
  104.                    }
  105.                }
  106.                return SamplerStatus.Cancel;
  107.            }
  108.            public Entity GetEntity()
  109.            {
  110.                return Entity;
  111.            }
  112.        }
  113.        class CircPlaceJig : EntityJig
  114.        {
  115.            Point3d m_cenPt;
  116.            Point3d m_prev;
  117.            Matrix3d m_ucs;
  118.            public CircPlaceJig(Entity ent, Point3d cenPoint, Matrix3d ucs)
  119.                : base(ent.Clone() as Entity)
  120.            {
  121.                m_prev = cenPoint;
  122.                m_ucs = ucs;
  123.            }
  124.            protected override SamplerStatus Sampler(JigPrompts jp)
  125.            {
  126.                JigPromptPointOptions jppo = new JigPromptPointOptions("\nLocation of Circle: ");
  127.                PromptPointResult ppr = jp.AcquirePoint(jppo);
  128.                if (ppr.Status == PromptStatus.OK)
  129.                {
  130.                    if (m_prev == ppr.Value)
  131.                    {
  132.                        return SamplerStatus.NoChange;
  133.                    }
  134.                    else
  135.                    {
  136.                        m_cenPt = ppr.Value;
  137.                        return SamplerStatus.OK;
  138.                    }
  139.                }
  140.                return SamplerStatus.Cancel;
  141.            }
  142.            protected override bool Update()
  143.            {
  144.                Matrix3d trans = Matrix3d.Displacement(m_cenPt - m_prev);
  145.                Entity.TransformBy(trans);
  146.                m_prev = m_cenPt;
  147.                return true;
  148.            }
  149.            public Entity GetEntity()
  150.            {
  151.                return Entity;
  152.            }
  153.        }
  154.    }
  155. }
回复

使用道具 举报

15

主题

687

帖子

169

银币

中流砥柱

Rank: 25

铜币
582
发表于 2022-7-6 13:05:29 | 显示全部楼层
我对原始请求参数不是很确定。老实说,我很怀疑我的例程是否符合这些参数。尽管如此,这是一个有趣的想法。
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 13:16:07 | 显示全部楼层
嗨,肖特,
你的日常生活很有趣。我玩了一会儿。
我需要的是更简单的,我认为:半径是固定的,用户不改变它。所以我只需要固定的圆来用鼠标指针移动。最好是从起点到圆心的一条线。
我将尝试修改您发布的内容。
回复

使用道具 举报

35

主题

97

帖子

62

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
175
发表于 2022-7-6 13:20:45 | 显示全部楼层
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-5 06:22 , Processed in 0.412208 second(s), 68 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表