Scale a block from its insertion point(pre-set block's name)

Scale a block from its insertion point(pre-set block's name)

sam_safinia
Advocate Advocate
1,244 Views
4 Replies
Message 1 of 5

Scale a block from its insertion point(pre-set block's name)

sam_safinia
Advocate
Advocate

I have this lisp from here but it prompts to select a block before scaling it.

 

 

 

Spoiler
(defun c:sscale(/ ss cn entn ent ans sca)
(setq ss (ssget '((0 . "INSERT"))))
(setq sca (getreal "give scalefactor: "))
(setq cn 0)
(repeat (sslength ss)
(setq ent (entget (setq entn (ssname ss cn))))
(setq cn (1+ cn))
(entmod (subst (cons 50 cn) (assoc 50 ent) ent))
(progn
(setq ent (subst (cons 41 (* (cdr (assoc 41 ent)) sca))
(assoc 41 ent) ent))
(setq ent (subst (cons 42 (* (cdr (assoc 42 ent)) sca))
(assoc 42 ent) ent))
(setq ent (subst (cons 43 (* (cdr (assoc 43 ent)) sca))
(assoc 43 ent) ent))
(entmod ent)
)
)
(princ)
)

 

How can I specific block's name instead of selection? I want it gets the block's name from a list, some thing like 

....(strcat "C:/" Block ".dwg")... or any block name.

 

Thanks

0 Likes
Accepted solutions (2)
1,245 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant
Accepted solution

Try this...

 

Spoiler
(vl-load-com)

(defun c:bnscale (/ ss cn entn ent ans sca blkname found objs ss i blk objs name)
  
  (if (and (setq blkname (getstring T "\n Enter name block :"))
           (setq found (tblsearch "BLOCK" blkname))
           (setq objs (ssadd)
                 ss   (ssget "_x" '((0 . "INSERT")))
           )
      )
    (progn
      (repeat
        (setq i (sslength ss))
         (setq name (vla-get-effectivename
                      (vlax-ename->vla-object
                        (setq blk (ssname ss (setq i (1- i))))
                      )
                    )
         )
         (if (eq (strcase blkname) (strcase name))
           (ssadd blk objs)
         )
      )))
 
  
  (if (and objs
	   (setq ss objs)
	   (or (initget 1)
	       (setq sca (getreal "\nGive scalefactor: ")))
	   (setq cn 0)
	   )
  (repeat (sslength ss)
    (setq ent (entget (setq entn (ssname ss cn))))
    (setq cn (1+ cn))
    (entmod (subst (cons 50 cn) (assoc 50 ent) ent))
    (progn
      (setq ent (subst (cons 41 (* (cdr (assoc 41 ent)) sca))
		       (assoc 41 ent) ent))
      (setq ent (subst (cons 42 (* (cdr (assoc 42 ent)) sca))
		       (assoc 42 ent) ent))
      (setq ent (subst (cons 43 (* (cdr (assoc 43 ent)) sca))
		       (assoc 43 ent) ent))
      (entmod ent)
      )
    )
    )
  (princ)
)

For nameblock selection used _Tharwat's code originally posted here thx

0 Likes
Message 3 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

@s_plant wrote:

.... 

How can I specific block's name instead of selection? I want it gets the block's name from a list, some thing like 

....(strcat "C:/" Block ".dwg")... or any block name.

 

Thanks


If you want it to find all Blocks of a certain specific name, replace this:

 

  (setq ss (ssget '((0 . "INSERT"))))

 

with this]:

 

  (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 "YourBlockName"))))

 

The "_X" tells it to search the whole drawing, rather than ask the User to select [read about it in Help for the (ssget) function].  "YourBlockName" can be a variable name [without the double-quotes] containing a Block name, rather than an explicit name as a text string, and that can be pulled from a list, but exactly how would depend on the form of your list and how it's supposed to know which item in the list to use.  Can you give more detail about that?  [[ EDIT:  If you want it to do the same to all Block names in a list, it can find all of them at once, rather than running it for each name separately, by stringing the Block names together with comma separators, and using that collective string in place of "YourBlockName" above. ]]

 

But whether a spelled-out name or a variable, it needs to be a Block definition that's already in the drawing.  If you want the routine to look for Blocks by name, I don't understand what your (strcat "C:/" Block ".dwg") part is for.  Any drawing that has been Inserted and is now a Block name in the current drawing will not have a path or filetype ending associated with it any longer in the current drawing.

 

[The 'entn' variable is never used, and the (progn) function isn't doing anything for you.]

 

[I'm also confused by the

  (entmod (subst (cons 50 cn) (assoc 50 ent) ent))

line, which looks like it should be changing the rotation angle of each Block it finds to the count integer at the time, which would give them all different rotations in whole-number radian values.  But it doesn't affect rotations in a quick trial.  I can't imagine a reason for wanting to do that, so I really wonder what that's doing there -- should it be working with some association-list number other than 50 (rotation)?  I think the reason it's not affecting rotations is that it doesn't save 'ent' with that substitution in it, so the later functions that do save it with the scale factor substitutions are starting from the original version with its original rotation, and therefore if the 50-based line did change the rotation, those others change it back.]

Kent Cooper, AIA
0 Likes
Message 4 of 5

sam_safinia
Advocate
Advocate

Many thanks guys. Both are working exceleent. I had plan to fix an issue with this but even with running this lisp still I cannot figure out how I fina a way around it.

 

Here is my issue: because of percision limit of "linear parameter" to 0.0, I draw my dynamic blocks to 1/100 (1%) of actual size to get the right size of it on my 1:100 scaled drawing then I drew all of them in 1:1 scale. For istance for a fitting size of 275mm I draw it 275mm in 1:1 model space. Now when I insert it into 1:100 drawing it make it 100 times bigger. I resolved it in my lisp  during insert process by 0.01 of scaling factor.

The only issue is "block preview" size. As soon as I select an insertion point to add a block, the block shrink and the scaling factors and blocks come in right size. No issue.

 

Then I thought scaling the block before inserting into blocks which is not working just to see the preview in right size:(

And I am struggling to draw a fitting of size 275 in dynamic block to 2.75 because it rounds up it to 2.8 or in the other hand 280mm when I insert it into 1:100 drawing.

 

0 Likes
Message 5 of 5

sam_safinia
Advocate
Advocate

I made mistake in last post regarding percsion of linear parameters. It is fine now

0 Likes