TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Lupo76 on June 11, 2013, 12:30:33 PM

Title: Scaling the nested entities of a block
Post by: Lupo76 on June 11, 2013, 12:30:33 PM
Hello to all,
I searched the web but I could not find it.

Is there a lisp able to scale the entities nested inside a block, without using the block editor?
It would be nice that he could work with multiple blocks simultaneously.

Thanks in advance
Title: Re: Scaling the nested entities of a block
Post by: CAB on June 11, 2013, 01:16:21 PM
You can modify the block definition.

Title: Re: Scaling the nested entities of a block
Post by: Tharwat on June 11, 2013, 01:50:07 PM
Try this ...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ sc ss i sn en)
  2.   (if (and (setq sc (getdist "\n Specify The scale factor :"))
  3.            (setq ss  (ssget "_:L"  '((0 . "INSERT"))))
  4.       )
  5.     (repeat (setq i (sslength ss))
  6.       (setq sn (ssname ss (setq i (1- i))))
  7.       (setq en (tblobjname "BLOCK" (cdr (assoc 2 (entget sn)))))
  8.       (while (setq en (entnext en))
  9.         (if (eq (cdr (assoc 0 (entget en))) "INSERT")
  10.           (vl-catch-all-apply
  11.             'vla-scaleEntity
  12.             (list (vlax-ename->vla-object en)
  13.                   (vlax-3d-point (cdr (assoc 10 (entget en))))
  14.                   sc
  15.             )
  16.           )
  17.         )
  18.       )
  19.     )
  20.   )
  21.   (command "_.regen")
  22.   (princ)
  23. )
  24.  
Title: Re: Scaling the nested entities of a block
Post by: Lupo76 on June 12, 2013, 01:20:11 AM
You can modify the block definition.

Yes, this I know, but I have hundreds of blocks "with name and different graphics" in the drawing.
And so I'm looking for a lisp to speed up this operation.
Title: Re: Scaling the nested entities of a block
Post by: Lupo76 on June 12, 2013, 01:29:04 AM
Try this ...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ sc ss i sn en)
  2. ---- etc
  3. )
  4.  

What should he do this lisp.
I've tried it in AutoCAD 2010 but did nothing  :-(

I try to better explain my need:
I have hundreds of blocks in the drawing "with name and different graphics", all included with scale in X, Y, Z = 1

I want to scale the contents of the blocks (nested objects inside them) to make sure that the insertion scale remains stable in X, Y, Z = 1.

Thank you all in advance for suggestions.
Title: Re: Scaling the nested entities of a block
Post by: Marc'Antonio Alessi on June 12, 2013, 02:57:02 AM
Ti conviene allegare un esempio di un blocco "prima" e "dopo".
Se ho ben capito, devi scalare i blocchi annidati in un blocco?
Title: Re: Scaling the nested entities of a block
Post by: Lupo76 on June 12, 2013, 03:11:24 AM
Ti conviene allegare un esempio di un blocco "prima" e "dopo".
Se ho ben capito, devi scalare i blocchi annidati in un blocco?


Non devo scalare i "blocchi annidati dentro i blocchi", ma gli "oggetti annidati dentro i blocchi" senza scalare l'oggetto "blocco".
Nel file che ho allegato vedrai dei blocchi con scala di inserimento in X Y e Z pari a 10. Io vorrei che la grafica del blocco sia scalata 10 volte pił piccola, ma che nel pannello delle proprietą venga riportata come scala di inserimento sempre 10.

Spero di essere stato chiaro.

Translate in english:
I do not have scale the "nested blocks in the blocks", but the "nested objects within blocks" without scaling the object "block."
In the file I attached you will see the blocks with insertion scale in XY and Z equal to 10. I wish that the graphics of the block is scaled 10 times smaller, but in the properties panel is reported as scale always added 10.

I hope I was clear.
Title: Re: Scaling the nested entities of a block
Post by: Marc'Antonio Alessi on June 12, 2013, 03:30:20 AM
You must act as Tharwat (and CAB) have suggested.
Indeed the function of Tharwat does not work,
perhaps it needs some little modification...

