Author Topic: Routine Lisp help  (Read 1952 times)

0 Members and 2 Guests are viewing this topic.

renkor

  • Newt
  • Posts: 27
Routine Lisp help
« on: September 01, 2018, 03:17:25 PM »
Hello,

I have this code, which at the beginning was made to increment 1 attribute from a block, but now i need to increment 3 attributes from the same block. Any help? Block is attached.

Thanks in advance.

Code - Auto/Visual Lisp: [Select]
  1. ;;
  2.  
  3. (defun c:pagbloc2 (/ _padzeros _insblock b dn se d n lnum inc bn xyz d1)
  4. (defun _padzeros ( s l)
  5.         (if (< (strlen s) l) (_padzeros (strcat "0" s) l) s)
  6.     )
  7. (defun _insblock (e ds bnm data i il  / pt p_ang)
  8.         (setq pt (vlax-curve-getpointatdist e ds))
  9.         (setq p_ang (angle '(0.0 0.0 0.0) (vlax-curve-getfirstderiv se (vlax-curve-getparamatpoint e pt))))
  10.         (setq part (vlax-invoke
  11.                            (vlax-get
  12.                                  (vla-get-ActiveLayout
  13.                                        (vla-get-activedocument
  14.                                              (vlax-get-acad-object)))
  15.                                  'Block)
  16.                            'InsertBlock pt bnm
  17.                            (car data)(cadr data)(caddr data)
  18.                            p_ang))
  19.         (vla-put-textstring (car (vlax-invoke part 'GetAttributes))
  20.           (_padzeros (itoa i) il)
  21.           )
  22.   )
  23.   (if (and             
  24.         (setq b (car (entsel "\nSelect block")))
  25.         (setq dn (getreal "\n Enter distance :"))
  26.         (setq se (car (entsel "\nSelect path")))
  27.       )
  28.         (progn
  29.           (setq n  (fix (/ d dn)))
  30.           (setq lnum (strlen (itoa n)) num 1)
  31.           (setq inc dn)
  32.           (setq bn (cdr (assoc 2 (setq bdata (entget b)))))
  33.           (setq xyz (mapcar '(lambda (s)
  34.                                (cdr (assoc s bdata))) '( 41 42 43 8 10)))
  35.           (setvar 'clayer (cadddr xyz))
  36.           (setq d1 (vlax-curve-getdistatpoint se (vlax-curve-getclosestpointto  se (last xyz))))
  37.          
  38.          (_insblock se (Setq inc (+ inc d1)) bn xyz (setq num (1+ num)) 2)
  39.          
  40.         (repeat (1- n)
  41.           (_insblock se (Setq inc (+ inc dn)) bn xyz (setq num (1+ num)) 2)
  42.          
  43.         )
  44.       )      
  45.     )
  46.   (princ)
  47. )

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Routine Lisp help
« Reply #1 on: September 04, 2018, 09:19:04 AM »
Assuming your block only has 3 attributes, change this:
Code: [Select]
(vla-put-textstring (car (vlax-invoke part 'getattributes)) (_padzeros (itoa i) il))to this
Code: [Select]
(foreach att (vlax-invoke part 'getattributes) (vla-put-textstring att (_padzeros (itoa i) il)))
« Last Edit: September 04, 2018, 09:22:50 AM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

renkor

  • Newt
  • Posts: 27
Re: Routine Lisp help
« Reply #2 on: September 05, 2018, 11:36:57 AM »
Hello,

thanks for replying. it gives an error "Select path; error: no function definition: _INSBLOCK"

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Routine Lisp help
« Reply #3 on: September 05, 2018, 12:21:48 PM »
Just tested and works fine here?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

renkor

  • Newt
  • Posts: 27
Re: Routine Lisp help
« Reply #4 on: September 05, 2018, 01:22:50 PM »
Hello,

I retested it and works very good.
Thanks a lot.

renkor

  • Newt
  • Posts: 27
Re: Routine Lisp help
« Reply #5 on: September 07, 2018, 12:05:00 PM »
Hello,

In the block to align, I added some movement parameters to displace the mtext and attributes inside the block if i need it. But when I test the code again, the movement parameters of new blocks are not copied. Does it have to be recode for that?