DimitrisKaparelis Posted March 22, 2021 Share Posted March 22, 2021 (edited) Dear all, I need your help. I have draw and create a block (I draw it in autocad not with VBA) I want to insert this block using VBA. I use visual basic 2008. The file i use is TEST.dwg The name of the block is ENA. My code is: Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim acad As New AcadApplication acad.Documents.Open("C:\Users\dCap\Desktop\TEST\TEST.dwg") ' The file i use acad.Visible = True End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim a As AcadBlockReference Dim points(2) As Double points(0) = 0 : points(1) = 0 : points(2) = 0 a = cad.ModelSpace.InsertBlock(points, "ENA.dwg", 1.0#, 1.0#, 1.0#, 0, False) acad.Update() End Sub The error i get is in the image. us i told you the name of the block is "ENA" i also try "ENA" and"ENA.dwg" Any help ? Help in advance Edited March 22, 2021 by DimitrisKaparelis Quote Link to comment Share on other sites More sharing options...
PeterPan9720 Posted March 22, 2021 Share Posted March 22, 2021 5 hours ago, DimitrisKaparelis said: Dear all, I need your help. I have draw and create a block (I draw it in autocad not with VBA) I want to insert this block using VBA. I use visual basic 2008. The file i use is TEST.dwg The name of the block is ENA. My code is: Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim acad As New AcadApplication acad.Documents.Open("C:\Users\dCap\Desktop\TEST\TEST.dwg") ' The file i use acad.Visible = True End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim a As AcadBlockReference Dim points(2) As Double points(0) = 0 : points(1) = 0 : points(2) = 0 a = cad.ModelSpace.InsertBlock(points, "ENA.dwg", 1.0#, 1.0#, 1.0#, 0, False) acad.Update() End Sub The error i get is in the image. us i told you the name of the block is "ENA" i also try "ENA" and"ENA.dwg" Any help ? Help in advance Hi, I'm not so expert with Visual Basic, I'm using directly VBA Application directly used with Autocad, not LT version. In any case inside the code a = cad.ModelSpace.InsertBlock(points, "ENA.dwg", 1.0#, 1.0#, 1.0#, 0, False) seems you are using cad instead acad. In addition you already have created the block inside TEST dwg or you are trying to insert a block as dwg ?. Bye Quote Link to comment Share on other sites More sharing options...
DimitrisKaparelis Posted March 23, 2021 Author Share Posted March 23, 2021 I have already create the block ENA in the TEST.dwg Thanks Quote Link to comment Share on other sites More sharing options...
BIGAL Posted March 24, 2021 Share Posted March 24, 2021 cad.Modelspace is not equal to acad.Modelspace as provided by Peterpan Quote Link to comment Share on other sites More sharing options...
DimitrisKaparelis Posted March 24, 2021 Author Share Posted March 24, 2021 Dear, Thanks for your responces. I already use this comand in the beggining of my code Dim acad As New AcadApplication Dim cad As AcadDocument = acad.ActiveDocument Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.