Author Topic: fill scalebar tags  (Read 12519 times)

0 Members and 2 Guests are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: fill scalebar tags
« Reply #30 on: November 07, 2014, 10:22:53 PM »
You were closer on your previous attempt.  Don't change anything inside Lee's function.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: fill scalebar tags
« Reply #31 on: November 08, 2014, 12:14:29 AM »
Hi ronjonp i try to change it but i still have problem, can help me?

Code - Auto/Visual Lisp: [Select]
  1. ;;< .. >
  2.  

TRY A STRUCTURE LIKE THIS :
Code - Auto/Visual Lisp: [Select]
  1. (defun LM:vl-Setattributevalue ( blk tag VAL)
  2.  
  3.         ;; the original routine content ... do not edit
  4.  
  5.  
  6. )
  7.  
  8. (defun c:test ( / local_variables)
  9.  
  10.         ;; DO YOUR STUFF
  11.  
  12.   ;; Call the external routine
  13.  
  14.   (setq result (LM:vl-Setattributevalue  blkval tagval VALval) )
  15.  
  16.   ;; DO YOUR STUFF with result if needed.
  17. )
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

pedroantonio

  • Guest
Re: fill scalebar tags
« Reply #32 on: November 08, 2014, 03:35:45 AM »
Hi Kerry , I am confused. I am not good in lisp , i am trying to learn and i can not understand more things.

Quote
(defun LM:vl-Setattributevalue ( blk tag VAL)
 
     ;; the original routine content ... do not edit
 
 
)
 
(defun c:test ( / local_variables)
 
   ;; DO YOUR STUFF
 
  ;; Call the external routine
 
  (setq result (LM:vl-Setattributevalue  blkval tagval VALval) )
 
  ;; DO YOUR STUFF with result if needed.
)

How to do this , and a think tha here in my code is a lot of mistakes !!!

Code - Auto/Visual Lisp: [Select]
  1.   (defun lm:vl-setattributevalue b "d1" (strcat (rtos (/ 50 scl1) 2 2)))
  2.    ("d2" (strcat (rtos (/ 100 scl1) 2 2)))
  3.    ("d3" (strcat (rtos (/ 50 scl1) 2 2)))
  4.    ("d4" (strcat (rtos (* (/ 50 scl1) 2) 2 2)))
  5.    ("d5" (strcat (rtos (* (/ 50 scl1) 3) 2 2)))
  6.    ("d6" (strcat (rtos (/ 50 scl1) 2 2)))
  7.     ("scale" (strcat (scl1) 2 2)))
  8.  

Thanks

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: fill scalebar tags
« Reply #33 on: November 08, 2014, 04:01:41 AM »
You just don't want to read what people are saying, do you ??

DO NOT REDEFINE THE lm:vl-setattributevalue code.

use something like this in your routine

