Jump to content

BLOCK INSERT USING VBA


smuthuc

Recommended Posts

NOT WORKING MY VBA CODE

 

Public Sub index_test()

 

Dim strPath As String
Dim strBlockName As String
strBlockName = "INDEX"
strPath = "E:\Soft\Template\INDEX.dwg"

'On Error Resume Next
DbxCopyBlock strBlockName, strPath

strBlockName = "BSC1"
DbxCopyBlock strBlockName, strPath

Dim Pt1 As Variant

Pt1 = ThisDrawing.Utility.GetPoint(, "Pick the Index Table Corner:")

Dim BlkNme As AcadBlock
Dim BlkRef As AcadBlockReference

Set BlkRef = ThisDrawing.ModelSpace.InsertBlock(Pt1, strBlockName, 1, 1, 1, 0)


End Sub

 

';;;;;

 

Sub DbxCopyBlock(strBlockName As String, strPath As String)

Dim strFullDef As String
Dim objBlock As AcadBlock
Dim colBlocks As AcadBlocks
Dim objArray(0) As Object
Dim ACDbx As Object
   Set ACDbx = GetAcDbxDoc()
   ACDbx.Open strPath
   Set colBlocks = ACDbx.Blocks
   Set objBlock = colBlocks.Item(strBlockName) 'Find appropriate block in container file's Blocks Collection
   Set objArray(0) = objBlock 'Create object array as required by the CopyObjects Method
   ACDbx.CopyObjects objArray, ThisDrawing.Blocks 'Copy to current drawing's Blocks Collection
   Set ACDbx = Nothing
   
End Sub

';;;;;

 

Function GetAcDbxDoc() As Object

Dim strAcadVersion As String
With ThisDrawing.Application
   strAcadVersion = Mid(.Version, 1, 2)
   If CInt(strAcadVersion) < 16 Then
       Set GetAcDbxDoc = .GetInterfaceObject("ObjectDBX.AxDbDocument")
   Else
       Set GetAcDbxDoc = .GetInterfaceObject("ObjectDBX.AxDbDocument." & strAcadVersion)
   End If
End With

End Function

 

PLEASE RECTIFY ANYBODY

 

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...