home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / turbocad / v8trial / TurboCADv8ProfessionalNoReg.exe / Data.Cab / F40630_modBlocks.bas < prev    next >
Encoding:
BASIC Source File  |  2001-10-16  |  2.5 KB  |  81 lines

  1. Attribute VB_Name = "modBlocks"
  2. '******************************************************************'
  3. '*                                                                *'
  4. '*                      TurboCAD for Windows                      *'
  5. '*                   Copyright (c) 1993 - 2001                    *'
  6. '*             International Microcomputer Software, Inc.         *'
  7. '*                            (IMSI)                              *'
  8. '*                      All rights reserved.                      *'
  9. '*                                                                *'
  10. '******************************************************************'
  11.  
  12. Option Explicit
  13.  
  14. Public Function GroupFromSelection() As Graphic
  15.     On Error GoTo GroupError
  16.     Dim grGroup As Graphic
  17.     Dim gr As Graphic
  18.     Dim i As Integer
  19.     Dim count As Integer
  20.     Dim ids() As Long
  21.     
  22.     count = ActiveDrawing.Selection.count
  23.     If count = 0 Then
  24.         MsgBox "No graphics selected"
  25.         GoTo GroupError
  26.     End If
  27.     
  28.     ReDim ids(0 To count - 1)
  29.     
  30.     'First make a group container
  31.     Set grGroup = ActiveDrawing.Graphics.Add
  32.     'Then add in the selected objects
  33.     'This is made difficult because you the Selection object is not mutable
  34.     'So we need to save the Graphic ID's in an array
  35.     i = 0
  36.     For Each gr In ActiveDrawing.Selection
  37.         ids(i) = gr.ID
  38.         i = i + 1
  39.     Next
  40.     'Not implemented!
  41.     'ActiveDrawing.UnselectAll
  42.     
  43.     'Now recapture the ids and add the graphics to the group
  44.     For i = 0 To count - 1
  45.         Set gr = ActiveDrawing.Graphics.GraphicFromID(ids(i))
  46.         
  47.         'Selected no more
  48.         gr.Unselect
  49.         
  50.         'Internal DBAPI Failure if you don't remove the graphic first
  51.         ActiveDrawing.Graphics.Remove gr.Index
  52.         grGroup.Graphics.AddGraphic gr
  53.     Next
  54.     Set GroupFromSelection = grGroup
  55.     Exit Function
  56.     
  57. GroupError:
  58.     Set GroupFromSelection = Nothing
  59. End Function
  60.  
  61. Public Sub MakeBlockFromSelection()
  62.     On Error GoTo BlockError
  63.     Dim grGroup As Graphic
  64.     Dim grInsert As Graphic
  65.     
  66.     Set grGroup = GroupFromSelection
  67.     
  68.     'Now make the block
  69.     ActiveDrawing.Blocks.Add "Test", grGroup
  70.     Set grGroup = Nothing
  71.     
  72.     'And do an insertion to see what we get
  73.     Set grInsert = ActiveDrawing.Graphics.AddBlockInsertion("Test", 1, 1, 1)
  74.     
  75.     Exit Sub
  76.     
  77. BlockError:
  78.     MsgBox "Error: " & Err.Description
  79.     
  80. End Sub
  81.