0 Members and 1 Guest are viewing this topic.
Have a look at GetObjectSnapPoints() in the managed arx reference help, all drawn autocad entities have this property and using this api you have direct access to them.hth.
Sorry Jeff, I don't but James may have coded something up he can share.In the mean time I would suggest looking into the ARX ref.-> AcDb -> AcDbEntity-> getOsnapPoints() method which explains how and what the parameters are used for (the managed method simply wraps this so it should be very similar). While the managed help does list all/most methods available they have little help in the way of using them and I guess they expect you to be able to understand the C/C++ help already available.cheers.
Sorry Jeff, I don't but James may have coded something up he can share.cheers.
Matrix3d mat = new Matrix3d();mat = Matrix3d.Identity();ent.GetObjectSnapPoints(ObjectSnapModes.ModeMid, 0, pickPt, pickPt, mat, snapPts, geomIds);
ps:Welcome to theSwamp Jeff !Great to see another adventurer posting here.
(defun Initialize ()(setq NewLayer "ANNO-NOTE")(if (null (tblsearch "LAYER" NewLayer)) (command "._layer" "new" NewLayer "s" NewLayer "C" "2" NewLayer ""));End if(command "._layer" "s" "ANNO-NOTE" "")(command "COLOR" "BYLAYER") (setq OldSnapMode (getvar "OSMODE"))(SETVAR "OSMODE" 0) (setq DwgScale (/ 1.0 (getvar "CANNOSCALEVALUE"))) (setq Entity (nentsel))(setq EndPoint (osnap (cadr Entity) "End"))(setq MidPoint (osnap (cadr Entity) "mid")) (setq LineAngle (rtd (angle EndPoint MidPoint)));Adjust Angle for proper text orientation(if (and (> LineAngle 90.1) (< LineAngle 270.1) ) (setq LineAngle (- LineAngle 180)) );end if );END DEFUN (defun c:BMX (/ NewLayer OldSnapMode Entity EndPoint MidPoint LineAngle DwgScale TextPoint)(Initialize)(setq TextPoint (Polar MidPoint (dtr (+ LineAngle 90)) (* 0.03125 DwgScale)))(initdia)(command "._MText" TextPoint "J" "BC" "R" LineAngle "W" "0")(SETVAR "OSMODE" OldSnapMode));End defun(defun c:UBMX (/ NewLayer OldSnapMode Entity EndPoint MidPoint LineAngle DwgScale TextPoint)(Initialize)(setq TextPoint (Polar MidPoint (dtr (+ LineAngle 270)) (* 0.03125 DwgScale)))(initdia)(command "._MText" TextPoint "J" "TC" "R" LineAngle "W" "0")(SETVAR "OSMODE" OldSnapMode));End defun
[CommandMethod("BeaMtext")] public void AddBeamText() { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; Database db = HostApplicationServices.WorkingDatabase; Transaction tr = db.TransactionManager.StartTransaction(); PromptEntityResult selectionRes = ed.GetEntity("Select Entity "); if (selectionRes.Status == PromptStatus.OK) { try { ObjectId objId = selectionRes.ObjectId; Entity ent = (Entity)tr.GetObject(objId, OpenMode.ForRead); Point3d pickPt = selectionRes.PickedPoint; Matrix3d mat = new Matrix3d(); mat = Matrix3d.Identity; Point3dCollection snapPts = new Point3dCollection(); IntegerCollection geomIds = new IntegerCollection(); geomIds.Add(0); ent.GetObjectSnapPoints(ObjectSnapModes.ModeMid, 1, pickPt, pickPt, mat, snapPts, geomIds); ed.WriteMessage("\nYour selected point is:" + pickPt.ToString()); ent.Dispose(); } catch (Autodesk.AutoCAD.Runtime.Exception ex) { ed.WriteMessage(ex.Message); tr.Abort(); } }//end if }//end function
I finally stumbled on what I wanted all along, and it's a lot less complex than I thought.I believe the equivalent code for this lisp:(setq Entity (entsel))(setq MidPoint (osnap (cadr Entity) "mid"))is PromptEntityResult selectionRes = ed.GetEntity("Select Entity ");Point3d pickPt = selectionRes.PickedPoint;Point3d snapPt = ed.Snap("midpoint", pickPt);
static public void getosnap(string mode){ Database db = HostApplicationServices.WorkingDatabase; Document doc = acadApp.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; PromptEntityResult res = ed.GetEntity("\nSelect entity: "); if (res.Status != PromptStatus.OK) return; using (Transaction tr = db.TransactionManager.StartTransaction()) { Curve obj = tr.GetObject(res.ObjectId, OpenMode.ForRead, false) as Curve; if (obj is Curve) { Point3d pickPoint = res.PickedPoint; Point3d oPoint = obj.GetClosestPointTo(pickPoint, ed.GetCurrentView().ViewDirection, false); Point3d sp = obj.StartPoint; Point3d ep = obj.EndPoint; Point3d pt = new Point3d(); // point to return double dx = obj.GetDistAtPoint(oPoint); double param = obj.GetParameterAtPoint(oPoint); //where is that point selected? double sparam = obj.GetParameterAtPoint(sp); double eparam = obj.GetParameterAtPoint(ep); double xparam = param - sparam; double yparam = param - eparam; double ds = obj.GetDistanceAtParameter(Math.Abs(xparam)); double de = obj.GetDistanceAtParameter(Math.Abs(yparam)); switch (mode.ToUpper()) { case "MIDP": double totlen = obj.GetDistanceAtParameter(obj.EndParam); pt = obj.GetPointAtDist(totlen / 2.0); break; case "ENDP": if (ds > de) pt = ep; else pt = sp; break; } BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); DBPoint point = new DBPoint(pt); point.ColorIndex = 1; btr.AppendEntity(point); tr.AddNewlyCreatedDBObject(point, true); } tr.Commit(); }}[CommandMethod("GETOSNAP")]static public void testosnap(){ getosnap("MIDP"); // test getosnap("ENDP"); // test}
static public Point3d getosnap(Curve obj, string mode){return pt;}
Just be aware that is really risky code.All you are doing is mimicking what happens when the user clicks on that point, and has the MID osnap turned on.If entities overlap at that point, you may not get the midpoint of the previously-selected entity. You may get the midpoint of a different entity.
using System;using Autodesk.AutoCAD.ApplicationServices;using Autodesk.AutoCAD.DatabaseServices;using Autodesk.AutoCAD.EditorInput;using Autodesk.AutoCAD.Geometry;using Autodesk.AutoCAD.Runtime;using Autodesk.AECC.Interop.Land;using AutocadUtilities;using Civil3DUtilities;namespace SincpacC3D.RotateObjects{ public class RotationMatch { [CommandMethod("ROTATIONMATCH", CommandFlags.UsePickSet)] public void RotationMatchCommand() { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; C3DUtil c3dUtil = new C3DUtil(); Database db = Application.DocumentManager.MdiActiveDocument.Database; PromptSelectionOptions sPrmpt = new PromptSelectionOptions(); sPrmpt.MessageForAdding = "\nSelect objects to rotate: "; sPrmpt.MessageForRemoval = "\nSelect objects to remove: "; PromptSelectionResult ssResult; ssResult = ed.GetSelection(sPrmpt); if (ssResult.Status == PromptStatus.OK) { PromptEntityOptions entityOps = new PromptEntityOptions("\nSelect object to match: "); PromptEntityResult entityRes = ed.GetEntity(entityOps); if (entityRes.Status == PromptStatus.OK) { using (Transaction tr = db.TransactionManager.StartTransaction()) { ObjectId[] objIds = ssResult.Value.GetObjectIds(); Entity matchEntity = tr.GetObject(entityRes.ObjectId, OpenMode.ForRead, false) as Entity; double rot = 0; int errorCount = 0; Curve crv = matchEntity as Curve; if (crv != null) { Point3d pickPt = entityRes.PickedPoint; Point3d pointOnCurve = crv.GetClosestPointTo(pickPt, false); rot = CurveUtil.AzimuthAtParam(crv, crv.GetParameterAtPoint(pointOnCurve)); } else { try { rot = (double)matchEntity.GetType().GetProperty("Rotation").GetValue(matchEntity, null); } catch { AeccPoint p = matchEntity.AcadObject as AeccPoint; if (p != null) { rot = p.Rotation; } else { ed.WriteMessage("\nCould not get rotation for selected object..."); } } } foreach (ObjectId oId in objIds) { Entity ent = tr.GetObject(oId, OpenMode.ForWrite, false) as Entity; try { ent.GetType().GetProperty("Rotation").SetValue(ent, rot, null); } catch { Line line = ent as Line; if (line != null) { LineSegment2d calcLine = new LineSegment2d(line.StartPoint.Convert2d(CurveUtil.PlaneXY), line.EndPoint.Convert2d(CurveUtil.PlaneXY)); double dist = line.Length / 2; double dX = Math.Cos(rot) * dist; double dY = Math.Sin(rot) * dist; Point2d midpoint = calcLine.MidPoint; Point3d newStart = new Point3d(midpoint.X - dX, midpoint.Y - dY, line.StartPoint.Z); Point3d newEnd = new Point3d(midpoint.X + dX, midpoint.Y + dY, line.EndPoint.Z); line.StartPoint = newStart; line.EndPoint = newEnd; } else { AeccPoint p = ent.AcadObject as AeccPoint; if (p != null) p.Rotation = rot; else ++errorCount; } } } if (errorCount > 0) ed.WriteMessage("\nCould not rotate {0} object(s).", errorCount); tr.Commit(); } } } } }}