Jump to content

How do i get block reference from dwg?


BUrBaKy
 Share

Recommended Posts

Ok, so i have created a dymanic block with tags named "ID_EL" and saved it in a dwg named "ID_EL_DWG.dwg".

I open a new drawing and with vba in want to: import the "ID_EL" reference form the "ID_EL_DWG.dwg" file, and the insert the block 3 times in the modelspace with different tag values.

I figured out almost everything except the first part.

How can i load a block reference form another dwg into the current one?

 

I don't want to insert the dwg as block because then i must explode it to get acces to my dynamic block with tags to modify it.

 

Hope it's not a lot to ask, but i searched the web many times for this and found nothing. (except inserting dwg as block)

 

Alternative solutions are also welcome.

Thanks in advance!

Edited by BUrBaKy
i ate a letter :) (spelling mistake)
Link to comment
Share on other sites

this was discussed recently and I think the end result was that you couldn't. You can WBLOCK your block out from the drawing it currently lives in to make it available for INSERT without having to explode it. Alternatively you can add a * to the front of your block name to insert it already exploded.

Link to comment
Share on other sites

:: Once you've WBLOCKed your dynamic block ::

 

Instead of invoking the Add Method upon the Blocks Collection to define the Block Reference, only to insert said Block Reference (read create a new Block Item) multiple times into the ModelSpace object, why not simply use the InsertBlock Method and do both in one step (repeated x3 times in this situation):

 

 
object.[color=red]InsertBlock[/color](InsertionPoint, Name, Xscale, Yscale, ZScale, Rotation [, Password])

 

... Then modify each instance's tags accordingly.

 

Hope this helps!

Link to comment
Share on other sites

I think i found a way. It's not very professional but it get's the job done.

   Dim ipt(0 To 2) As Double
   Dim B As AcadBlockReference
   ipt(0) = 0: ipt(1) = 0: ipt(2) = 0
   Set B = ThisDrawing.ModelSpace.InsertBlock(ipt, "I:\ID_EL_DWG.dwg", 1#, 1#, 1#, 0)
   B.Delete
   Set B = ThisDrawing.ModelSpace.InsertBlock(ipt, "ID_EL", 1#, 1#, 1#, 0)
   ZoomAll

The thing is that by inserting the dwg, comes also the block reference inside the dwg separately.

So after the first .InsertBlock i wil have two references: ID_EL_DWG (wich i just inserted) and ID_EL (the block reference in the drawing i just inserted).

Then i can just erase the dwg and reinsert my wanted block, being assignet to the "B" object, making it ready to be tag-edited :)

Link to comment
Share on other sites

Ok, so i have created a dymanic block with tags named "ID_EL" and saved it in a dwg named "ID_EL_DWG.dwg".

I open a new drawing and with vba in want to: import the "ID_EL" reference form the "ID_EL_DWG.dwg" file, and the insert the block 3 times in the modelspace with different tag values.

...

I don't want to insert the dwg as block because then i must explode it to get acces to my dynamic block with tags to modify it.

 

You can WBLOCK your block out from the drawing it currently lives in to make it available for INSERT without having to explode it.

 

:: Once you've WBLOCKed your dynamic block ::

 

The thing is that by inserting the dwg, comes also the block reference inside the dwg separately.

So after the first .InsertBlock i wil have two references: ID_EL_DWG (wich i just inserted) and ID_EL (the block reference in the drawing i just inserted).

Then i can just erase the dwg and reinsert my wanted block, being assignet to the "B" object, making it ready to be tag-edited :)

 

