- UID
- 6847
- 积分
- 1065
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-6-23
- 最后登录
- 1970-1-1
|
发表于 2019-10-1 19:37:24
|
显示全部楼层
请教一下,我的写法怎么不能返回值给lisp,应该怎么写,谢谢,初学
- {
- // 7:47 PM 6/29/2007 - LE! -
- // from the MgdDbg SLN by Jim Awe AutoDesk
- const Double pi = Math.PI;
- public static Double dVal = 0.2;
- public static readonly Point3d kOrigin = new Point3d(0.0, 0.0, 0.0);
- public static readonly Vector3d kXAxis = new Vector3d(1.0, 0.0, 0.0);
- public static readonly Vector3d kYAxis = new Vector3d(0.0, 1.0, 0.0);
- public static readonly Vector3d kZAxis = new Vector3d(0.0, 0.0, 1.0);
- static Double delta(Double a1, Double a2)
- {
- Double ang;
- if (a1 > a2 + pi)
- ang = (a2 + pi + pi) - a1;
- else if (a2 > a1 + pi)
- ang = a2 - a1 - pi - pi;
- else
- ang = a2 - a1;
- return ang;
- }
- public static Database GetCurDwg()
- {
- Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
- return db;
- }
- // from the MgdDbg SLN by Jim Awe AutoDesk
- public static bool IsPaperSpace(Database db)
- {
- if (db.TileMode)
- return false;
- Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
- if (db.PaperSpaceVportId == ed.CurrentViewportObjectId)
- return true;
- return false;
- }
- // from the MgdDbg SLN by Jim Awe AutoDesk
- public static Matrix3d GetUcsMatrix(Database db)
- {
- Point3d origin;
- Vector3d xAxis, yAxis, zAxis;
- if (IsPaperSpace(db))
- {
- origin = db.Pucsorg;
- xAxis = db.Pucsxdir;
- yAxis = db.Pucsydir;
- }
- else
- {
- origin = db.Ucsorg;
- xAxis = db.Ucsxdir;
- yAxis = db.Ucsydir;
- }
- zAxis = xAxis.CrossProduct(yAxis);
- return Matrix3d.AlignCoordinateSystem(kOrigin, kXAxis, kYAxis, kZAxis, origin, xAxis, yAxis, zAxis);
- }
- // from the MgdDbg SLN by Jim Awe AutoDesk
- public static Point3d Ucs2Wcs(Point3d pt)
- {
- Matrix3d m = GetUcsMatrix(GetCurDwg());
- return pt.TransformBy(m);
- }
- // from the MgdDbg SLN by Jim Awe AutoDesk
- public static Point3d Wcs2Ucs(Point3d pt)
- {
- Matrix3d m = GetUcsMatrix(GetCurDwg());
- return pt.TransformBy(m.Inverse());
- }
- // by Luis Esquivel on June 29 2007
- // using the idea/algorithm by John F. Uhden,
- // one of the masters that use to frequent the customization ng of AutoDesk
- static ResultBuffer isPointInside(Point3d inPt, ObjectId objid)
- {
- Database db = HostApplicationServices.WorkingDatabase;
- Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- //ResultBuffer resultBuffer = new ResultBuffer(); //初始化返回值链表
- TypedValue[] tv = new TypedValue[1];
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- Polyline pPoly = (Polyline)tr.GetObject(objid, OpenMode.ForWrite, false);
- if (pPoly is Polyline)
- {
- if (!pPoly.Closed)
- {
- ed.WriteMessage("\n*** Curve is not closed. ");
- }
- Point3d P = new Point3d();
- P = Ucs2Wcs(inPt);
- Point3d ClosestPoint = pPoly.GetClosestPointTo(P, false); //true);
- if (P.IsEqualTo(ClosestPoint))
- {
- //ed.WriteMessage("\n*** Point is on curve. "); return;
- //resultBuffer.Add(new TypedValue((int)LispDataType.Text, "0"));
- tv[0] = new TypedValue((int)LispDataType.Int32, 0);
- }
- Double ClosestParam, EndParam;
- ClosestParam = pPoly.GetParameterAtPoint(ClosestPoint);
- ClosestPoint = Wcs2Ucs(ClosestPoint);
- EndParam = pPoly.EndParam;
- Double Param1 = 0.0, Param2 = dVal, Deflection = 0.0, a2;
- Point3d StartPT = pPoly.StartPoint;
- StartPT = Wcs2Ucs(StartPT);
- Double a1 = Math.Atan2(StartPT.Y - inPt.Y, StartPT.X - inPt.X);
- while (Param2 <= EndParam)
- {
- Param2 = Math.Min(Param2, EndParam);
- if (Param1 < ClosestParam && ClosestParam < Param2)
- {
- a2 = Math.Atan2(ClosestPoint.Y - inPt.Y, ClosestPoint.X - inPt.X);
- Deflection = Deflection + delta(a1, a2);
- a1 = a2;
- }
- bool test = true;
- while (test)
- {
- try
- {
- P = pPoly.GetPointAtParameter(Param2);
- Param2 = Param2 + dVal;
- }
- catch (System.Exception ex)
- {
- ed.WriteMessage("\nERROR = " + ex.Message);
- }
- finally
- {
- test = false;
- }
- }
- P = Wcs2Ucs(P);
- a2 = Math.Atan2(P.Y - inPt.Y, P.X - inPt.X);
- Deflection = Deflection + delta(a1, a2);
- a1 = a2;
- Param1 = Param2;
- Param2 = Param2 + dVal;
- }
- if (Math.Abs(Deflection) > 4)
- //ed.WriteMessage("\n*** Point is inside. ");
- //resultBuffer.Add(new TypedValue((int)LispDataType.Text, "-1"));
- tv[0] = new TypedValue((int)LispDataType.Int32, -1);
- else
- //ed.WriteMessage("\n*** Point is outside. ");
- //resultBuffer.Add(new TypedValue((int)LispDataType.Text, "1"));
- tv[0] = new TypedValue((int)LispDataType.Int32, 1);
- }
- tr.Commit();
-
- ResultBuffer resb = new ResultBuffer(tv);
- //ed.WriteMessage("\n*** Point is inside. ");
- return resb;
- }
- }
- [LispFunction("INSIDE")]
- public static void inside(ResultBuffer rb)
- {
- Database db = HostApplicationServices.WorkingDatabase;
- Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- TypedValue[] rbArr = rb.AsArray(); //Convoert to Array
- TypedValue entId = rbArr[0]; //取出第一个参数
- ObjectId objId = (ObjectId)entId.Value;
- TypedValue pt = rbArr[1]; //取出第二个参数
- Point3d pt1 = (Point3d)pt.Value;
- //PromptEntityResult res = ed.GetEntity("\nSelect polyline: ");
- ResultBuffer resultBuffer = new ResultBuffer(); //初始化返回值链表
- //if (res.Status != PromptStatus.OK) return;
- //PromptPointResult pt2Res = ed.GetPoint("\nPick internal point: ");
- //if (pt2Res.Status != PromptStatus.OK) return;
- //isPointInside(pt2Res.Value, res.ObjectId);
- isPointInside(pt1, objId);
- }
- }
|
|