Jump to content

get block properties


Tomislav

Recommended Posts

Hello friends..

I have a problem with getting some properties out of block...I'm trying like in these two ways

 

(setq blok(car(entsel "\nSelect block...")))
(setq blok_vla(vlax-ename->vla-object blok))
;1
(setq item_num (vlax-get-property blok_vla 'Count))
...
;2
(setq item_num (vla-get-Count blok_vla))

 

but I always get 'ActiveX Server returned the error: unknown name:'

any suggestions on how to obtain block properties

Link to comment
Share on other sites

Hi,

What are you trying to achieve ?

 

There is not property Count with Block references.

 

Dump the block with vlax-dump-object to see all properties & methods that is available?

Link to comment
Share on other sites

If you are wanting to count the number of blocks in the drawing file, I don't think you access it via the count method. If I'm not mistaken, that just counts how many items are inside an instance of the block.

Link to comment
Share on other sites

You can't achieve counting through reference entity (VLA-OBJECT)... Instead use count method on definition entity (VLA-OBJECT)...

To get the definition try :

(setq vla-blok (vlax-ename->vla-object (tblobjname "BLOCK" (vla-get-effectivename (vlax-ename->vla-object (car (entsel "\nPick block reference...")))))))

Then try count method...

 

[EDIT : I was wrong, you should check block definition collection VLA-OBJECT...]

 

(vla-get-count (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (vla-get-effectivename (vlax-ename->vla-object (car (entsel "\nPick block reference..."))))))

Edited by marko_ribar
Link to comment
Share on other sites

This may be what you want

 

(setq  doc (vla-get-activedocument (vlax-get-acad-object))) ; open database
(setq x 0)
(vlax-for block (vla-get-blocks doc) 
(if (not (wcmatch (strcase (vla-get-name block) t) "*_space*")) 
(vlax-for*ent block 
(setq x (+ x 1)) 
) ;_ end of vlax-for
) ;_ end of if 
(princ (strcat "\nThere are " (rtos x 2 0) "objects in block " (vla-get-name block)))
) ; end of vlax-for

Link to comment
Share on other sites

Thank you all for answers...what i'm trying to do is a routine to partially explode block...it must have happened to you sometimes that you wanted to take some line or text out of block but to leave everything

else in block, so i got an idea to make it in a way that you select block,than with 'nantsel' you select parts of block that you want to explode, and than with some kind of iterating function (that's why i need number of item's in block) i would get all objects from the block,remove those i want to explode and make same block without them...seems easy or?

What Marko wrote gives me number of items in a block, so i will go from there...and just to say that i would probably never figure out to compose that line of code :oops: , i still don't get it exactly

If you have some ideas on this lisp i'm making, or there already is that kind of lisp, i'll be happy to hear your suggestions...

Link to comment
Share on other sites

What i'm trying to do is a routine to partially explode block...select block, than with 'nentsel' you select parts of block that you want to explode, and than with some kind of iterating function i would get all objects from the block, remove those i want to explode and make same block without them...

 

In very simple terms:

(defun c:test ( / ent sel )
   (if (and (cdddr (setq sel (nentselp)))
            (setq ent (entmakex (entget (car sel))))
       )
       (progn
           (vla-transformby (vlax-ename->vla-object ent) (vlax-tmatrix (caddr sel)))
           (vla-delete (vlax-ename->vla-object (car sel)))
           (vla-regen (vla-get-activedocument (vlax-get-acad-object)) acallviewports)
       )
   )
   (princ)
)
(vl-load-com) (princ)

You may also find this program useful for your task.

  • Like 1
Link to comment
Share on other sites

well Lee, you make it look so easy 8) and that code is the solution....THANX

now i will take some time to process this code to better understand the mechanics of it...never used matrix before...

the other lisp you submitted via link is also a good example to learn from ...

Link to comment
Share on other sites

In very simple terms:

(defun c:test ( / ent sel )
   (if (and (cdddr (setq sel (nentselp)))
            (setq ent (entmakex (entget (car sel))))
       )
       (progn
           (vla-transformby (vlax-ename->vla-object ent) (vlax-tmatrix (caddr sel)))
           (vla-delete (vlax-ename->vla-object (car sel)))
           (vla-regen (vla-get-activedocument (vlax-get-acad-object)) acallviewports)
       )
   )
   (princ)
)
(vl-load-com) (princ)

You may also find this program useful for your task.

 

 

Smooth , elegant , brilliant .... art :-)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...