Hi all-
I am trying to find a way that I can select a segment of a leader and have it return that segment's angle. I have tried several approaches with very little success. Any help is greatly appreciated. Thanks in advance.
Manuel A. Ayala
|
|
|
Hi all-
I am trying to find a way that I can select a segment of a leader and have it return that segment's angle. I have tried several approaches with very little success. Any help is greatly appreciated. Thanks in advance.
Manuel A. Ayala
If I do something like this
(entget (car (entsel)))
then I can see the objects data values. From there look for "LEADER LINE" and group codes 10. this is the coordinates for the starting end points for the leader. If I use any two I can calculate the angle in between.
For reference I am attaching the data that was returned by the "entget" function.
Hope this helps
I'd advise getting something like (setq en (entsel)), the 2nd portion of this would be the cursor position of the selection. So then you check the leader's vectors, first get the leader's data: (setq ed (entget (car en))) from the 1st portion = ename.
Then extract the portion starting with the vectors: (setq vectors (member (assoc 10 ed) ed))
Now step through each, compare the distances from the selection point to perpendicular of each vector. The smallest distance shows which vector was picked.
Last edited by irneb; 2009-02-09 at 10:07 AM. Reason: Some typo's fixed
Try this:
Note that this will work with:Code:(defun LeaderAngleAtPoint( / ent obj pt param slope) (setq ent (entsel) obj (vlax-ename->vla-object (car ent)) pt (cadr ent) param (vlax-curve-getparamatpoint obj (trans (osnap pt "near")(car ent) 0)) slope(vlax-curve-getFirstDeriv obj param) ) (angle '(0 0 0) slope) )
Lines
Plines
Arcs
Circles
Splines and
Leaders
Mweaver
Thank you very much for the code. I will try it out.
Manuel
mweaver
Is it possible, using similar code, to find the angle of line or polyline within a block as well? Thanks again.
Manuel
With the help of some procedures found here(http://www.theswamp.org/index.php?topic=26591.0 Reply #14 has a link to a file: objmatrix v2.lsp) The following code will get the slope of a nested line:Doing the same with a pline is a bit tougher.Code:(defun GetAngleOfNestedLine( / ) (setq ent (nentsel) elist (entget (car ent)) p0 (transpt (cdr (assoc 10 elist)) (last ent) 2 1) p1 (transpt (cdr (assoc 11 elist)) (last ent) 2 1) ang (angle p0 p1) ) )
I had a brainstorm (and remembered a technique pioneered by Robert Grandmaison). Here is a rough routine that should work on all the objects mentioned in my earlier post, even if they're nested.
This is a proof of concept only, with very little testing. It needs to have error checking added as well as testing for and dealing with blocks set to not allow exploding (toggle that property, explode the block, and toggle the property back).Code:(defun c:test( / ent e ent2 p0 obj p1 param1 slope) (vl-load-com) (command "undo" "be") (setq ent (nentsel) ) (foreach e (last ent) (command "explode" e "") ) (setq ent2 (nentselp (cadr ent)) p0 (osnap (cadr ent2) "Near") obj (vlax-ename->vla-object (car ent2)) p1 (vlax-curve-getClosestPointTo obj p0) param1 (vlax-curve-getParamAtPoint obj p1) slope (vlax-curve-getfirstderiv obj param1) ) (command "undo" "back") (angle '(0 0 0) slope) )
Hopefully this will get you headed in the right direction.
Mike