Search Tools Links Login

Insert Template in AutoCAD


Visual Basic 6, or VB Classic

SrA John Spence asked for some examples for VBA with AutoCAD, so here is the first.
This is an example for creating a new drawing in AutoCAD and inserting a template. This is coded for VBA but is easily ported to VB 6. I can show that also if someone wants it.

Original Author: Troy Gates

Assumptions

Must have AutoCAD
This needs to be in its own module or form and not ThisDrawing. Easiest is to add a new form and a button and put it in the button click event.

Code

Dim acadApp As AcadApplication 'reference to the AutoCAD application
  Dim acadDocs As AcadDocuments  'reference to the AutoCAD Documents collection
  Dim acadDoc As AcadDocument  'reference to a Document in the Collection
  Dim acadBlock As AcadBlockReference 'Block reference
  Dim strTemplate As String  'path to template file
  Dim dblInsertPt(2) As Double  'array with insert points (X,Y,Z)
  
  strTemplate = "S:D+AcadD+TemplatesAPF-Floor Plan.dwt" 'change to the path of the template you want
    
  Set acadApp = ThisDrawing.Application  'connect to AutoCAD application
  Set acadDocs = acadApp.Documents  'get the Documents collection
  Set acadDoc = acadDocs.Add 'create an empty document
  
  'set the inseration points to 0,0,0
  dblInsertPt(0) = 0# 'X
  dblInsertPt(1) = 0# 'Y
  dblInsertPt(2) = 0# 'Z
  
  'Insert the template with no XYZ scale and no rotation
  Set acadBlock = acadDoc.ModelSpace.InsertBlock(dblInsertPt, strTemplate, 1, 1, 1, 0)
  acadBlock.Explode  'explode the template
  acadApp.ZoomExtents 'zoom to the extents
  
  'clear objects from memory
  Set acadBlock = Nothing
  Set acadDoc = Nothing
  Set acadDocs = Nothing
  Set acadApp = Nothing

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 123 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.