Code - Auto/Visual Lisp: [Select]
  1.     (progn (command "_layer" "_m" "scale" "_c" "7" "" "")
  2.            (setvar 'attreq 0)
  3.            (command "insert" "test" p scl scl "0")
  4.            (setq b (vlax-ename->vla-object (entlast)))
  5.  
  6.            ( lm:vl-setattributevalue b "d1" (strcat (rtos (/ 50 scl1) 2 2)))
  7.            ( lm:vl-setattributevalue b "d2" (strcat (rtos (/ 100 scl1) 2 2)))
  8.            ( lm:vl-setattributevalue b "d3" (strcat (rtos (/ 50 scl1) 2 2)))
  9.            ( lm:vl-setattributevalue b "d4" (strcat (rtos (* (/ 50 scl1) 2) 2 2)))
  10.            ( lm:vl-setattributevalue b "d5" (strcat (rtos (* (/ 50 scl1) 3) 2 2)))
  11.            ( lm:vl-setattributevalue b "d6" (strcat (rtos (/ 50 scl1) 2 2)))
  12.            ( lm:vl-setattributevalue b "scale" (strcat (scl1) 2 2))
  13.     )
  14.  
  15.  


I haven't tried to test your code because you didn't bother to supply the block for people to test with ... and I'm not inclined to make a block.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

pedroantonio

  • Guest
Re: fill scalebar tags
« Reply #34 on: November 08, 2014, 04:18:34 AM »
Here is the block i have already uploaded in previous post

pedroantonio

  • Guest
Re: fill scalebar tags
« Reply #35 on: November 08, 2014, 04:28:38 AM »
I try this but still not update the scalebar ....

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ b p scl d1 d2 d3 d4 d5 d6 d7 scale) ;scalebar
  2.   (if (and (setq scl (getint "\nEnter scale to use: "))
  3.            (setq p (getpoint "\n insert scale bar (scale bar):"))
  4.       )
  5.  (progn (command "_layer" "_m" "scale" "_c" "7" "" "")
  6.            (setvar 'attreq 0)
  7.            (command "insert" "test" p scl scl "0")
  8.            (setq b (vlax-ename->vla-object (entlast)))
  9.            ( lm:vl-setattributevalue b "d1" (strcat (rtos (/ 50 scl1) 2 2)))
  10.            ( lm:vl-setattributevalue b "d2" (strcat (rtos (/ 100 scl1) 2 2)))
  11.            ( lm:vl-setattributevalue b "d3" (strcat (rtos (/ 50 scl1) 2 2)))
  12.            ( lm:vl-setattributevalue b "d4" (strcat (rtos (* (/ 50 scl1) 2) 2 2)))
  13.            ( lm:vl-setattributevalue b "d5" (strcat (rtos (* (/ 50 scl1) 3) 2 2)))
  14.            ( lm:vl-setattributevalue b "d6" (strcat (rtos (/ 50 scl1) 2 2)))
  15.            ( lm:vl-setattributevalue b "d7" (strcat (rtos (/ 10 scl1) 2 2)))
  16.            ( lm:vl-setattributevalue b "scale" (strcat (scl1) 2 2))
  17.     )
  18.  
  19.           '(lambda (test)
  20.              (if (= d1 (strcase (vla-get-tagstring test)))
  21.                (progn (vla-put-textstring test (/ 50 scl1)) (/ 50 scl1))
  22.              )
  23.            )
  24.           (vlax-invoke b 'getattributes)
  25.         )
  26.       )
  27.       (setvar 'attreq 1)
  28.     )
  29.     (princ)
  30.  


Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: fill scalebar tags
« Reply #36 on: November 08, 2014, 05:58:17 AM »
Here is the block i have already uploaded in previous post

Ooops , sorry, I missed the first page of the thread ... my bad  :oops:

I'll have a look at it in the morning if no-one else has resolved the issue.

Regards,
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Ketxu

  • Newt
  • Posts: 109
Re: fill scalebar tags
« Reply #37 on: November 08, 2014, 06:03:20 AM »
Code - Auto/Visual Lisp: [Select]
  1. OOOPS ^^
  2. ;;PLEASE DO NOT CHANGE THIS FROM HERE <=============
  3.  
  4. ;; Set Attribute Value  -  Lee Mac
  5. ;; Sets the value of the first attribute with the given tag found within the block, if present.
  6. ;; blk - [vla] VLA Block Reference Object
  7. ;; tag - [str] Attribute TagString
  8. ;; val - [str] Attribute Value
  9. ;; Returns: [str] Attribute value if successful, else nil.
  10.  
  11. (defun LM:vl-setattributevalue ( blk tag val )
  12.     (setq tag (strcase tag))
  13.     (vl-some
  14.        '(lambda ( att )
  15.             (if (= tag (strcase (vla-get-tagstring att)))
  16.                 (progn (vla-put-textstring att val) val)
  17.             )
  18.         )
  19.         (vlax-invoke blk 'getattributes)
  20.     )
  21. )
  22.  
  23. ;;;;;; =========================================> TO HERE
  24.  
  25.  
  26.  
  27. (defun c:test (/ b p scl d1 d2 d3 d4 d5 d6 d7 scale) ;scalebar
  28.   (if (and (setq scl (getint "\nEnter scale to use: "))
  29.            (setq p (getpoint "\n insert scale bar (scale bar):"))
  30.       )
  31.  (progn (command "_layer" "_m" "scale" "_c" "7" "" "")
  32.            (setvar 'attreq 0)
  33.            (command "insert" "test" p scl scl "0")
  34.            (setq b (vlax-ename->vla-object (entlast)))
  35.                    ;Now just use lm:vl-setattributevalue funtion was defined before
  36.            ( lm:vl-setattributevalue b "D1" (strcat (rtos (/ 50 scl) 2 2)))                     ;Where scl1 ? You did not specify it. I changed to scl
  37.            ( lm:vl-setattributevalue b "D2" (strcat (rtos (/ 100 scl) 2 2)))
  38.            ( lm:vl-setattributevalue b "D3" (strcat (rtos (/ 50 scl) 2 2)))
  39.            ( lm:vl-setattributevalue b "D4" (strcat (rtos (* (/ 50 scl) 2) 2 2)))
  40.            ( lm:vl-setattributevalue b "D5" (strcat (rtos (* (/ 50 scl) 3) 2 2)))
  41.            ( lm:vl-setattributevalue b "D6" (strcat (rtos (/ 50 scl) 2 2)))
  42.            ( lm:vl-setattributevalue b "D7" (strcat (rtos (/ 10 scl) 2 2)))
  43.            ( lm:vl-setattributevalue b "SCALE" (strcat (rtos scl 2 2)))
  44.     )
  45. )
  46.  (princ)
  47.  )

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: fill scalebar tags
« Reply #38 on: November 08, 2014, 06:58:05 AM »

This works for me:

Code - Auto/Visual Lisp: [Select]
  1.  
  2.  
  3. (defun c:test (/ b bname p scale)            ;scalebar
  4.   (if (and (setq scale (getint "\nEnter scale to use: "))
  5.            (setq p (getpoint "\nSelect insert point for scale bar:"))
  6.            (setq bname (findfile "test.dwg"))
  7.       )
  8.     (progn (command "_layer" "_m" "scale" "_c" "7" "" "")
  9.            (setvar 'attreq 0)
  10.            (command "insert" bname p scale scale "0")
  11.            (setq b (vlax-ename->vla-object (entlast)))
  12.            (lm:vl-setattributevalue b "D1" (strcat (rtos (/ 50 scale) 2 2)))
  13.            (lm:vl-setattributevalue b "D2" (strcat (rtos (/ 100 scale) 2 2)))
  14.            (lm:vl-setattributevalue b "D3" (strcat (rtos (/ 50 scale) 2 2)))
  15.            (lm:vl-setattributevalue b "D4" (strcat (rtos (* (/ 50 scale) 2) 2 2)))
  16.            (lm:vl-setattributevalue b "D5" (strcat (rtos (* (/ 50 scale) 3) 2 2)))
  17.            (lm:vl-setattributevalue b "D6" (strcat (rtos (/ 50 scale) 2 2)))
  18.            (lm:vl-setattributevalue b "D7" (strcat (rtos (/ 10 scale) 2 2)))
  19.            (lm:vl-setattributevalue b "SCALE" (strcat (rtos scale 2 2)))
  20.            (setvar 'attreq 1)
  21.     )
  22.   )
  23. )
  24.  
  25.  
  26.  

Your Math could do with some modifications though :)

Please compare my code thoroughly with yours.
Personally I use a routine that takes the blockID and a association list of all the <key . value > pairs.
... since you are using Lee's stuff ; similar to http://www.lee-mac.com/attributefunctions.html#alsetattributevaluesit
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

pedroantonio

  • Guest
Re: fill scalebar tags
« Reply #39 on: November 08, 2014, 09:38:47 AM »
Hi  Kerry I change the code but give me only 0.00 and it is very slow

Code - Auto/Visual Lisp: [Select]
  1. ;; Set Attribute Value  -  Lee Mac
  2. ;; Sets the value of the first attribute with the given tag found within the block, if present.
  3. ;; blk - [vla] VLA Block Reference Object
  4. ;; tag - [str] Attribute TagString
  5. ;; val - [str] Attribute Value
  6. ;; Returns: [str] Attribute value if successful, else nil.
  7.  
  8. (defun LM:vl-setattributevalue ( blk tag val )
  9.     (setq tag (strcase tag))
  10.     (vl-some
  11.        '(lambda ( att )
  12.             (if (= tag (strcase (vla-get-tagstring att)))
  13.                 (progn (vla-put-textstring att val) val)
  14.             )
  15.         )
  16.         (vlax-invoke blk 'getattributes)
  17.     )
  18. )
  19.  
  20. (defun c:test (/ b p d1 d2 d3 d4 d5 d6 d7 scale) ;scalebar
  21.   (if (and (setq scale (getint "\nEnter scale to use: "))
  22.            (setq p (getpoint "\nSelect insert point for scale bar:"))
  23.            (setq bname (findfile "test.dwg"))
  24.       )
  25.     (progn (command "_layer" "_m" "scale" "_c" "7" "" "")
  26.            (setvar 'attreq 0)
  27.            (command "insert" bname p scale scale "0")
  28.            (setq b (vlax-ename->vla-object (entlast)))
  29.            (lm:vl-setattributevalue b "D1" (strcat (rtos (/ 50 scale) 2 2)))
  30.            (lm:vl-setattributevalue b "D2" (strcat (rtos (/ 100 scale) 2 2)))
  31.            (lm:vl-setattributevalue b "D3" (strcat (rtos (/ 50 scale) 2 2)))
  32.            (lm:vl-setattributevalue b "D4" (strcat (rtos (* (/ 50 scale) 2) 2 2)))
  33.            (lm:vl-setattributevalue b "D5" (strcat (rtos (* (/ 50 scale) 3) 2 2)))
  34.            (lm:vl-setattributevalue b "D6" (strcat (rtos (/ 50 scale) 2 2)))
  35.            (lm:vl-setattributevalue b "D7" (strcat (rtos (/ 10 scale) 2 2)))
  36.            (lm:vl-setattributevalue b "SCALE" (strcat (rtos scale 2 0)))
  37.            (setvar 'attreq 1)
  38.     )
  39.   )
  40. )
  41.  
  42.  

Any ideas

pedroantonio

  • Guest
Re: fill scalebar tags
« Reply #40 on: November 08, 2014, 09:49:29 AM »
I change the maths and works

Code: [Select]
(lm:vl-setattributevalue b "D1" (strcat (rtos (/ scale 50) 2 0)))
           (lm:vl-setattributevalue b "D2" (strcat (rtos (/ scale 100) 2 0)))
           (lm:vl-setattributevalue b "D3" (strcat (rtos (/ scale 50) 2 0)))
           (lm:vl-setattributevalue b "D4" (strcat (rtos (* (/ scale 50) 2) 2 0)))
           (lm:vl-setattributevalue b "D5" (strcat (rtos (* (/ scale 50) 3) 2 0)))
           (lm:vl-setattributevalue b "D6" (strcat (rtos (* (/ scale 50) 4) 2 0)))
           (lm:vl-setattributevalue b "D7" (strcat (rtos (/ scale 10) 2 0)))
           (lm:vl-setattributevalue b "SCALE" (strcat (rtos scale 2 0)))

Thanks  :-D

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: fill scalebar tags
« Reply #41 on: November 09, 2014, 03:43:53 AM »
I change the maths and works

< .. >
Thanks  :-D

You're welcome. Glad to be able to help.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: fill scalebar tags
« Reply #42 on: November 09, 2014, 09:27:03 PM »
This is one way I'd look at

See if it's any faster ...

Code - Auto/Visual Lisp: [Select]
  1. ;;;------------------------------------------------------------------
  2. ;;;------------------------------------------------------------------
  3. ;;;
  4. ;| KDUB:SetAttributes
  5.     < BlockRef > Object [VLA-OBJECT]
  6.     < DotList   > Dot-list '(("tagstring1" . "textstring1")...) [LIST]
  7.        
  8.         Description: Set attribute values to a block.
  9.    
  10.         Return [Typ]    ==>nil
  11.        
  12.         Remarks:        N/a
  13.         Dependencies:   N/a    
  14. revised kdub 2003 for ac2004|;
  15. ;;;------------------------------------------------------------------
  16. ;;;------------------------------------------------------------------
  17. ;;;
  18.  
  19. (defun kdub:setattributes (blockref dotlist / catchit attval)
  20.   (if (= (type blockref) 'ename)
  21.     (setq blockref (vlax-ename->vla-object blockref))
  22.   )
  23.                                    (vl-catch-all-apply 'vlax-invoke (list blockref 'getattributes))
  24.                             )
  25.       )
  26.     ;; else
  27.     (progn
  28.       (mapcar
  29.         '(lambda (attref)
  30.            (if (setq attval (cdr (assoc (vla-get-tagstring attref) dotlist)))
  31.              (vla-put-textstring attref attval)
  32.            )
  33.          )
  34.         catchit
  35.       )
  36.       (vla-update blockref)
  37.     )
  38.   )
  39.   (princ)
  40. )
  41.  
  42.  

