Author Topic: Why vla-put-coordinates ,to a Leader , rotates its arrowhead block  (Read 2541 times)

0 Members and 1 Guest are viewing this topic.

DEVITG

  • Bull Frog
  • Posts: 480
The task to do is to fix leader horizontal line to fit the text located on it . The text it ios not part of a mleader.
 
My question is ,
 
 
Why vla-put-coordinates ,to a Leader , rotates its arrowhead block


See dwg and lisp attached .
 
At the dwg it can see 2 pairs off leader entext , the upmost is fit by calcs at lisp , then I replace the leader coordinate list with its new end value , and vla-put-coordinates to the leader.
 
I can not wonder why the arrow head block is rotated . 
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

ymg

  • Guest
Re: Why vla-put-coordinates ,to a Leader , rotates its arrowhead block
« Reply #1 on: May 23, 2016, 08:39:13 AM »
Devitg,

I believe it has to do with roundoff error.

Take a look at dxfcode 210 212 and 213 before and after.

Quote
(entget (car (entsel)))
((-1 . <Entity name: 7ffff603bd0>) (0 . "LEADER") (330 . <Entity name: 7ffff603820>) (5 . "3D") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "1-DEUSTUA TEXTOS") (100 . "AcDbLeader") (3 . "1-DEU-DIM-50-PLANTA") (71 . 1) (72 . 0) (73 . 3) (74 . 1) (75 . 0) (40 . 0.0) (41 . 0.0) (76 . 3) (10 1846.4 860.455 0.0) (10 1846.2 860.804 -7.96236e-012) (10 1845.51 860.804 -3.49143e-011) (340 . <Entity name: 0>) (211 -1.0 -2.86427e-009 -3.94591e-011) (210 -3.94591e-011 -8.88199e-016 1.0) (212 0.0 0.0 0.0) (213 1.27255 3.64492e-009 5.02136e-011))
_$ (c:fttl)
_1_$
nil
_$ (entget (car (entsel)))
((-1 . <Entity name: 7ffff603bd0>) (0 . "LEADER") (330 . <Entity name: 7ffff603820>) (5 . "3D") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "1-DEUSTUA TEXTOS") (100 . "AcDbLeader") (3 . "1-DEU-DIM-50-PLANTA") (71 . 1) (72 . 0) (73 . 3) (74 . 1) (75 . 0) (40 . 0.0) (41 . 0.0) (76 . 3) (10 1846.4 860.455 1.61559e-027) (10 1846.2 860.804 -7.96236e-012) (10 1845.89 860.804 -2.01383e-011) (340 . <Entity name: 0>) (211 1.0 -2.86427e-009 3.94591e-011) (210 3.94591e-011 8.88184e-016 -1.0) (212 0.0 0.0 0.0) (213 -1.27255 3.64492e-009 -5.02136e-011))
_$

DEVITG

  • Bull Frog
  • Posts: 480
Re: Why vla-put-coordinates ,to a Leader , rotates its arrowhead block
« Reply #2 on: May 23, 2016, 10:17:24 AM »
Hi YMG, now I noticed the differences, I had check it , but I did it not . So Y have to check such  code before , and after the Vla-put-coordinates , and change if need .
Such codes 210 212 and 213 , seem to be block VECTORS .
I will change as suggested.
Thanks a lot.

Gabriel 
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Why vla-put-coordinates ,to a Leader , rotates its arrowhead block
« Reply #3 on: May 23, 2016, 02:12:44 PM »
This:
(210 3.94591e-011 8.88184e-016 -1.0)
is a strange extrusion for a 2D entity.

How did this come about? Are you using the _Mirror3D command?

DEVITG

  • Bull Frog
  • Posts: 480
Re: Why vla-put-coordinates ,to a Leader , rotates its arrowhead block
« Reply #4 on: May 23, 2016, 02:36:40 PM »
Hi Roy , I do not used mirror , only the 

Code: [Select]
(VLA-PUT-COORDINATES LEADER VAR)
Leader is the VL-object , Var is the point list as Variant .

That´s why I ask , WHY IT ROTATE THE ARROWHEADBLOCK??

I copy both at the same point and ENTGET for such codes , return



