马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
写了个 LispFunction ,很简单,
(linetoplane p1 p2 p3 p4 p5)
p1 p2 为线上两点, p3 p4 p5 为i构成平面的非共线三点
- // (C) Copyright 2014 by
- using System;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.EditorInput;
- using Exception = System.Exception;
- [assembly: CommandClass(typeof(AutoCAD_CSharp_plug_in34.MyCommands))]
- namespace AutoCAD_CSharp_plug_in34
- {
- public class MyCommands
- {
- [LispFunction("LineToPlane")]
- public object MyLispFunction(ResultBuffer args) // This method can have any name
- {
- TypedValue[] vars = args.AsArray();
- if (vars != null && vars.Length == 5
- && vars[0].TypeCode == (int)LispDataType.Point3d
- && vars[1].TypeCode == (int)LispDataType.Point3d
- && vars[2].TypeCode == (int)LispDataType.Point3d
- && vars[3].TypeCode == (int)LispDataType.Point3d
- && vars[4].TypeCode == (int)LispDataType.Point3d)
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Transaction tr = db.TransactionManager.StartTransaction();
- using (tr)
- {
- try
- {
- Point3d p1 = (Point3d)vars[0].Value;
- Point3d p2 = (Point3d)vars[1].Value;
- Point3d p3 = (Point3d)vars[2].Value;
- Point3d p4 = (Point3d)vars[3].Value;
- Point3d p5 = (Point3d)vars[4].Value;
- Line3d ln = new Line3d(p1, p2);
- Vector3d vv = p4 - p3;
- Vector3d vu = p5 - p3;
- Plane plan = new Plane(p3, vv.CrossProduct(vu));
- if (ln.IsParallelTo(plan))
- return null;
- else
- {
- Point3d[] pnt = ln.IntersectWith(plan);
- if (pnt != null)
- {
- return pnt[0];
- }
- else
- {
- return null;
- }
- }
- tr.Commit();
- }
- catch (Exception)
- {
- throw;
- }
-
- }
- }
- else
- {
- return null;
- }
- }
- }
- }
相同功能的 XdGe 函数实现如下
- (defun linetoPlane (p1 p2 p3 p4 p5 / line3d plane pnt)
- (and (setq line3d (xdge::constructor "kLine3d" p1 p2))
- (setq plane (xdge::constructor "kPlane" p3 p4 p5))
- (setq pnt (xdge::getpropertyvalue line3d "intersectWith" plane))
- (xdge::free)
- )
- pnt
- )
测试代码,修改下点样式,不然可能不容易发现
- (defun c:tt (/ p1 p2 p3 p4 p5 p)
- (if (and (setq p1 (getpoint "\n线上地一点: "))
- (setq p2 (getpoint p1 "\n线上第二点: "))
- (setq p3 (getpoint "\n平面上第一点: "))
- (setq p4 (getpoint p3 "\n平面上第二点: "))
- (setq p5 (getpoint p3 "\n平面上第三点: "))
- (setq p (linetoplane p1 p2 p3 p4 p5))
- )
- (entmake (list '(0 . "point") (cons 10 p)))
- )
- (princ)
- )
|