×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Use VBA to insert dwg file as block?

Use VBA to insert dwg file as block?

Use VBA to insert dwg file as block?

(OP)
I have used VBA to insert a previously defined block in a drawing, and even create block definitions.
Can VBA also be used to insert another dwg file as a block? What is the code? I have tried simply adding the file path info to the insert block code, but with no success.

Thanks to all who respond :)

RE: Use VBA to insert dwg file as block?

The operative part of your code for this purpose would be as under.

CODE

Sub InsDwg()
  Dim BlockRef As AcadBlockReference
  Dim insertionPnt(0 To 2) As Double
  insertionPnt(0) = 0#: insertionPnt(1) = 0#: insertionPnt(2) = 0#
  FileToInsert = "C:\Documents and Settings\Mala Singh\Desktop\Test.dwg"
  Set BlockRef = ThisDrawing.ModelSpace.InsertBlock(insertionPnt, FileToInsert, 1#, 1#, 1#, 0)
End Sub

The 1,1,1,0 you see in the arguments list are x- y- z- scaling factors and rotation angle respectively


Mala Singh
'Dare to Imagine'

RE: Use VBA to insert dwg file as block?

Mala
I hope you dont mind me asking. I have a very interesting
project that I just got pushed into and could use a little
help.

I need to launch Autocad R14 from the Web, have it
load a drawing insert a block of text into the drawing
then close with out anyone knowing that it happened.

All the code that I have written for Autocad depends on
user interaction...
Is there a way I could force code to run as soon as Autocad
opens?

Thank you
William O'Malley

RE: Use VBA to insert dwg file as block?


WillOMalley:

I would definitely help if I could...

Unfortunately, I do not have any experience of launching apps from the web. Also, I do not know of the extent to which AutoCad R14 supports VBA (if at all). I am familiar with versions 2000 and 2004.

However, I'll try to find a way to auto-run a piece of code on launching of ACad on a desktop - if I succeed, you  might try to adapt that to your work.


Mala Singh
'Dare to Imagine'

RE: Use VBA to insert dwg file as block?

(OP)
Mala,

Thanks for the reply, you're a life saver.

- Brent Lim

RE: Use VBA to insert dwg file as block?

Glad to be of help...
FYI: The forum also provides you with another means of expressing appreciation (less transparent but no less meaningful)...you might like to find this out.


Mala Singh
'Dare to Imagine'

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources