乐筑天下

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

GripOverrule problem

[复制链接]

1

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2015-4-28 10:13:36 | 显示全部楼层 |阅读模式
Hi,
I have written own GripOverrule and GripData with custom grip points. Every thing is worikng in programic way. But I'm stuck with one thing. I have requirement to set stretch point by typing delta X and delta Y (as it is presented on attached picture). I have tried to use GetHotGripDimensionData in similar way as in jig but it doesn't work and after command autocad present critical error. Does anybody have idei how to achive desire functionality?
Thanks
回复

使用道具 举报

69

主题

875

帖子

15

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1146
发表于 2015-4-28 17:11:11 | 显示全部楼层
You will need to post some code so people can review it for errors and/or omissions .
回复

使用道具 举报

116

主题

996

帖子

9

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1466
发表于 2015-4-28 19:28:06 | 显示全部楼层

Do you mean Stretch point(ie rescale)  or Move point ? ... you may also need to clarify your intent.
回复

使用道具 举报

40

主题

132

帖子

107

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
227
发表于 2015-4-30 00:36:22 | 显示全部楼层
it's ok guys, i'll take the lead on this one
  1. #include
  2. AcadApplication.AcadPreferences.AcadPreferencesSelection;
  3. method properties loop array :: endl;
  4. system("pause");
回复

使用道具 举报

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2015-6-3 14:21:47 | 显示全部楼层
Well, I am not filo327, but I have the exact same question so I'll continue this discussion. Hopefully, since I'm giving some sample code, I will get a more direct response.   
This sample overrides the base Line Grips with a single grip on the line's endpoint. I need to be able to allow the user to enter the movement in the X and/or Y directions when DynamicInput is on. Similar to how this ADN c++ example does for a circle. I'm thinking it will need 2 dynamic dimensions (X & Y) that update as the grip is stretched but also allow the user to input a value for either one. Unfortunately, I'm drawing a blank on HOW to achieve this in c#. (Note - Code below started life as an example on the ADN blog, used as a guide by user CivilReminders for use in a commercial product, then stripped down to use for this inquiry.)
[ol]
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Runtime;

namespace Test_Commands.GripTest
{

    public class GripTest
    {

        private static bool ShouldBeOn = false;

        [CommandMethod("GripTestToggle")]
        public void griptestCommand()
        {
            if (ShouldBeOn)
            {
                ShouldBeOn = false;
                RemoveOverrule();
            }
            else
            {
                ShouldBeOn = true;
                AddOverrule();
            }
        }


        // Added for grips for line
        public static TestGripsOverrule mGripOverrule;

        public static void AddOverrule()
        {
            if (ShouldBeOn)
            {
                // Instantiate our global Overrule and set it to overrule lines with my data attached
                mGripOverrule = new TestGripsOverrule();
                Overrule.AddOverrule(RXObject.GetClass(typeof(Line)), mGripOverrule, false);
                //Turn overruling on
                Overrule.Overruling = true;   
            }
        }

        public static void RemoveOverrule()
        {
            if (!ShouldBeOn)
            {
                Overrule.RemoveOverrule(RXObject.GetClass(typeof(Line)), mGripOverrule);
                mGripOverrule = null;
            }
        }
    }

    //Grip overrule to add our custom grips to the profile view
    public class TestGripsOverrule : GripOverrule
    {
        public static short gripcolor { get; set; }

        //Our custom grip class
        //(Could have derived one class for each grip, but we'll use member data (Ordinal property) to distinguish grips instead)
        public class MyGrip : GripData
        {
            private int mGripNum;
            public int Ordinal
            {
                get { return mGripNum; }
                set { mGripNum = value; }
            }

