Własna biblioteka w C#.NET - problem z Point Manager


Recommended Posts

Posted

Witam,

Od jakiegoś czasu tworzę własną bibliotekę dll do ZwCada w C#. Potrzebuję mieć możliwość po najechaniu kursorem myszki na obiekt (linia, blok itp.) wyświetlenia, w okienku na palecie, informacji o obiekcie znajdującym się pod kursorem. Wiem, że jest coś takiego jak Point Manager, jednak to nie działa. Może coś robię źle, ponieważ bazuję na informacji jak go wykorzystać w AutoCad a nie ZwCad. Dotychczas nie miałem problemów z przenoszeniem kodu z AutoCad do ZwCad, wszystko zawsze działało. Oczywiście w Google szukałem, jednak nie mogę nic znaleźć.

 

Point Monitor dodaję w następujący sposób:

editor.PointMonitor += new PointMonitorEventHandler(pointMonitor);
private void pointMonitor(object sender, PointMonitorEventArgs e)
{
   // mój kod
}

Niestety nie ma żadnej reakcji.

 

Pracuję na:

Visual Studio Community 2013 Update 4

W projekcie ustawiony .NET Framework 4.5

ZwCad+ 2015

Posted

Witam

Nie korzystałem dotychczas z PointMonitor, więc trudno jest mi powiedzieć coś wiążącego w temacie. Ale chętnie skonsultuję to  bezpośrednio z programistami ZWSOFT.

Czy mógłby Pan podesłać jakąś większą próbkę kodu?

Pozdrawiam

Posted

Poniżej kod dla AAutoCad, na podstawie którego ja próbuję to samo zrobić w ZwCad.

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;

public class PointMonitorTooltips
{
  [CommandMethod("SM")]
  public static void StartMonitor()
  {
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
    ed.PointMonitor += new PointMonitorEventHandler(ed_PointMonitor);
  }

  [CommandMethod("XM")]
  public static void StopMonitor()
  {
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
    ed.TurnForcedPickOn();
    ed.PointMonitor -= new PointMonitorEventHandler(ed_PointMonitor);
  }

  static void ed_PointMonitor(object sender, PointMonitorEventArgs e)
  {
    Editor ed = (Editor)sender;
    Document doc = ed.Document;
    try
    {
      FullSubentityPath[] paths = e.Context.GetPickedEntities();
      // Go through the results of the selection
      // and detect the curves
      string curveInfo = "";
      Transaction tr = doc.TransactionManager.StartTransaction();
      using (tr)
      {
        // Open each object, one by one
        foreach (FullSubentityPath path in paths)
        {
          ObjectId[] ids = path.GetObjectIds();
          if (ids.Length > 0)
          {
            ObjectId id = ids[ids.GetUpperBound(0)];
            DBObject obj = tr.GetObject(id, OpenMode.ForRead);
            if (obj != null)
            {
              // If it's a curve, get its length
              Curve cv = obj as Curve;
              if (cv != null)
              {
                double length = cv.GetDistanceAtParameter(cv.EndParam) - cv.GetDistanceAtParameter(cv.StartParam);
                // Then add a message including the object
                // type and its length
                curveInfo += obj.GetType().Name + "'s length: " + string.Format("{0:F}", length) + "\n";
              }
            }
          }
        }
        // Cheaper than aborting

        tr.Commit();
      }
      // Add the tooltip of the lengths of the curves detected
      if (curveInfo != "")
        e.AppendToolTipText(curveInfo);
    }
    catch
    {
      // Not sure what we might get here, but not real action
      // needed (worth adding an Exception parameter and a
      // breakpoint, in case things need investigating).
    }
  }
}
Posted

Dzięki wielkie. 

A tak poza tematem. Mogę znaleźć gdzieś jakieś kursy, szkolenia lub materiały na temat programowania c# w ZwCad ? 

Posted

Nie dysponuję jakąś bazą wiedzy ani innymi zebranymi materiałami dotyczącymi programowania w C# dla ZWCADa. W większości przypadków jest to przez analogię do C# dla AutoCADa. Jeśli natomiast szuka Pan odpowiedzi na konkretne pytania zapraszam do kontaktu na tym forum lub mailowo pod adresem pomoc@dobrycad.pl .

Posted

Witam

Otrzymałem odpowiedź z ZWSOFT. Problem jest w samym ZWCADzie. Niestety nie jest to temat, jaki można łatwo rozwiązać jakimś prostym obejściem. Na chwilę obecną pozostaje poczekać aż ZWSOFT naprawi działanie PointMonitorEventHandler.

Pozdrawiam

Posted

Szkoda. Bardzo by mi pomogła taka funkcjonalność, ale jak się nie da, to trzeba coś innego wymyślić :) Dzięki wielkie za pomoc.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...