I think Tharwat solution modify only nested blocks:
>>> (if (eq (cdr (assoc 0 (entget en))) "INSERT")

Try this ONLY as example not as solution:
Code: [Select]
(defun c:Test (/ sc ss i sn en)
 (if (and (setq sc (getdist "\n Specify The scale factor :"))
          (setq ss  (ssget "_:L"  '((0 . "INSERT"))))
     )
   (repeat (setq i (sslength ss))
     (setq sn (ssname ss (setq i (1- i))))
     (setq en (tblobjname "BLOCK" (cdr (assoc 2 (entget sn)))))
     (while (setq en (entnext en))
         (vl-catch-all-apply
           'vla-scaleEntity
           (list (vlax-ename->vla-object en)
                 (vlax-3d-point (cdr (assoc 10 (entget en))))
                 sc
           )
         )
     )
   )
 )
 (command "_.regen")
 (princ)
)
[\code]
Title: Re: Scaling the nested entities of a block
Post by: Tharwat on June 12, 2013, 03:02:02 PM
Try this ...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ sc ss i sn en)
  2. ---- etc
  3. )
  4.  

What should he do this lisp.
I've tried it in AutoCAD 2010 but did nothing  :-(


It does scale the nested blocks only .
Title: Re: Scaling the nested entities of a block
Post by: Lupo76 on June 13, 2013, 01:13:59 AM
Ok thank you all!
I solved it.

Code: [Select]
(defun c:Test (/ sc ss i sn en)
  (if (and (setq sc (getdist "\n Specify The scale factor :"))
           (setq ss  (ssget "_:L"  '((0 . "INSERT"))))
      )
    (repeat (setq i (sslength ss))
      (setq sn (ssname ss (setq i (1- i))))
      (setq en (tblobjname "BLOCK" (cdr (assoc 2 (entget sn)))))
      (while (setq en (entnext en))
        (progn
          (vl-catch-all-apply
            'vla-scaleEntity
            (list (vlax-ename->vla-object en)
                  (vlax-3d-point (list 0 0 0))
                  sc
            )
          )
        )
      )
    )
  )
  (command "_.regen")
  (princ)
)
(vl-load-com)






I replaced replaced the line

Code: [Select]
(vlax-3d-point (cdr (assoc 10 (entget en))))
with

Code: [Select]
(vlax-3d-point (list 0 0 0))
and removed the type checking of entity.

Now is ok.
Title: Re: Scaling the nested entities of a block
Post by: roy_043 on June 13, 2013, 03:20:29 AM
@ Lupo76:
There is a problem if the selection contains multiple inserts referencing the same block. That block will then be scaled multiple times...
Title: Re: Scaling the nested entities of a block
Post by: Lupo76 on June 13, 2013, 03:22:44 AM
it is true!
However in my case I do not have these situations.
No I never nested blocks ;-)
Title: Re: Scaling the nested entities of a block
Post by: Lee Mac on June 13, 2013, 08:26:02 AM
However in my case I do not have these situations.
No I never nested blocks ;-)

Note that roy was referring to multiple occurrences of the same block, not nested block references.
To avoid this problem, simply check whether the block definition has already been processed:

Code: [Select]
(defun c:test ( / e f i l n s )
    (if
        (and
            (progn
                (initget 6)
                (setq f (getdist "\nScale Factor: "))
            )
            (setq s (ssget "_:L" '((0 . "INSERT"))))
        )
        (repeat (setq i (sslength s))
            (if (not (member (setq n (cdr (assoc 2 (entget (ssname s (setq i (1- i))))))) l))
                (progn
                    (setq l (cons n l)
                          e (tblobjname "block" n)
                    )
                    (while (setq e (entnext e))
                        (vl-catch-all-apply 'vlax-invoke (list (vlax-ename->vla-object e) 'scaleentity '(0.0 0.0 0.0) f))
                    )
                )
            )
        )
    )
    (command "_.regen")
    (princ)
)
(vl-load-com) (princ)
Title: Re: Scaling the nested entities of a block
Post by: Lupo76 on June 13, 2013, 10:23:51 AM
Perfect!
Thank you!!!
Title: Re: Scaling the nested entities of a block
Post by: Lee Mac on June 13, 2013, 10:25:43 AM
You're welcome.  :-)
Title: Re: Scaling the nested entities of a block
Post by: ribarm 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?
Title: Re: Scaling the nested entities of a block
Post by: Lee Mac 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
Title: Re: Scaling the nested entities of a block
Post by: ribarm 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.  
Title: Re: Scaling the nested entities of a block
Post by: Lupo76 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