PDA

View Full Version : Inserting blocks with VBA



dbroada
20th Apr 2010, 01:46 pm
How do I add an existing block object into a drawing using VBA?

If the block is already defined in the drawing a simple


Set BlockRefObj = ThisDrawing.ModelSpace.InsertBlock(TriPos, "Tri", CScale, CScale, CScale, 0)
will insert the block I want. However my routine doesn't work if my block is only defined on the network. I can
-INSERT Tri to show that it can be found but my routine just gives me a "File error" message.

I'm guessing I have to add the block into the block collection but I can't find how to add one from a .dwg file.

Any pointers?

Lee Mac
20th Apr 2010, 02:10 pm
When using the InsertBlock method in VL, if the block is not in the support path, you must supply the full path that the block resides at. I would assume this would be the same for VBA.

dbroada
20th Apr 2010, 02:27 pm
That's what I thought too but I get still get a File error with

Set BlockRefObj = ThisDrawing.ModelSpace.InsertBlock(TriPos, "P:\Design_Office\DO_Admin\symbols\miscellaneous\Tr i.DWG", CScale, CScale, CScale, 0)

What is REALLY annoying me is that it used to work without any path but our network has been "rearranged" and it no longer works either with or without the full path being given. GGRRRRRR

Lee Mac
20th Apr 2010, 02:29 pm
Double Backslashes?

dbroada
20th Apr 2010, 02:39 pm
not usually in VBA

<wanders off to test>

hey that worked! Lets try again.

########

inconsistant or what?

Lee Mac
20th Apr 2010, 02:45 pm
not usually in VBA

<wanders off to test>

hey that worked! Lets try again.

########

inconsistant or what?

I thought escape characters were in all languages - but glad you got it working :)

dbroada
20th Apr 2010, 02:46 pm
only working sometimes - REALLY frustrating!

Lee Mac
20th Apr 2010, 03:52 pm
only working sometimes - REALLY frustrating!

You still receive the file error? I'm out of ideas - I can only get that method to fail if the block cannot be found.

dbroada
21st Apr 2010, 10:55 am
I really couldn't get this sorted. I still can't find a way of getting an ,dwg file into my drawing without encountering a file error message.

The routine that was causing the problem inserted a simple attributed issue triangle block so I have created the block from scratch within the routine. At least I now know it is available each time the routine is run. :)

Lt Dan's legs
14th May 2010, 08:09 pm
Is visual basic full of errors? We have a VB program here at my work and I hear people say it doesn't always work right. I just figured it was user error. I'm actually in the middle of a VB book right now.. Would this language be worth my while to learn?

dbroada
14th May 2010, 08:28 pm
FORTRAN is the only language that I have had ANY formal instruction in so I prefer to use BASIC which looks similar. VBA is a sub set of Visual BASIC and is my language of choice as I find it a lot easier than LISP to do quickly (I am an occasional programmer). However, VBA is no longer supported by Microsoft and therefore being phased out by AutoDesk too. VBA isn't quite the same as VB.

VB.Net will be available but I am struggling with that at the moment. I can't find enough tutorials on VB.Net for AutoCAD to get more than frustrated with my progress so far.