Author Topic: Scaling the nested entities of a block  (Read 4379 times)

0 Members and 1 Guest are viewing this topic.

ribarm

  • Gator
  • Posts: 3293
  • Marko Ribar, architect
Re: Scaling the nested entities of a block
« Reply #15 on: June 13, 2013, 12:25:26 PM »
Code: [Select]
(setq f (getdist "\nScale Factor: "))

(getdist) will always return positive real number, so to prevent entering 0.0, you need (initget 2), and to prevent entering ENTER - nil value, you need (initget 1)...

So instead of :
Code: [Select]
(initget 6)
(setq f (getdist "\nScale Factor: "))

I would suggest :
Code: [Select]
(initget 3)
(setq f (getdist "\nScale Factor: "))

And what if "INSERT" contains "INSERT" entities... I suppose child "INSERT" entities will be scaled, and then child entities of child "INSERT" will be scaled... Shouldn't you operate only on parent "INSERT" entities?
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lee Mac

  • Seagull
  • Posts: 12917
  • London, England
Re: Scaling the nested entities of a block
« Reply #16 on: June 13, 2013, 01:11:14 PM »
Code: [Select]
(setq f (getdist "\nScale Factor: "))
(getdist) will always return positive real number, so to prevent entering 0.0, you need (initget 2)
Code: [Select]
Command: (getdist "\nEnter a distance: ")

Enter a distance: -2
-2.0

...and to prevent entering ENTER - nil value, you need (initget 1)...

I don't want to prevent the user from pressing ENTER - hence the if statement.
By preventing ENTER there is no way for the user to exit the program without forcing an error with Esc

ribarm

  • Gator
  • Posts: 3293
  • Marko Ribar, architect
Re: Scaling the nested entities of a block
« Reply #17 on: June 13, 2013, 01:55:10 PM »
OK Lee, so I left (initget 6)... Here is my modification for my second question - though not tested thoroughly...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:scaleparentinsertsinside ( / ssparins e f i l n s )
  2.  
  3.     (defun ssparins ( / blchk _reml ss sss i ins lst lstbl chbll parbll )
  4.  
  5.       (defun blchk ( ins / en lst )
  6.         (setq en (tblobjname "BLOCK" (cdr (assoc 2 (entget ins)))))
  7.         (while (setq en (entnext en))
  8.           (if (eq (cdr (assoc 0 (entget en))) "INSERT")
  9.             (setq lst (cons (tblobjname "BLOCK" (cdr (assoc 2 (entget en)))) lst))
  10.           )
  11.         )
  12.         lst
  13.       )
  14.  
  15.       (defun _reml (l1 l2 / a n ls)
  16.         (while
  17.           (setq n nil
  18.                 a (car l2)
  19.           )
  20.           (while (and l1 (null n))
  21.             (if (equal a (car l1) 1e-8)
  22.               (setq l1 (cdr l1)
  23.                     n t
  24.               )
  25.               (setq ls (append ls (list (car l1)))
  26.                     l1 (cdr l1)
  27.               )
  28.             )
  29.           )
  30.           (setq l2 (cdr l2))
  31.         )
  32.         (append ls l1)
  33.       )
  34.  
  35.       (setq ss (ssget "_:L" '((0 . "INSERT"))))
  36.       (setq sss (ssadd) i -1)
  37.       (while (setq ins (ssname ss (setq i (1+ i))))
  38.         (setq lst (cons ins lst))
  39.       )
  40.       (foreach ins lst
  41.         (setq lstbl (cons (tblobjname "BLOCK" (cdr (assoc 2 (entget ins)))) lstbl))
  42.       )
  43.       (setq lstbl (acet-list-remove-duplicates lstbl nil))
  44.       (foreach ins lst
  45.         (foreach in (vl-remove ins lst)
  46.           (if (member (tblobjname "BLOCK" (cdr (assoc 2 (entget in)))) (blchk ins))
  47.             (setq chbll (cons (tblobjname "BLOCK" (cdr (assoc 2 (entget in)))) chbll))
  48.           )
  49.         )
  50.       )
  51.       (setq chbll (acet-list-remove-duplicates chbll nil))
  52.       (setq parbll (_reml lstbl chbll))
  53.       (foreach ins lst
  54.         (if (member (tblobjname "BLOCK" (cdr (assoc 2 (entget ins)))) parbll)
  55.           (ssadd ins sss)
  56.         )
  57.       )
  58.       sss
  59.     )
  60.  
  61.     (if
  62.         (and
  63.             (progn
  64.                 (initget 6)
  65.                 (setq f (getdist "\nScale Factor: "))
  66.             )
  67.             (setq s (ssparins))
  68.         )
  69.         (repeat (setq i (sslength s))
  70.             (if (not (member (setq n (cdr (assoc 2 (entget (ssname s (setq i (1- i))))))) l))
  71.                 (progn
  72.                     (setq l (cons n l)
  73.                           e (tblobjname "block" n)
  74.                     )
  75.                     (while (setq e (entnext e))
  76.                         (vl-catch-all-apply 'vlax-invoke (list (vlax-ename->vla-object e) 'scaleentity '(0.0 0.0 0.0) f))
  77.                     )
  78.                 )
  79.             )
  80.         )
  81.     )
  82.     (command "_.regen")
  83.     (princ)
  84. )
  85.  
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lupo76

  • Bull Frog
  • Posts: 343
Re: Scaling the nested entities of a block
« Reply #18 on: June 14, 2013, 02:03:22 AM »
OK Lee, so I left (initget 6)... Here is my modification for my second question - though not tested thoroughly...

I see that my question has sparked your creativity  :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-D