            public override bool ViewportDraw(ViewportDraw worldDraw, ObjectId entityId, DrawType type, Point3d? imageGripPoint, int gripSizeInPixels)
            {
                Point2d unit = worldDraw.Viewport.GetNumPixelsInUnitSquare(GripPoint);
                var gripPolygonPts = new Point3dCollection();
                double lengthVal = 1.20 * gripSizeInPixels / unit.X;
                gripPolygonPts.Add(new Point3d(GripPoint.X, GripPoint.Y + lengthVal, 0));
                gripPolygonPts.Add(new Point3d(GripPoint.X + lengthVal, GripPoint.Y, 0));
                gripPolygonPts.Add(new Point3d(GripPoint.X, GripPoint.Y - lengthVal, 0));
                gripPolygonPts.Add(new Point3d(GripPoint.X - lengthVal, GripPoint.Y, 0));
               
                // Polygon properties
                worldDraw.SubEntityTraits.Color = gripcolor;
                worldDraw.SubEntityTraits.FillType = FillType.FillAlways;

                worldDraw.Geometry.Polygon(gripPolygonPts);
                return true;
            }

        }

        //Array to hold our grip
        public GripData[] mGripData = new GripData[1];

        public override void GetGripPoints(Autodesk.AutoCAD.DatabaseServices.Entity entity, Autodesk.AutoCAD.DatabaseServices.GripDataCollection grips, double curViewUnitSize, int gripSize, Autodesk.AutoCAD.Geometry.Vector3d curViewDir, Autodesk.AutoCAD.DatabaseServices.GetGripPointsFlags bitFlags)
        {
            //We assume entity is a profile view
            Line line = entity as Line;

            if (line == null)
                return;
            gripcolor = (short)Application.GetSystemVariable("GRIPHOT");

            // Set point at end of line
            MyGrip grip = new MyGrip();
            grip.Ordinal = 0;
            mGripData[0] = grip;

            
            UpdateGripLocations(line);

            //Add our grips to the list
            foreach (MyGrip g in mGripData)
            {
                grips.Add(g);
            }

            //Get the standard line grip points as well, but not wanted for this test
            //base.GetGripPoints(entity, grips, curViewUnitSize, gripSize, curViewDir, bitFlags);            
        }

        public override void MoveGripPointsAt(Autodesk.AutoCAD.DatabaseServices.Entity entity, GripDataCollection grips,
                                              Vector3d offset, MoveGripPointsFlags bitFlags)
        {
            //We only take  action when we get this call on a database resident entity
            //Dragging operation makes shallow clone of line, and setting clomeMeForDragging to false is generally a bad idea.
            //(If you do set clone me for dragging to false, then don't call base class overriden methods).
            try
            {
                if (entity.Id.IsValid)
                {
                    var line = entity as Line;

                    //Iterate through list of all grips being moved
                    foreach (GripData g in grips)
                    {
                        if (g is MyGrip)
                        {
                            MyGrip grip = g as MyGrip;
                            //Cast to our grip type
                            double newX = g.GripPoint.X + offset.X;
                            double newY = g.GripPoint.Y + offset.Y;

                            switch (grip.Ordinal)
                            {
                                case 0:
                                    line.EndPoint = new Point3d(newX, newY, line.EndPoint.Z);
                                    break;
                                default:
                                    break;
                            }

                            //Tell grip to move itself long the line
                            UpdateGripLocations(line);
                        }
                    }
                }
            }
            catch (System.Exception)
            {

            }
        }

        private void UpdateGripLocations(Line line)
        {
            Point3d pt = new Point3d(line.EndPoint.X, line.EndPoint.Y, 0);
            mGripData[0].GripPoint = pt;
        }

    }
}
[/ol]
回复

使用道具 举报

3

主题

28

帖子

1

银币

初来乍到

Rank: 1

铜币
40
发表于 2015-6-6 08:55:55 | 显示全部楼层

I would think that support for Dynamic Dimensions requires a Jig, because only there is a way designated to tell AutoCAD about them:
virtual DynamicDimensionDataCollection GetDynamicDimensionData(double dimScale)
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-2-5 00:32 , Processed in 0.233356 second(s), 64 queries .

© 2020-2025 乐筑天下

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