Huh!? I guess it is true... you can only lead a horse to water. :(

Link to comment
Share on other sites

I must admit to not having read his request too carefully else I would have pointed out you don't need to explode it to get the extra block definitions but even so I thought you led him nicely.

 

Somebody used to have a sig about leading horses to water and Sat Navs but I have forgotten what it was. :(

Link to comment
Share on other sites

I must admit to not having read his request too carefully else I would have pointed out you don't need to explode it to get the extra block definitions but even so I thought you led him nicely.

 

No worries; and thank you, that's very kind of you to say.

 

Happy Friday. :)

Link to comment
Share on other sites

I tend to think i'm better than horses despite my begginer level in VBA, thank you.

 

It's true though, that i said i want to insert in a new file, although i actualy needed it to be inserted in an already open one. The reason i did that is, that i didn't know that it would be a difference (didn't know about the wblock method).

That's why i couldn't use "wblock" command.

As for InsertBlock method, it's what i used or maybe i didn't know how to exploit it fully for this case.Living is learning.

As for the horse, what may be true by lamplight is not always true in sunlight but i have to say you got good diplomatic skills.:)

Link to comment
Share on other sites

Huh!? I guess it is true... you can only lead a horse to water. :(

 

I tend to think i'm better than horses despite my begginer level in VBA, thank you.

 

My statement was analogous to the fact that you were provided a solution (twice), and then completely disregard said solution... I've not actually compared you (or anyone else) to a horse, dude.

 

It still is not clear, and truly does not matter, whether you've even tested the proposed solution. I voluntarily made my post and will continue to do so (God willing) for many years to come. What you decide to do with the information I share is, well, exactly that - for you to decide. I'm certainly not always correct.

 

It's true though, that i said i want to insert in a new file, although i actualy needed it to be inserted in an already open one. The reason i did that is, that i didn't know that it would be a difference (didn't know about the wblock method).

That's why i couldn't use "wblock" command.

As for InsertBlock method, it's what i used or maybe i didn't know how to exploit it fully for this case.Living is learning.

 

We all start somewhere.

 

WBLOCK is a command that would remove your need to copy / extract / etc. the Block Reference from another drawing (hence the suggestions). Simply open "ID_EL_DWG.dwg" and enter the WBLOCK command. In the resultant dialog, select 'block' in the upper left, and select "ID_EL" from the drop down list, specify a file path, and desired units, and hit OK.

 

The result is a block ("ID_EL.dwg" perhaps?) that can be inserted without duplicate block references ("ID_EL_DWG" and "ID_EL"), instead only making available a single block reference ("ID_EL").

 

In which case object.InsertBlock accomplishes your stated goal; simply be sure to include the code necessary to conditionally modify the values for each attribute / property needed.

 

As for the horse, what may be true by lamplight is not always true in sunlight but i have to say you got good diplomatic skills.:)

 

"There are two ways of spreading light; to be the candle, or the mirror that reflects it" - Edith Wharton

 

Besides, lamp / flash / chem / cigarette light violates 'light discipline' during night operations; and day or night, if it breathes, there's a scope that can see it:

 

495417276_kxytT-S.jpg

 

(^^ Rifle with day / night vision scope ^^)

 

:airborne:

Link to comment
Share on other sites

I, too, prefer a block library setup based on a WBLOCK methodology (i.e., one block per drawing) due to the ease of automation. If the “master file” method needed to be preserved, though, this thread shows an additional programming option regarding the transfer of a Block Definitions to a working drawing.

 

Inserting the actual reference may require further enhancements to account for dynamic manipulation and/or attributes.

http://www.cadtutor.net/forum/showthread.php?26666

Link to comment
Share on other sites

I, too, prefer a block library setup based on a WBLOCK methodology (i.e., one block per drawing) due to the ease of automation. If the “master file” method needed to be preserved, though, this thread shows an additional programming option regarding the transfer of a Block Definitions to a working drawing.

 

Inserting the actual reference may require further enhancements to account for dynamic manipulation and/or attributes.

http://www.cadtutor.net/forum/showthread.php?26666

The "master file" indeed, very good word to describe the method.

This is what i had in mind when i first posted this thread. Thank you for this reply. I tried it and it worked for me too.

 

As for the wblock method, i studied it today again and noticed the difference. I initialy saw the new dwg( created with wblock) and said to myself, "why would i need another dwg, i already have one?!" But today I tried it again (insertblock a file created with wblock) and i worked, it inserted only the block with it's reference as you said in the first replyes. Obvious it did otherwise you would't use it :)

 

Initialy i wanted to close the thread, and use my firstly nonprofessional method. It worked for my purpose.

But the i thought i should try harder to get it the way it should be, and i succesfully ended up with two methods, thanks to you guys.

 

So many thanks are in order, to all of you guys.

I feel a little smarter now :P

Link to comment
Share on other sites

Inserting the actual reference may require further enhancements to account for dynamic manipulation and/or attributes.

http://www.cadtutor.net/forum/showthread.php?26666

 

Seant, you beat me to it!

 

I was going to post back today, that if the OP 'insisted' on using a nested block (a block within another drawing, i.e. a master file) that the CopyBlocks Method be used, and the thread you linked already has the code written.

 

Cheers! :beer:

 

As for the wblock method, i studied it today again and noticed the difference.

 

Glad you were able to get the help you needed.

Link to comment
Share on other sites

I suspect a lot of customization deals with existing conditions that are less than ideal. It sounds like you, BUrBaKy, have some flexibility with regard to how you proceed. Exploring all the options, and finding out about the inherent pitfalls, makes sense.

The OP in the thread I referenced implied that there were assets already in place that favored a certain approach. A rather bold decision would be required to strike out on a different course.

Link to comment
Share on other sites

Indeed, in the thread you referenced that guy already had the "master file" so the discussed technique was the best for him. As for my case, i'm trying to build something from scratch so any alternative to a given method is more than welcome. I can balance the advantages/disadvantages.

I splitted my end result in more "areas of interest" and i'm tying each one independently.This thread represented one of them.

After i will make every one of them work, i will combine them all to get what i want. Hopefully :)

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
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.

 Share

×
×
  • Create New...