Как преобразовать LSP в objectarx C #, чтобы закрыть полилинии Autocad? - PullRequest
0 голосов
/ 14 февраля 2019

Мне нужно создать объектную функцию C #, которая будет проверять, подключена и открыта ли ломаная линия.Если так, то закройте их ломаной линией.Этот пример кода не может быть использован, потому что он не будет проверять, подключен ли он:

if (polyline.Closed == false)
{
    // Close polyline
    polyline.Closed = true;
}

Я узнал, как это сделать, но он есть в LISP.Кто-нибудь знает, как преобразовать это в C # objectarx .net?

;;  PLsCloseCorners.lsp [command name: PLsCL for PolyLines CLose]
;;  To Close all open lightweight Polylines, with the start/end
;;  vertex at the [apparent] intersection of the starting and
;;  ending segments, without coincident start/end vertices.
;;  If one "looks" closed (i.e. last vertex coincides with first one),
;;  but is not closed in Polyline terms, this will close it from
;;  the next-to-last vertex, not by adding a zero-length segment.
;;  [If beginning and/or ending Polyline segment is/are arcs, and
;;  start/end vertices are not coincident, will locate new corner
;;  as if endpoints of arc(s) are endpoints of line segment(s);
;;  if ending segment is an arc and start/end vertices are not
;;  coincident, will alter arc's path.]
;;  Kent Cooper, July 2009
;;
(defun C:PLsCL (/ plset pl plverts corner)
  (setq cmde (getvar 'cmdecho))
  (setvar 'cmdecho 0)
  (command "_.undo" "_begin")
  (setq plset (ssget "X" '((0 . "LWPOLYLINE"))))
    ; omit the "X" from the above line to let User select them
  (while (> (sslength plset) 0)
    (setq pl (ssname plset 0))
    (if (not (vlax-curve-isclosed pl))
      (progn
        (setq
          plverts (cdr (assoc 90 (entget pl))); number of vertices
          corner
            (inters 
              (vlax-curve-getStartPoint pl)
              (vlax-curve-getPointAtParam pl 1)
              (vlax-curve-getPointAtParam pl (1- plverts))
              (vlax-curve-getPointAtParam pl (- plverts 2))
              nil
            ); end inters & corner
        ); end setq
        (command
          "_.pedit"
          pl
          "_edit"
          "_move"
          corner
        ); end command
        (repeat (- plverts 2)
          (command "_next"); move to next-to-last vertex
        ); end repeat
        (command
          "_break"
          "_next"
          "_go"
          "_eXit"
          "_close"
          ""
        ); end command
      ); end progn
    ); end if
    (ssdel (ssname plset 0) plset)
  ); end while
  (command "_.undo" "_end")
  (setvar 'cmdecho cmde)
  (princ)
); end defun

Обновление # 1

Что я на самом деле пытаюсь сделать, это определить, должна ли быть закрыта ломаная линия.Изобразите полилинию в форме буквы C, а другую полилинию в виде буквы O. В этом случае я бы хотел закрыть одну в форме буквы O.

Пример:

public bool IsPolylineConnected(Polyline pline)
{

  // Convert the code from the LSP to C#
  // A polyline with the shape of the letter C would return false
  // A polyline with the shape of the letter O would return true

}

Ответы [ 2 ]

0 голосов
/ 18 февраля 2019

Можете ли вы предоставить тестовый чертеж?И, если вы действительно хотите использовать логику в lisp, вы всегда можете вызвать функцию LISP из .NET.

Например, у вас есть функция lisp

;(defun DoIt()

;Define the Lisp function as a command using c:
(defun c:DoIt()

    (setq    pntA (getpoint "\nPick A")
            pntB (getpoint pntA "\nPick B")
    )
    (grdraw pntA pntB 1 2)

)

C #:

[CommandMethod("DoIt", CommandFlags.Session)]
public void DoItMethod()
{
DocumentCollection acDocMgr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
Document acDoc = acDocMgr.Open(@"C:\SampleDrawings\Lights.dwg", false);
using (DocumentLock dl = acDoc.LockDocument())
{
Editor ed = acDoc.Editor;
using (ResultBuffer rb = new ResultBuffer())
{
rb.Add(new TypedValue((int)LispDataType.Text, "c:DoIt"));
ResultBuffer rbRes = Application.Invoke(rb);
if (rbRes != null)
{
TypedValue[] tvalues = rbRes.AsArray();
foreach (TypedValue tv in tvalues)
ed.WriteMessage("\n" + tv.ToString());
rbRes.Dispose();
}
else
ed.WriteMessage("\n Result buffer is null.");
}
}
}
0 голосов
/ 14 февраля 2019

Если вы приведете полилинию как объект кривой, вы можете проверить, совпадают ли начальная и конечная точки.

Приведение полилинии в виде кривой избавит вас от необходимости иметь дело с различными типами полилинии.

...