VB (stand alone app): Copy blocks between drawings

VB (stand alone app): Copy blocks between drawings

Anonymous
Not applicable
532 Views
4 Replies
Message 1 of 5

VB (stand alone app): Copy blocks between drawings

Anonymous
Not applicable
Does anyone have a sample of code that copies a block from one drawing to another drawing in VB 6.0. I've got a sample that does it with VBA, but I haven't had any luck with code for a stand alone VB app.
0 Likes
533 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
"wtso" wrote in message
news:f1402b0.-1@WebX.maYIadrTaRb...

> I've got a sample that does it with VBA, but I haven't had any
> luck with code for a stand alone VB app.

You'll have to tweak the code to manually connet to AutoCAD and the
drawings in question but other than that, the code should work as is.
Can you post it?

--
Someone left the grass out in the yard all night.
http://www.acadx.com
0 Likes
Message 3 of 5

Anonymous
Not applicable
Okay, here's the VBA code:

Public Function DwgToDwg(objTarget As AcadDocument) As Variant
Dim objSelSet As AcadSelectionSet
Dim objOrgEnts() As Object
Dim destEnts As Variant
Dim intCnt As Long
On Error GoTo Error_Control
Set objSelSet = ThisDrawing.SelectionSets.Add("copyobjs")
objSelSet.SelectOnScreen
'Now reset the size of the array to the selection sets
'count minus one (arrays are zero-based)
ReDim objOrgEnts(objSelSet.Count - 1)
'Add each of the selected objects into the array
For intCnt = 0 To objSelSet.Count - 1
Set objOrgEnts(intCnt) = objSelSet(intCnt)
Next
'Copy all of the objects into the target drawings' model space.
DwgToDwg = ThisDrawing.CopyObjects(objOrgEnts, objTarget.ModelSpace)
Exit_Here:
objSelSet.Delete
Exit Function
Error_Control:
MsgBox Err.Description, vbOKOnly, Err.Number
End Function

Public Sub TestCopy()
Dim varObjs As Variant
Dim intCnt As Integer
On Error GoTo Err_Control
'Make sure that the index of the target drawing is correct for your project!
varObjs = DwgToDwg(Application.Documents(1))
Application.ActiveDocument = Application.Documents(1)
For intCnt = LBound(varObjs) To UBound(varObjs)
'Ghost the new objects.
varObjs(intCnt).Highlight True
Next intCnt
Exit_Here:
Exit Sub
Err_Control:
MsgBox Err.Description
End Sub


Some of the things I'm missing are how to start AutoCad up from VB, how to load drawings in VB (into AutoCad), and the syntax used to refer to the different drawings in VB.
0 Likes
Message 4 of 5

Anonymous
Not applicable
See if this is better . . . *sigh*

Public Function DwgToDwg(objTarget As AcadDocument) As Variant
Dim objSelSet As AcadSelectionSet
Dim objOrgEnts() As Object
Dim destEnts As Variant
Dim intCnt As Long
On Error GoTo Error_Control
Set objSelSet = ThisDrawing.SelectionSets.Add("copyobjs")
objSelSet.SelectOnScreen
'Now reset the size of the array to the selection sets
'count minus one (arrays are zero-based)
ReDim objOrgEnts(objSelSet.Count - 1)
'Add each of the selected objects into the array
For intCnt = 0 To objSelSet.Count - 1
Set objOrgEnts(intCnt) = objSelSet(intCnt)
Next
'Copy all of the objects into the target drawings' model space.
DwgToDwg = ThisDrawing.CopyObjects(objOrgEnts, objTarget.ModelSpace)
Exit_Here:
objSelSet.Delete
Exit Function
Error_Control:
MsgBox Err.Description, vbOKOnly, Err.Number
End Function

Public Sub TestCopy()
Dim varObjs As Variant
Dim intCnt As Integer
On Error GoTo Err_Control
'Make sure that the index of the target drawing is correct for your

project!
varObjs = DwgToDwg(Application.Documents(1))
Application.ActiveDocument = Application.Documents(1)
For intCnt = LBound(varObjs) To UBound(varObjs)
'Ghost the new objects.
varObjs(intCnt).Highlight True
Next intCnt
Exit_Here:
Exit Sub
Err_Control:
MsgBox Err.Description
End Sub
0 Likes
Message 5 of 5

Anonymous
Not applicable
Or this???
0 Likes