VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using VB program to insert AutoCAD block

1 REPLY 1
Reply
Message 1 of 2
lgabriel
1547 Views, 1 Reply

Using VB program to insert AutoCAD block

Currently using AutoCAD 2010

 

Inside VB, under references I have selected AutoCAD 2010 Type Library and AutoCAD/ObjectDBX Common 18.0 Library.

 

I created a titleblock insertion program for our projects which has been working fine in AutoCAD 2008

 

Part of code where it crashes:

 

Public Sub InsertBorder(DwgBlock As String)

  Dim Inspt(0 To 2) As Double
  Dim XYZScale As Double
  Dim Rotation As Double
  Dim varAttribute As Variant
   
  Inspt(0) = 0
  Inspt(1) = 0
  Inspt(2) = 0
  XYZScale = 1
  Rotation = 0
  'set border layer to SHEET01
  Set objCurrentLayer = acadDoc.Layers.Add("SHEET01")
  acadDoc.ActiveLayer = objCurrentLayer
  ;code crashes on the next line. In Debug mode, I discovered that the variable Inspt has no value, all other variables are
  Set objBRef = acadDoc.ModelSpace.InsertBlock(Inspt, DwgBlock, XYZScale, XYZScale, XYZScale, Rotation)

 

Any suggestions will be greatly appreciated. I am guessing there is a change with AutoCAD 2010, but hell if I can find it.

1 REPLY 1
Message 2 of 2
wayne.brill
in reply to: lgabriel

Hi,

 

I am not aware of a change to the ActiveX API method InsertBlock() that would explain why the error is occurring. Can you try simplifying your code to narrow down the cause of the error? You could use this VBA example that does something similar to your code. It uses ThisDrawing to instantiate acadDoc variable. (change the path to a dwg on your system)

 

Public Sub wbtest()
    InsertBorder ("c:\temp\wbtest.dwg")
End Sub


Public Sub InsertBorder(DwgBlock As String)

  Dim Inspt(0 To 2) As Double
  Dim XYZScale As Double
  Dim Rotation As Double
  Dim varAttribute As Variant
  
  Inspt(0) = 0
  Inspt(1) = 0
  Inspt(2) = 0
 
  XYZScale = 1
 
  Rotation = 0
 
  Dim acadDoc As AcadDocument
  Set acadDoc = ThisDrawing
 
  'set border layer to SHEET01
  Set objCurrentLayer = acadDoc.Layers.Add("SHEET01")
  acadDoc.ActiveLayer = objCurrentLayer
  ' This is working on my system
  Set objBRef = acadDoc.ModelSpace.InsertBlock(Inspt, DwgBlock, XYZScale, XYZScale, XYZScale, Rotation)

End Sub

 

Thanks,

Wayne Brill



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost