Advertisement
7_2009-2012 Microsoft Office Apps/VBA #226937

Insert Template in AutoCAD

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.

AI

สรุปโดย AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

ซอร์สโค้ด
original-source
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+Acad\D+Templates\APF-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
ความคิดเห็นดั้งเดิม (3)
กู้คืนจาก Wayback Machine