home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "modBlocks"
- '******************************************************************'
- '* *'
- '* TurboCAD for Windows *'
- '* Copyright (c) 1993 - 2001 *'
- '* International Microcomputer Software, Inc. *'
- '* (IMSI) *'
- '* All rights reserved. *'
- '* *'
- '******************************************************************'
-
- Option Explicit
-
- Public Function GroupFromSelection() As Graphic
- On Error GoTo GroupError
- Dim grGroup As Graphic
- Dim gr As Graphic
- Dim i As Integer
- Dim count As Integer
- Dim ids() As Long
-
- count = ActiveDrawing.Selection.count
- If count = 0 Then
- MsgBox "No graphics selected"
- GoTo GroupError
- End If
-
- ReDim ids(0 To count - 1)
-
- 'First make a group container
- Set grGroup = ActiveDrawing.Graphics.Add
- 'Then add in the selected objects
- 'This is made difficult because you the Selection object is not mutable
- 'So we need to save the Graphic ID's in an array
- i = 0
- For Each gr In ActiveDrawing.Selection
- ids(i) = gr.ID
- i = i + 1
- Next
- 'Not implemented!
- 'ActiveDrawing.UnselectAll
-
- 'Now recapture the ids and add the graphics to the group
- For i = 0 To count - 1
- Set gr = ActiveDrawing.Graphics.GraphicFromID(ids(i))
-
- 'Selected no more
- gr.Unselect
-
- 'Internal DBAPI Failure if you don't remove the graphic first
- ActiveDrawing.Graphics.Remove gr.Index
- grGroup.Graphics.AddGraphic gr
- Next
- Set GroupFromSelection = grGroup
- Exit Function
-
- GroupError:
- Set GroupFromSelection = Nothing
- End Function
-
- Public Sub MakeBlockFromSelection()
- On Error GoTo BlockError
- Dim grGroup As Graphic
- Dim grInsert As Graphic
-
- Set grGroup = GroupFromSelection
-
- 'Now make the block
- ActiveDrawing.Blocks.Add "Test", grGroup
- Set grGroup = Nothing
-
- 'And do an insertion to see what we get
- Set grInsert = ActiveDrawing.Graphics.AddBlockInsertion("Test", 1, 1, 1)
-
- Exit Sub
-
- BlockError:
- MsgBox "Error: " & Err.Description
-
- End Sub
-