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

0 Members and 1 Guest are viewing this topic.

Lupo76

  • Bull Frog
  • Posts: 343
Scaling the nested entities of a block
« 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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Scaling the nested entities of a block
« Reply #1 on: June 11, 2013, 01:16:21 PM »
You can modify the block definition.

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Scaling the nested entities of a block
« Reply #2 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.  
« Last Edit: June 11, 2013, 02:08:33 PM by Tharwat »

Lupo76

  • Bull Frog
  • Posts: 343
Re: Scaling the nested entities of a block
« Reply #3 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.

Lupo76

  • Bull Frog
  • Posts: 343
Re: Scaling the nested entities of a block
« Reply #4 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.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: Scaling the nested entities of a block
« Reply #5 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?

Lupo76

  • Bull Frog
  • Posts: 343
Re: Scaling the nested entities of a block
« Reply #6 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.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1454
  • Marco
Re: Scaling the nested entities of a block
« Reply #7 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]

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: Scaling the nested entities of a block
« Reply #8 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 .

Lupo76

  • Bull Frog
  • Posts: 343
Re: Scaling the nested entities of a block
« Reply #9 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.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Scaling the nested entities of a block
« Reply #10 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...

Lupo76

  • Bull Frog
  • Posts: 343
Re: Scaling the nested entities of a block
« Reply #11 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 ;-)

Lee Mac

  • Seagull
  • Posts: 12917
  • London, England
Re: Scaling the nested entities of a block
« Reply #12 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)

Lupo76

  • Bull Frog
  • Posts: 343
Re: Scaling the nested entities of a block
« Reply #13 on: June 13, 2013, 10:23:51 AM »
Perfect!
Thank you!!!

Lee Mac

  • Seagull
  • Posts: 12917
  • London, England
Re: Scaling the nested entities of a block
« Reply #14 on: June 13, 2013, 10:25:43 AM »
You're welcome.  :-)