Snapping Issue

Hi All,

I created an AddIn in Microstation Select series 3.

My Add in allows user to pick two points on existing data and places a line between two points, which was implimented by using ipremitive events.

during the command while picking points i am not able to get snapping options even i selecting on button bar.

Please suggest me how can i do this.

Thanks in advance,

Kumar.

  • Hi Kumar,

    without knowing your code it's hard to say, but similar issue (primitive or locate command and snap) has been discussed several times in the programming community.

    At first you have to ensure AccuSnap is enabled for your command. From MicroStation VBA help: MicroStation does not enable AccuSnap unless the user has it enabled and the current command enables it. AccuSnap is automatically disabled every time a new command starts. For example, calling StartPrimitive or StartLocate, or starting a MicroStation primitive or locate command automatically resets MicroStation's command state thereby disabling the AccuSnap mode.

    It means if you did not enabled AccuSnap explicitely, it will be not active. Use CommandState.EnableAccuSnap method to allow AccuSnap.

    With regards,

      Jan

  • Hi Jan,

    Thanks for the reply.

    I enable accusnap every time started premitive.

    further i noticed that same tool it is working in some machines and not working in some machines.

    I am unable to identify what changes are there in other machines.

    Here is the code i have written.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    using BMW = Bentley.MicroStation.WinForms;
    using BMI = Bentley.MicroStation.InteropServices;
    using BCOM = Bentley.Interop.MicroStationDGN;
    
    namespace Point_Placing
    {
        class cls4PointCreation : BCOM.IPrimitiveCommandEvents
        {
            
            List<BCOM.Point3d> ptlist = new List<BCOM.Point3d>();
            BCOM.Application app = BMI.Utilities.ComApp;
            int tMaxid = 0;
            public void Cleanup()
            {
                
            }
            
            public void DataPoint(ref BCOM.Point3d Point, BCOM.View View)
            {
                app.CommandState.EnableAccuSnap();
                
                ptlist.Add(Point);
                
    
                if (ptlist.Count == 1)
                {
                    app.CadInputQueue.SendKeyin("snap perpendicular");
                    app.CommandState.StartDynamics();
                }
                
                if (ptlist.Count == 2)
                {
                    app.CadInputQueue.SendKeyin("snap nearest");
    
                    BCOM.LineElement ln = app.CreateLineElement2(null, ptlist[0], ptlist[1]);
                    GlobalFunctions_MS.LayerFunctions.CreateLay("AVI_Point1", app);
                    ln.Level = app.ActiveDesignFile.Levels["AVI_Point1"];
                    ln.Color = 2;
                    app.ActiveModelReference.AddElement(ln);
                    
                }
                if (ptlist.Count == 3)
                {
                    app.CadInputQueue.SendKeyin("snap perpendicular");
                }
    
                if (ptlist.Count == 4)
                {
    		
                    BCOM.LineElement ln = app.CreateLineElement2(null, ptlist[2], ptlist[3]);
                    GlobalFunctions_MS.LayerFunctions.CreateLay("AVI_Point2", app);
                    ln.Level = app.ActiveDesignFile.Levels["AVI_Point2"];
                    ln.Color = 3;
                    app.ActiveModelReference.AddElement(ln);
                    ptlist = new List<BCOM.Point3d>();
                }
            }
    
            
    
            public void Dynamics(ref BCOM.Point3d Point, BCOM.View View, BCOM.MsdDrawingMode DrawMode)
            {
                
                if (ptlist.Count == 1)
                {
                    app.CadInputQueue.SendKeyin("snap perpendicular");
                    app.ActiveSettings.Color = 2;
                    BCOM.LineElement ln = app.CreateLineElement2(null, ptlist[0], Point);
                    ln.Redraw(DrawMode);
                }
                else if (ptlist.Count == 3)
                {
                    app.CadInputQueue.SendKeyin("snap perpendicular");
                }
                else if (ptlist.Count == 2)
                {
                    app.CadInputQueue.SendKeyin("snap nearest");
                }
                else if(ptlist.Count == 3)
                {
                    app.ActiveSettings.Color = 3;
                    BCOM.LineElement ln = app.CreateLineElement2(null, ptlist[2], Point);
                    ln.Redraw(DrawMode);
                }
            }
    
            public void Keyin(string Keyin)
            {
                
            }
    
            public void Reset()
            {
                app.CommandState.StartDefaultCommand();
            }
    
            public void Start()
            {
                
            }
        }
    }
    

    Thanks,

    Kumar.

  • Hi Kumar,

    look at your code, I have a couple of comments. Not all relate to the discussed issue, only look weird for me.

    • For what purpose you use Bentley.MicroStation.InteropServices? These namespaces is used rarely in MicroStation addins and I guess never in Primitive Command Code.
    • Why you enable AccuSnap during evey DataPoint event? Usually AccuSnap is enabled / disable as a part of the command initialization in Start method. And when the snapping depends on an internal command state, it's called from inside some condition.
    • My personal feeling is that BCOM.Application app = BMI.Utilities.ComApp; is not correct. As far as I remember all Bentley examples use ComApp reference received at the time addin is instantiated and loaded, not later. I am not COM expert, but I can imagine the reference can change anytime and ComApp reference received from addin loader is the right reference specifically for the addin.
      I remember I tried to use direct ComApp reference long time ago in my application and it leads to crash or disfunction.
    • Also if (count) conditions, especially in DataPoint, look a bit dirty. You require to test all options despite of only one can be valid. In my opinion switch() leads to better code here.

    With regards,

      Jan