Author Topic: change jusifications of attribute in block  (Read 8902 times)

0 Members and 1 Guest are viewing this topic.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: change jusifications of attribute in block
« Reply #15 on: August 20, 2014, 07:41:05 AM »
In vanilla - maybe:
Code - Auto/Visual Lisp: [Select]
  1. ;;;Change ATTRIBute Justification To Top Center
  2. (defun c:att-tc (/ ss i en an ad)
  3.   (and (setq ss (ssget '((0 . "INSERT")(66 . 1))))
  4.        (setq i 0)
  5.        (while (setq en (ssname ss i))
  6.               (setq an (entnext en)
  7.                     ad (entget an))
  8.               (while (= "ATTRIB" (cdr (assoc 0 ad)))
  9.                      (setq ad (subst '(72 . 1) (assoc 72 ad) ad)
  10.                            ad (subst '(74 . 3) (assoc 74 ad) ad)
  11.                            ad (subst (cons 11 (cdr (assoc 10 ad))) (assoc 11 ad) ad))
  12.                      (entmod ad)
  13.                      (setq an (entnext an)
  14.                            ad (entget an)))
  15.               (entupd en)
  16.               (setq i (1+ i))))
  17.   (prin1))

-David
« Last Edit: August 22, 2014, 06:57:18 AM by David Bethel »
R12 Dos - A2K

kpblc

  • Bull Frog
  • Posts: 396
Re: change jusifications of attribute in block
« Reply #16 on: August 20, 2014, 09:23:59 AM »
If an attribute is multistring, it has no property TextAlignmentPoint (only InsertionPoint and AttachmentPoint properties).
Sorry for my English.

Coder

  • Swamp Rat
  • Posts: 827
Re: change jusifications of attribute in block
« Reply #17 on: August 20, 2014, 11:43:20 AM »
In vanilla - maybe:
Code: [Select]
;;;Change ATTRIBute Justification To Top Center
(defun c:att-tc (ss i en an ad)
  (and (setq ss (ssget '((0 . "INSERT")(66 . 1))))
       (setq i 0)
       (while (setq en (ssname ss i))
              (setq an (entnext en)
                    ad (entget an))
              (while (= "ATTRIB" (cdr (assoc 0 ad)))
                     (setq ad (subst '(72 . 1) (assoc 72 ad) ad)
                           ad (subst '(74 . 3) (assoc 74 ad) ad))
                     (entmod ad)
                     (setq an (entnext an)
                           ad (entget an)))
              (entupd en)
              (setq i (1+ i))))
  (prin1))

-David

I am sorry David , your codes did not work for me . and did not make any change to blocks  :embarrassed:
I added the back slash at the top of the routine .

Can you modify it again please ?

many thanks

Coder

  • Swamp Rat
  • Posts: 827
Re: change jusifications of attribute in block
« Reply #18 on: August 20, 2014, 11:49:31 AM »
If an attribute is multistring, it has no property TextAlignmentPoint (only InsertionPoint and AttachmentPoint properties).

Thank you for your reply  :-)

If I removed the function TextAlignmentPoint  , it change to left but the position of the attribute will be irregular  :-o

kpblc

  • Bull Frog
  • Posts: 396
Re: change jusifications of attribute in block
« Reply #19 on: August 20, 2014, 12:58:37 PM »
Try to use this:
Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun test1 (tag / _kpblc-conv-vla-to-list selset att_lst pt)
  3.  
  4.   (defun _kpblc-conv-vla-to-list (value / res)
  5.     (cond
  6.       ((listp value)
  7.        (mapcar (function _kpblc-conv-vla-to-list) value)
  8.        )
  9.       ((= (type value) 'variant)
  10.        (_kpblc-conv-vla-to-list (vlax-variant-value value))
  11.        )
  12.       ((= (type value) 'safearray)
  13.        (if (>= (vlax-safearray-get-u-bound value 1) 0)
  14.          (_kpblc-conv-vla-to-list (vlax-safearray->list value))
  15.          ) ;_ end of if
  16.        )
  17.       ((and (= (type value) 'vla-object)
  18.             (vlax-property-available-p value 'count)
  19.             ) ;_ end of and
  20.        (vlax-for sub value
  21.          (setq res (cons sub res))
  22.          ) ;_ end of vlax-for
  23.        )
  24.       (t value)
  25.       ) ;_ end of cond
  26.     ) ;_ end of defun
  27.  
  28.   (if (= (type (setq selset (vl-catch-all-apply
  29.                               (function
  30.                                 (lambda () (ssget '((0 . "INSERT") (66 . 1))))
  31.                                 ) ;_ end of function
  32.                               ) ;_ end of vl-catch-all-apply
  33.                      ) ;_ end of setq
  34.                ) ;_ end of type
  35.          'pickset
  36.          ) ;_ end of =
  37.     (progn
  38.       (foreach obj (mapcar (function vlax-ename->vla-object)
  39.                            ((lambda (/ tab item)
  40.                               (repeat (setq tab  nil
  41.                                             item (sslength selset)
  42.                                             ) ;_ end setq
  43.                                 (setq tab (cons (ssname selset (setq item (1- item))) tab))
  44.                                 ) ;_ end of repeat
  45.                               ) ;_ end of lambda
  46.                             )
  47.                            ) ;_ end of mapcar
  48.         (foreach att (vl-remove-if-not
  49.                        (function
  50.                          (lambda (x)
  51.                            (= (strcase (vla-get-textstring x)) (strcase tag))
  52.                            ) ;_ end of lambda
  53.                          ) ;_ end of function
  54.                        (apply (function append)
  55.                               (mapcar (function _kpblc-conv-vla-to-list)
  56.                                       (list
  57.                                         (vla-getattributes obj)
  58.                                         (vla-getconstantattributes obj)
  59.                                         ) ;_ end of list
  60.                                       ) ;_ end of mapcar
  61.                               ) ;_ end of apply
  62.                        ) ;_ end of vl-remove-if-not
  63.           (setq pt (vl-remove nil
  64.                               (mapcar
  65.                                 (function
  66.                                   (lambda (x)
  67.                                     (if (vlax-property-available-p att x)
  68.                                       (cons x (vlax-get-property att x))
  69.                                       ) ;_ end of if
  70.                                     ) ;_ end of lambda
  71.                                   ) ;_ end of function
  72.                                 '("insertionpoint" "textalignmentpoint")
  73.                                 ) ;_ end of mapcar
  74.                               ) ;_ end of vl-remove
  75.                 ) ;_ end of setq
  76.           (vla-put-alignment att acalignmenttopcenter)
  77.           (foreach item pt
  78.             (vlax-put-property att (car item) (cdr item))
  79.             ) ;_ end of foreach
  80.           ;; added only this string:
  81.           (vla-put-textalignmentpoint att (cdr (assoc "insertionpoint" pt)))
  82.           ) ;_ end of foreach
  83.         ) ;_ end of foreach
  84.       ) ;_ end of progn
  85.     ) ;_ end of if
  86.   ) ;_ end of defun
Sample of use:
Code - Auto/Visual Lisp: [Select]
  1. (test1 "1")
Sorry for my English.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: change jusifications of attribute in block
« Reply #20 on: August 20, 2014, 02:14:18 PM »

I am sorry David , your codes did not work for me . and did not make any change to blocks  :embarrassed:
I added the back slash at the top of the routine .

Can you modify it again please ?

many thanks

I fixed the local variables. Can you post an example of 1 of your blocks?  -David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12940
  • London, England
Re: change jusifications of attribute in block
« Reply #21 on: August 20, 2014, 02:25:31 PM »
I have error message after I modified your codes to make it left alignment  :embarrassed:

Quote
; error: Automation Error. Not applicable
Can you please help ?

Hint:

The InsertionPoint property controls the text position when the Alignment property is set to Left, the TextAlignmentPoint controls the text position for all other values of the Alignment property.

Coder

  • Swamp Rat
  • Posts: 827
Re: change jusifications of attribute in block
« Reply #22 on: August 21, 2014, 01:41:23 AM »
I fixed the local variables. Can you post an example of 1 of your blocks?  -David

You routine make changes to attribute string but it moves the attributes to '(0.0 0.0 0.0)  :-(

Thank you .

[/quote]
Try to use this:

Your codes make the attribute to top center and I am looking for left alignment .  :-(

Thank you .

I have error message after I modified your codes to make it left alignment  :embarrassed:

Quote
; error: Automation Error. Not applicable
Can you please help ?

Hint:

The InsertionPoint property controls the text position when the Alignment property is set to Left, the TextAlignmentPoint controls the text position for all other values of the Alignment property.
I got that lee , but I see the changes to left alignment does not affect the same thing as the attribute editor .

For example , if you change attribute from top center to left with the command eattedit , the attribute goes back to its original position and this is correct and perfect , but with
codes the attributes moves to left but its position keeps the attribute in its current position and this is my CONFUSION.  :-o

Thank you .


kpblc

  • Bull Frog
  • Posts: 396
Re: change jusifications of attribute in block
« Reply #23 on: August 21, 2014, 01:55:25 AM »
<...>
Your codes make the attribute to top center and I am looking for left alignment .  :-(<...>
Change acalignmenttopcenter to any value you like :)
Sorry for my English.

Coder

  • Swamp Rat
  • Posts: 827
Re: change jusifications of attribute in block
« Reply #24 on: August 21, 2014, 08:19:40 AM »
<...>
Your codes make the attribute to top center and I am looking for left alignment .  :-(<...>
Change acalignmenttopcenter to any value you like :)

I changed this from your routine and it give me error message .

Code: [Select]
          ) ;_ end of setq
          (vla-put-alignment att acalignmentleft) ;;; <<< to left alignment
          (foreach item pt (vlax-put-property att (car item) (cdr item))) ;_ end of foreach

; error: Automation Error. Not applicable

David Bethel

  • Swamp Rat
  • Posts: 656
Re: change jusifications of attribute in block
« Reply #25 on: August 21, 2014, 08:29:46 AM »
The problem is determining the existing justification values including dxf groups 10 & 11.  Do you want the attribute to retain its original location and only change the group 72 & 74 values? 

The initial default is group 10 baseline left and group 11 '(0 0 0)  flags 72 & 74 0

I changed the code so that it exchanges group 11 from group 10.  -David
R12 Dos - A2K

Coder

  • Swamp Rat
  • Posts: 827
Re: change jusifications of attribute in block
« Reply #26 on: August 21, 2014, 09:01:59 AM »
David , Did you try your codes by any chance ?

Your codes still do the same  :-( all attributes go to origin .

Thank you

David Bethel

  • Swamp Rat
  • Posts: 656
Re: change jusifications of attribute in block
« Reply #27 on: August 21, 2014, 09:58:46 AM »
David , Did you try your codes by any chance ?

Your codes still do the same  :-( all attributes go to origin .

It works on my test blocks.  That's why it is important to provide samples as there are lots and lots of scenarios that can lead to unintended errors   -David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12940
  • London, England
Re: change jusifications of attribute in block
« Reply #28 on: August 21, 2014, 10:31:44 AM »
David , Did you try your codes by any chance ?

Your codes still do the same  :-( all attributes go to origin .

It works on my test blocks.  That's why it is important to provide samples as there are lots and lots of scenarios that can lead to unintended errors   -David

David,

I believe this:
Code - Auto/Visual Lisp: [Select]
  1. (subst (assoc 10 ad) (assoc 11 ad) ad))

Needs to be:
Code - Auto/Visual Lisp: [Select]
  1. (subst (cons 11 (cdr (assoc 10 ad))) (assoc 11 ad) ad))

The existing code would move the attributes to the origin if the current attribute alignment is set to Left.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: change jusifications of attribute in block
« Reply #29 on: August 22, 2014, 06:59:47 AM »
Lee,

Yes, you are correct.  My bad for editing on the fly.  The end result could still be unintended if the OP wants the text to retain it's original position and only change the justifacation flags.   -Thanks!  -David
R12 Dos - A2K