Quote
(211 1.0 -2.86427e-009 3.94591e-011)
(210 3.94591e-011 8.88184e-016 -1.0)
(212 0.0 0.0 0.0)
(213 -1.27255 3.64492e-009 -5.02136e-011)


(211 -1.0 -2.86427e-009 -3.94591e-011)
(210 -3.94591e-011 -8.88199e-016 1.0)
(212 0.0 0.0 0.0)
(213 1.27255 3.64492e-009 5.02136e-011)


 
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Why vla-put-coordinates ,to a Leader , rotates its arrowhead block
« Reply #5 on: May 23, 2016, 03:21:55 PM »
Quick test & get the same flipped results only after the leader is mirrored.
Code - Auto/Visual Lisp: [Select]
  1. ;; Flips arrow on mirrored leader
  2. (defun c:foo (/ o pts)
  3.   (if (setq o (car (entsel)))
  4.     (progn (vlax-get (vlax-ename->vla-object o) 'coordinates)
  5.            (setq pts (apply 'append (list (getpoint) (getpoint) (getpoint))))
  6.            (vlax-put (vlax-ename->vla-object o) 'coordinates pts)
  7.     )
  8.   )
  9. )
  10. ;; Retains arrow position
  11. (defun c:foo2 (/ e)
  12.   (if (setq e (car (entsel)))
  13.     (entmod (mapcar '(lambda (x)
  14.                        (if (= 10 (car x))
  15.                          (cons 10 (getpoint "\nPick a point: "))
  16.                          x
  17.                        )
  18.                      )
  19.                     (entget e)
  20.             )
  21.     )
  22.   )
  23. )
« Last Edit: May 23, 2016, 03:32:16 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

DEVITG

  • Bull Frog
  • Posts: 480
Re: Why vla-put-coordinates ,to a Leader , rotates its arrowhead block
« Reply #6 on: May 23, 2016, 03:52:22 PM »
I will try this way ,

Code: [Select]
(vlax-put (vlax-ename->vla-object o) 'coordinates pts)
as I have the PT list in XYZ value.
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

ymg

  • Guest
Re: Why vla-put-coordinates ,to a Leader , rotates its arrowhead block
« Reply #7 on: May 23, 2016, 03:54:09 PM »
Gabriel,

Look also at the assoc 10  of the entget.

Your z coordinates should be 0.0, but you are getting some
very small z coordinates sometimes on the plus side and sometime on the negative
side.

So I believe this is where the calculation of the extrusion vector gets thrown off.

Try also moving the leader  along the z axis.



ymg

ymg

  • Guest
Re: Why vla-put-coordinates ,to a Leader , rotates its arrowhead block
« Reply #8 on: May 23, 2016, 04:27:04 PM »
Gabriel,

I check by moving the z of the text and the leader , no luck, same result.

The 210 extrusion vector should be (0 0 1)

So maybe entmod it after completing your code.  I believe this property is read-only
on the object.

Did a test with entmod and it's working as it should!

Code: [Select]
(setq en  (SSNAME (SSGET "_cp" SS-BOX-11 '((0 . "LEADER"))) 0))
  (setq ent (entget en))
  (SETQ LEADER (VLAX-ENAME->VLA-OBJECT en)); maybe it need to check if it select more than 1
  (SETQ LEADER-XYZ-LIST (GROUP-BY-NUM (VAR->LST (VLA-GET-COORDINATES LEADER)) 3))
  (SETQ PT-A-REEMP-EN-LEADER (LAST LEADER-XYZ-LIST)) ; The last pt is the further most leader pt
  (SETQ PT-EN-LEADER (VLAX-CURVE-GETCLOSESTPOINTTO LEADER ABI-PT))
  (entmod (SUBST (cons 10 PT-EN-LEADER) (cons 10 PT-A-REEMP-EN-LEADER) ent))




ymg
« Last Edit: May 23, 2016, 05:06:47 PM by ymg »

DEVITG

  • Bull Frog
  • Posts: 480
Re: Why vla-put-coordinates ,to a Leader , rotates its arrowhead block
« Reply #9 on: May 23, 2016, 04:40:01 PM »
Ron Jop , it still rotate the arrow head block , and do not replicate the points positions. 

Please try at the attached DWG


I use the attached lisp , and it start my question.
« Last Edit: May 23, 2016, 04:48:27 PM by DEVITG »
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Why vla-put-coordinates ,to a Leader , rotates its arrowhead block
« Reply #10 on: May 23, 2016, 04:51:36 PM »
Give this a try:
Code - Auto/Visual Lisp: [Select]
  1. ;; Matches leader landing length to width of selected text object
  2. ;; Quickly written .. needs more error checking & assumes the leader only has 3 points
  3. (defun c:l2w (/ _textwidth e el i n ss tmp txt)
  4.   ;; 05.23.2016 RJP
  5.   (defun _textwidth (ename / pts)
  6.     (if   (setq pts (textbox (list (cons 1 (cdr (assoc 1 (entget ename))))
  7.              (cons 7 (cdr (assoc 7 (entget ename))))
  8.              (cons 40 (cdr (assoc 40 (entget ename))))
  9.              (cons 41 (cdr (assoc 41 (entget ename))))
  10.             )
  11.         )
  12.    )
  13.       (distance (car pts) (list (caadr pts) (cadar pts)))
  14.     )
  15.   )
  16.   (setq n 0)
  17.   (print "Pick text & leader: ")
  18.   (if
  19.     (and (setq ss (ssget '((0 . "Leader,Text"))))
  20.     (setq ss (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
  21.     (setq txt (car (vl-remove-if-not '(lambda (x) (= "TEXT" (cdr (assoc 0 (entget x))))) ss)))
  22.     (setq e (car (vl-remove-if-not '(lambda (x) (= "LEADER" (cdr (assoc 0 (entget x))))) ss)))
  23.     )
  24.      (if (= 3 (length (vl-remove-if-not '(lambda (x) (= 10 (car x))) (setq el (entget e)))))
  25.        (progn (entmod (mapcar '(lambda (x)
  26.              (if (and (= 10 (car x)) (setq n (1+ n)) (= 3 n))
  27.                (progn (setq tmp (nth (setq i (vl-position x el)) el))
  28.                  (cons   10
  29.                   (polar (cdr (nth (1- i) el))
  30.                          (angle (cdr (nth (1- i) el)) (cdr tmp))
  31.                          (_textwidth txt)
  32.                   )
  33.                  )
  34.                )
  35.                x
  36.              )
  37.                 )
  38.                el
  39.             )
  40.          )
  41.        )
  42.        (print "Leader needs to have only 3 points...")
  43.      )
  44.   )
  45.   (princ)
  46. )
On a side note .. have you ever thought of using MLEADERS?
« Last Edit: May 23, 2016, 04:59:11 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ymg

  • Guest
Re: Why vla-put-coordinates ,to a Leader , rotates its arrowhead block
« Reply #11 on: May 23, 2016, 05:18:02 PM »
Gabriel,

With entmod every thing seems to work with your last drawing.

Code: [Select]
(setq en  (SSNAME (SSGET "_cp" SS-BOX-11 '((0 . "LEADER"))) 0))
  (setq ent (entget en))
  (SETQ LEADER (VLAX-ENAME->VLA-OBJECT en)); maybe it need to check if it select more than 1
  (SETQ LEADER-XYZ-LIST (GROUP-BY-NUM (VAR->LST (VLA-GET-COORDINATES LEADER)) 3))
  (SETQ PT-A-REEMP-EN-LEADER (LAST LEADER-XYZ-LIST)) ; The last pt is the further most leader pt
  (SETQ PT-EN-LEADER (VLAX-CURVE-GETCLOSESTPOINTTO LEADER ABI-PT))
  (entmod (SUBST (cons 10 PT-EN-LEADER) (cons 10 PT-A-REEMP-EN-LEADER) ent))

I still believe it is roundoff error by the object method when it recalculates
the extrusion vector.

ymg

DEVITG

  • Bull Frog
  • Posts: 480
Re: Why vla-put-coordinates ,to a Leader , rotates its arrowhead block
« Reply #12 on: May 23, 2016, 07:19:17 PM »
Hi Ymg , Entmod , is the way . Thanks
Location @ Córdoba Argentina Using ACAD 2019  at Window 10