Code - Auto/Visual Lisp: [Select]
  1. ;; kdub@theSwamp Nov2014
  2. (defun c:test-03 (/ b bname p scale)         ;scalebar
  3.   (if (and (setq scale (getint "\nEnter scale to use: "))
  4.            (setq p (getpoint "\nSelect insert point for scale bar:"))
  5.            (setq bname (findfile "test.dwg"))
  6.       )
  7.     (progn (command "_layer" "_m" "scale" "_c" "7" "" "")
  8.            (setvar 'attreq 0)
  9.            (command "insert" bname p scale scale "0")
  10.            (setq b (vlax-ename->vla-object (entlast)))
  11.            (setq TagData (list (cons "D1" (strcat (rtos (/ scale 50.) 2 1)))
  12.                                (cons "D2" (strcat (rtos (/ scale 100.) 2 1)))
  13.                                (cons "D3" (strcat (rtos (/ scale 50.) 2 1)))
  14.                                (cons "D4" (strcat (rtos (* (/ scale 50.) 2) 2 1)))
  15.                                (cons "D5" (strcat (rtos (* (/ scale 50.) 3) 2 1)))
  16.                                (cons "D6" (strcat (rtos (* (/ scale 50.) 4) 2 1)))
  17.                                (cons "D7" (strcat (rtos (/ scale 10.) 2 1)))
  18.                                (cons "SCALE" (strcat (rtos scale 2 0)))
  19.                          )
  20.            )
  21.            (kdub:setattributes b TagData)
  22.            (setvar 'attreq 1)
  23.     )
  24.   )
  25. )
  26.  
« Last Edit: November 10, 2014, 06:16:13 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

pedroantonio

  • Guest
Re: fill scalebar tags
« Reply #43 on: November 10, 2014, 01:43:40 AM »
Here is an error

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test3 (/ b bname p scale)         ;scalebar
  2.   (if (and (setq scale (getint "\nEnter scale to use: "))
  3.            (setq p (getpoint "\nSelect insert point for scale bar:"))
  4.            (setq bname (findfile "test.dwg"))
  5.       )
  6.     (progn (command "_layer" "_m" "scale" "_c" "7" "" "")
  7.            (setvar 'attreq 0)
  8.            (command "insert" bname p scale scale "0")
  9.            (setq b (vlax-ename->vla-object (entlast)))
  10.            (setq TagData (list (cons "D1" (strcat (rtos (/ scale 50) 2 0)))
  11.                                (cons "D2" (strcat (rtos (/ scale 100) 2 0)))
  12.                                (cons "D3" (strcat (rtos (/ scale 50) 2 0))
  13.                                (cons "D4" (strcat (rtos (* (/ scale 50) 2) 2 0)))
  14.                                (cons "D5" (strcat (rtos (* (/ scale 50) 3) 2 0)))
  15.                                (cons "D6" (strcat (rtos (* (/ scale 50) 4) 2 0)))
  16.                                (cons "D7" (strcat (rtos (/ scale 10) 2 0)))
  17.                                (cons "SCALE" (strcat (rtos scale 2 0)))
  18.                          )
  19.            )
  20.            (kdub:setattributes b TagData)
  21.            (setvar 'attreq 1)
  22.     )
  23.   )
  24. )
  25.  

[CHECKING TEXT <Untitled-0> loading...]
..
; error: malformed list on input
; Check done.


pedroantonio

  • Guest
Re: fill scalebar tags
« Reply #44 on: November 10, 2014, 01:53:53 AM »
Kerry is it possible to add a filter and when the scale is
50,150,250,350,450,650,...... then use this math for D2

Code: [Select]
(cons "D2" (strcat (rtos (/ scale 100) 2 1)))