View Full Version : Is it possible to redefine a nested block on insert?
pmedina
2006-12-11, 04:47 PM
I have a company logo which is a dynamic block (call it block "LOGO"). It uses visibility states to change the address (there are 25 addresses). The block "LOGO" is inserted via a company custom menu (CUI)
Since "LOGO"" is a dynamic block, it resides in a drawing, call it "DWG1". Through the menu I bring in "DWG1" as exploded. The user is then able to access the dynamic functionality of block "LOGO" directly without having to explode "DWG1".
Occasionally an address changes and users need to update the block "LOGO" which contains the address.
I know how to redefine a block on insert, using
(command "_-insert" "Myblock=X:/path/Myblock")
But is it possible to redefine the block "LOGO" which contains the address, on insert, since it itself is not a separate drawing file but a nested block?
I could possibly have my addresses be blocks within the block "LOGO", and redefine the address blocks on insert, if those addresses are themselves separate drawings. But I would like to avoid that. There are 25 addresses. So i would have to redefine 25 blocks.
Thanks for any help.
kennet.sjoberg
2006-12-11, 09:09 PM
But is it possible to redefine the block "LOGO" which contains the address, on insert, since it itself is not a separate drawing file . . .
Make it as a separate drawing file, then use (command "_-insert" "Myblock=X:/path/Myblock")
: ) Happy Computing !
kennet
peter
2006-12-11, 09:33 PM
I have a company logo which is a dynamic block (call it block "LOGO"). It uses visibility states to change the address (there are 25 addresses). The block "LOGO" is inserted via a company custom menu (CUI)
Since "LOGO"" is a dynamic block, it resides in a drawing, call it "DWG1". Through the menu I bring in "DWG1" as exploded. The user is then able to access the dynamic functionality of block "LOGO" directly without having to explode "DWG1".
Occasionally an address changes and users need to update the block "LOGO" which contains the address.
I know how to redefine a block on insert, using
(command "_-insert" "Myblock=X:/path/Myblock")
But is it possible to redefine the block "LOGO" which contains the address, on insert, since it itself is not a separate drawing file but a nested block?
I could possibly have my addresses be blocks within the block "LOGO", and redefine the address blocks on insert, if those addresses are themselves separate drawings. But I would like to avoid that. There are 25 addresses. So i would have to redefine 25 blocks.
Thanks for any help.
Well Yes you can!
When your titleblock is inserted, you need to access the blocks collection of the drawing and find the titleblock block definition
(setq objBlockDefinition (vla-item (vla-get-blocks (vla-get-activedocument
(vlax-get-acad-object)
)
)
"Mytitleblockname"
)
)
Then iterate through it using a vlax for looking for your dynamic block
(vlax-for objBlock objBlockDefinition
(if (= (strcase (vla-get-effectivename objBlock))
(strcase "MYDYNAMICBLOCK")
)
(changevisibility objBlock)
)
)
Using this function
(defun GetDynamicBlockPropertyObjects (objSelection / lstProperties)
(if (and (vlax-property-available-p objSelection "IsDynamicBlock")
(= (vla-get-IsDynamicBlock objSelection) :vlax-true)
(setq lstProperties (errortrap '(vlax-safearray->list
(variant-value
(vla-GetDynamicBlockProperties objSelection)
)
)
)
)
)
(progn
(mapcar '(lambda (x)(cons (vla-get-propertyname X) X)) lstProperties)
)
)
)
You can get a list of the dynamic block properties and their values for that block
(defun ChangeVisibility (obj / lstOfPairs dprPair objVisibility )
(and (setq lstOfPairs (getdynamicblockobjects obj))
(setq dprPair (assoc "Visibility" lstOfPairs))
(setq objVisibility (cdr dprPair))
(vla-put-value objVisibility "VisibilityState1")
)
)
Or something like that.
Hope it helps
pmedina
2006-12-11, 09:35 PM
This is in response to the suggestion by Kennet.
Please correct me if i am not seeing things correctly. I don't see how that would work because the block "LOGO" is a dynamic block. As such it cannot exist as a separate drawing. A dynamic block can only exist inside a drawing.
pmedina
2006-12-11, 09:38 PM
With regard to the suggestion by Peter: Thanks Peter. I'll give it a shot.
pmedina
2006-12-13, 08:54 PM
Here's what I have so far. (I'm a very weak code writer, so forgive my ignorance, since i don't know 98% of what the code below does).
I added a line of code to insert a drawing which contains the nested block (MyDwgWithDynamicBlock.dwg). But it does not redefine the block that already exists in the drawing ("MYDYNAMICBLOCK"). It only inserts the block definition that already exists in the drawing.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; When your titleblock is inserted, you need to access the blocks
; collection of the drawing and find the titleblock block definition.
(DEFUN c:InsertMyDwg ()
(command "_-insert" "*H:/test/MyDwgWithDynamicBlock")
; Above, I insert "MyDwgWithDynamicBlock.dwg", exploded.
; The drawing "MyDwgWithDynamicBlock.dwg" contains a dynamic block called "MYDYNAMICBLOCK"
; -> My goal is to have "MYDYNAMICBLOCK" be redefined after i change "MYDYNAMICBLOCK"
; which resides in "MyDwgWithDynamicBlock.dwg"
(setq objBlockDefinition (vla-item (vla-get-blocks (vla-get-activedocument
(vlax-get-acad-object)
)
)
"MyDwgWithDynamicBlock"
)
)
; Then iterate through it using a vlax for looking for your dynamic block
(vlax-for objBlock objBlockDefinition
(if (= (strcase (vla-get-effectivename objBlock))
(strcase "MYDYNAMICBLOCK")
)
(changevisibility objBlock)
)
)
; Using this function
(defun GetDynamicBlockPropertyObjects (objSelection / lstProperties)
(if (and (vlax-property-available-p objSelection "IsDynamicBlock")
(= (vla-get-IsDynamicBlock objSelection) :vlax-true)
(setq lstProperties (errortrap '(vlax-safearray->list
(variant-value
(vla-GetDynamicBlockProperties objSelection)
)
)
)
)
)
(progn
(mapcar '(lambda (x)(cons (vla-get-propertyname X) X)) lstProperties)
)
)
)
;You can get a list of the dynamic block properties and their values for that block
(defun ChangeVisibility (obj / lstOfPairs dprPair objVisibility )
(and (setq lstOfPairs (getdynamicblockobjects obj))
(setq dprPair (assoc "Visibility" lstOfPairs))
(setq objVisibility (cdr dprPair))
(vla-put-value objVisibility "VisibilityState1")
)
)
)
;; Thanks for any help
[ Moderator Action = ON ] What are [ CODE ] tags... (http://forums.augi.com/misc.php?do=bbcode#code) [ Moderator Action = OFF ]
peter
2006-12-14, 02:49 AM
To redefine a block using the command line or command expression:
(command "_-insert" "*MyDwgWithDynamicBlock=" pause)
; Notice the = sign to update the block.
; Add these two lines to complete the insert and get the block object
(while (= (getvar "cmdactive") 1)(command ""))
(setq obj (vlax-ename->vla-object (entlast)) )
Peter
there are three functions listed below. I have not crash tested this but it should work for you. Place the contents in a text file and name it and load it. If the block has a visibiltystate1 it should activate that visibility state.
(defun C:InsertMyDwg (/ obj objBlockDefinition objBlock)
(command "_-insert" "*MyDwgWithDynamicBlock=" pause); select insertion point
(while (= (getvar "cmdactive") 1)(command ""))
(setq obj (vlax-ename->vla-object (entlast)) )
(setq objBlockDefinition (vla-item (vla-get-blocks (vla-get-activedocument
(vlax-get-acad-object)
)
)
"MyDwgWithDynamicBlock"
)
)
(vlax-for objBlock objBlockDefinition
(if (= (strcase (vla-get-effectivename objBlock))
(strcase "MYDYNAMICBLOCK")
)
(changevisibility objBlock)
)
)
)
;
(defun GetDynamicBlockPropertyObjects (objSelection / lstProperties)
(if (and (vlax-property-available-p objSelection "IsDynamicBlock")
(= (vla-get-IsDynamicBlock objSelection) :vlax-true)
(setq lstProperties (errortrap '(vlax-safearray->list
(variant-value
(vla-GetDynamicBlockProperties objSelection)
)
)
)
)
)
(progn
(mapcar '(lambda (x)(cons (vla-get-propertyname X) X)) lstProperties)
)
)
)
(defun ChangeVisibility (obj / lstOfPairs dprPair objVisibility )
(and (setq lstOfPairs (getdynamicblockobjects obj))
(setq dprPair (assoc "Visibility" lstOfPairs))
(setq objVisibility (cdr dprPair))
(vla-put-value objVisibility "VisibilityState1")
)
)
)
artisteroi
2007-08-09, 08:37 PM
(defun ChangeVisibility (obj / lstOfPairs dprPair objVisibility )
(and (setq lstOfPairs (getdynamicblockobjects obj))
(setq dprPair (assoc "Visibility" lstOfPairs))
(setq objVisibility (cdr dprPair))
(vla-put-value objVisibility "VisibilityState1")
)
)
)
[/code]
can we revive this old thread. the info that is posted here doesn't seem to work (too few arguments) and I am interested in this subject. Is there any new info?
How did you try to execute the code?
The code in which you quoted is to be run on a vla-object type. To run the command you would use the following syntax.
(ChangeVisibility vla-object_to_change)
jpaulsen
2007-10-10, 04:59 PM
I also am trying to redefine a nested block. I wrote a program to update our titleblocks (see this thread (http://forums.augi.com/showthread.php?p=767374#post767374)). I want to modify that program to update our logo block at the same time.
Our company logo is a nested block inside of the titleblock and it is not dynamic. I have a seperate logo drawing for each address and we have several different formats of the logo.
I know who to redefine the block. I can use similar code to what I am using to redefine the titleblock. What I really need to know is how to extract the logo block name from the titleblock so I know which logo to redefine. I'm pretty sure that the logo is the only nested block in our titleblocks.
How can I extract the name of a nested block from the my titleblock block?
pmedina
2007-10-10, 05:36 PM
As far as "extract the logo block name from the titleblock": I'm too weak a programmer to know how to do it with code. My only way would be to get in the drawing & list the block, or doulbe click the block to open the block editor (as many times as necessary) to get to the originating block entities. The block name will be listed in the block editor. In saying "as many times as necessary" i mean that you can be in the block editor, and if there is a nested block, you can double-click that & it will open that block)
FYI: I have not yet successfully implemented any of the suggestions. If you want to share your code, please do so. Thanks
ccowgill
2007-10-12, 01:34 PM
is there any chance you can use the design center, or a tool palette to redefine the block? design center might be your best bet, select the block from inside the blocks portion of the drawing and right click, say insert (or redefine if avaiable) when the box pops up to insert it, it will want to know if you want to redefine the block.
jpaulsen
2007-10-12, 02:57 PM
I am trying to automate the process. But in order to do that I need the name of the nested block extracted from the block I am inserting.
jpaulsen
2007-10-12, 10:39 PM
I got my answer on the Autodesk DG.
See THIS (http://discussion.autodesk.com/thread.jspa?messageID=5748573�)thread.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.