simple request to get block scale by block name

simple request to get block scale by block name

Anonymous
Not applicable
1,990 Views
4 Replies
Message 1 of 5

simple request to get block scale by block name

Anonymous
Not applicable

I am trying to get the scale from a block that i know the name of and assign it to variable.

when i resize my title block i need to find the x scale of a block named logo and set "dscale" to that value so i can insert blocks where i need them by that scale.

what i have doesnt seem to work.

 

 

(setq en("business logo"))

(setq enlist(entget en))
(setq dscale (cdr(assoc 41 enlist)))

 

 

when i run it and ask the user to select the block (like below) it works

 

(setq en(car (entsel "\n Select an image:")))

(setq enlist(entget en))
(setq dscale (cdr(assoc 41 enlist)))

 

but i need it to grab the block by the name "business logo" and grab the x scale from it

 

ive tried the

(if (tblsearch "BLOCK" "business logo")

 

but i seem to not be able to figure out why this keeps giving me errors

 

 

seems like a simple thing to do but i am stuck and need to brush up on my lisp 

any help would be appreciated

0 Likes
1,991 Views
4 Replies
Replies (4)
Message 2 of 5

Kent1Cooper
Consultant
Consultant

I assume the

 

(setq en("business logo"))

 

is to set the Block name into the 'en' variable, but if so, the name as a text string must not be in parentheses.  Do it:

 

(setq en "business logo")

 

Then, this:

 

(setq enlist(entget en))

 

is invalid, because (entget) requires an entity name, such as that of a Block reference or insertion, not just a Block's name, which is unattached to any drawn entity [and therefore can't have, for example, scale factors].  To have the routine find a Block by that name and get its entity data, you will need it to search the drawing for insertions of Blocks by that name [even if there's only one], and get the entity data from the first [even if it's the only] Block insertion that it finds.  Try this:

 

(setq enlist (entget (ssname (ssget "_X" (list (cons 2 en))) 0)))

 

You could accomplish the same without the need for the 'en' variable at all, if you prefer:

 

(setq enlist (entget (ssname (ssget "_X" '((2 . "business logo"))))))

 

Note the difference between

 

... "_X" (list (cons 2 en))...

 

which needs to build its filter list with the explicit (list) function because it needs to evaluate the 'en' variable, and

 

... "_X" '((2 . "business logo"))...

 

which can use the "shortcut" version of the (quote) function [the apostrophe] to make the list, since all the information is specific and nothing needs to be evaluated but can be read directly [i.e. "quoted"].

 

Some would include the entity type in the (ssget) filter list:

 

(setq enlist (entget (ssname (ssget "_X" '((0 . "INSERT") (2 . "business logo"))))))

 

But unless you have any other kinds of entities with (assoc 2) entries that could be "business logo" [which seems highly unlikely], that shouldn't be necessary.

 

Then the:


(setq dscale (cdr (assoc 41 enlist)))

 

should work as expected.

Kent Cooper, AIA
0 Likes
Message 3 of 5

theseb1994
Participant
Participant

Hi there,

 

I'm trying to do something pretty similar. Here is the code I'm using but I keep getting a "too few arguments" error.

 

 

(setq enlist(entget(ssname(ssget "_X" '((0 . "BLOCK")(2 . "_block_name"))))))
(setq dscale(cdr(assoc 41 enlist)))

 

 

Any help would be greatly appreciated!!

0 Likes
Message 4 of 5

dbroad
Mentor
Mentor

ssname takes two arguments (ssname <selectionset> <index>)

 

BTW: You should avoid assumptions such as the fact that ssget will return anything by restructuring to add an if

;Will work
(setq
enlist (entget
(ssname
(ssget "_X" '((0 . "INSERT") (2 . "_block_name")))
0)
)
)
(setq dscale (cdr (assoc 41 enlist))) ;Better (if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "_block_name")))) (progn (setq enlist (entget (ssname ss 0))) (setq dscale (cdr(assoc 41 enlist))))) ;Block is not a type of object. Use insert.
Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 5 of 5

theseb1994
Participant
Participant
Fantastic! Thank you so much!
0 Likes