Jump to content

Inserting blocks with VBA


dbroada

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

not usually in VBA

 

 

hey that worked! Lets try again.

 

########

 

inconsistant or what?

 

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 4 weeks later...

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?

Link to comment
Share on other sites

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.

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