Author Topic: scale block  (Read 2194 times)

0 Members and 1 Guest are viewing this topic.

pedroantonio

  • Guest
scale block
« on: August 15, 2016, 09:27:06 AM »
Hi i have some blocks with names (Point,KORYFES,station,trigonom,KOKAEK,KOROT,AnnotPoint,AnnotKORYFES,Annotstation,Annottrigonom,AnnotKOKAEK,AnnotKOROT)

I am looking for a lisp to change the geometry of this blocks scale x, scale y , scale z to 1.

can any one helps me ?

thanks

ChrisCarlson

  • Guest
Re: scale block
« Reply #1 on: August 15, 2016, 10:08:19 AM »
Code - Auto/Visual Lisp: [Select]
  1. ;| Function: Scale Blocks at its insertion point.
  2.    Command Line: BS
  3.    Developed by: Theodorus Winata
  4.    January 2011 |;
  5.  
  6. (defun C:BS (/ cme eg en sf sl ss)
  7.   (setq cme (getvar "CMDECHO"))
  8.   (setvar "CMDECHO" 0)
  9.   (command ".undo" "group")
  10.   (setq ss (ssget '((0 . "INSERT")))
  11.         sl (sslength ss)
  12.         sf (getdist "\nSpecify scale factor: ")
  13.   ); setq
  14.   (while (>= (setq sl (1- sl)) 0)
  15.     (setq en (ssname ss sl)
  16.           eg (entget en)
  17.           eg (set_code eg 41 sf)
  18.           eg (set_code eg 42 sf)
  19.           eg (set_code eg 43 sf)
  20.     ); setq
  21.     (entmod eg)
  22.     (entupd en)
  23.   ); while
  24.   (command ".undo" "end")
  25.   (setvar "CMDECHO" cme)
  26.   (princ)
  27. ); defun
  28.  
  29. (defun set_code (eg code val)
  30.   (if (assoc code eg)
  31.     (setq eg (subst (cons code val) (assoc code eg) eg)
  32.           eg (cons (cons code val) eg)
  33.     ); setq
  34.   ); if
  35.   eg
  36. ); defun

Lifted from a google search

pedroantonio

  • Guest
Re: scale block
« Reply #2 on: August 15, 2016, 11:52:33 AM »
thank you i will check it

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: scale block
« Reply #3 on: August 15, 2016, 03:32:10 PM »
Heres some messing with visual lisp (this method will be slower, but it will work if you have dynamic blocks):
Code: [Select]
(defun C:test ( / SS ent vla-obj )
(vl-load-com)
(if (setq SS (ssget "X" (list (cons 0 "INSERT"))))
(repeat (setq i (sslength SS))
(setq ent (ssname SS (setq i (1- i))))
(setq vla-obj (vlax-ename->vla-object ent))
(if
(and
(or
(not (= (vla-get-XScaleFactor vla-obj) 1.0))
(not (= (vla-get-YScaleFactor vla-obj) 1.0))
(not (= (vla-get-ZScaleFactor vla-obj) 1.0))
)
; (vlax-get-IsDynamicBlock vla-obj :vlax-true)
(vlax-property-available-p vla-obj 'EffectiveName)
(member (vlax-get vla-obj 'EffectiveName)
'("Point" "KORYFES" "station" "trigonom" "KOKAEK" "KOROT" "AnnotPoint" "AnnotKORYFES" "Annotstation" "Annottrigonom" "AnnotKOKAEK" "AnnotKOROT")
)
)
(progn
(vla-put-XScaleFactor vla-obj 1.0)
(vlax-put-property vla-obj 'YScaleFactor 1.0)
(vlax-put vla-obj 'ZScaleFactor 1.0)
)
)
);repeat
)
(vla-Regen (vla-get-ActiveDocument (vlax-get-acad-object)) acActiveViewport)
(princ)
);defun
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

pedroantonio

  • Guest
Re: scale block
« Reply #4 on: August 16, 2016, 12:49:25 PM »
Thank you all for the help.My problem is solved 

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: scale block
« Reply #5 on: August 16, 2016, 04:07:13 PM »
By the way here's another approach (completely untested):
Code: [Select]
(defun C:test ( / SS vla-obj )
(vl-load-com)
(if (setq SS (ssget "_X" (list (cons 0 "INSERT")(cons 410 (getvar 'ctab)))))
(vlax-for vla-obj (vla-get-ActiveSelectionSet (vla-get-activedocument (vlax-get-acad-object)))
(if
(and
(eq (vla-get-isLayout vla-obj) :vlax-false)
(eq (vla-get-isXref vla-obj) :vlax-false)
(or
(not (= (vla-get-XScaleFactor vla-obj) 1.0))
(not (= (vla-get-property vla-obj 'YScaleFactor) 1.0))
(not (= (vlax-get vla-obj 'ZScaleFactor) 1.0))
)
; (vlax-get-IsDynamicBlock vla-obj :vlax-true)
(vlax-property-available-p vla-obj 'EffectiveName)
(member (vlax-get vla-obj 'EffectiveName)
'("Point" "KORYFES" "station" "trigonom" "KOKAEK" "KOROT" "AnnotPoint" "AnnotKORYFES" "Annotstation" "Annottrigonom" "AnnotKOKAEK" "AnnotKOROT")
)
); and
(progn
(vla-put-XScaleFactor vla-obj 1.0)
(vlax-put-property vla-obj 'YScaleFactor 1.0)
(vlax-put vla-obj 'ZScaleFactor 1.0)
)
); if
); vlax-for
); if SS
(vla-Regen (vla-get-ActiveDocument (vlax-get-acad-object)) acActiveViewport)
(princ)
);defun
I think it should be faster, since the objects from the SS are not converted into VLA objects (atleast I think so).
And I had fun writing it.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

ronjonp

  • Needs a day job
  • Posts: 7529
Re: scale block
« Reply #6 on: August 16, 2016, 04:17:50 PM »
Assuming these are not modified dynamic blocks, you could filter the selection with the blocknames directly:
Code - Auto/Visual Lisp: [Select]
  1. (setq ss
  2.        (ssget
  3.          "_X"
  4.          (list
  5.            '(0 . "INSERT")
  6.            (cons 410 (getvar 'ctab))
  7.            '(2
  8.              .
  9.              "Point,KORYFES,station,trigonom,KOKAEK,KOROT,AnnotPoint,AnnotKORYFES,Annotstation,Annottrigonom,AnnotKOKAEK,AnnotKOROT"
  10.             )
  11.          )
  12.        )
  13. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC