Jump to content

Insertblock?


DimitrisKaparelis

Recommended Posts

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

error.png

Edited by DimitrisKaparelis
Link to comment
Share on other sites

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

error.png

 

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...