home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 November / pcwk_11_98a.iso / Wtestowe / SOFTSRC / vtrial15.exe / DATA.1 / MainForm.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-14  |  9.4 KB  |  279 lines

  1. VERSION 4.00
  2. Begin VB.Form MainForm 
  3.    Caption         =   "Blocks/Attributes"
  4.    ClientHeight    =   3615
  5.    ClientLeft      =   555
  6.    ClientTop       =   1455
  7.    ClientWidth     =   6000
  8.    Height          =   4020
  9.    Icon            =   "MainForm.frx":0000
  10.    Left            =   495
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   241
  13.    ScaleMode       =   3  'Pixel
  14.    ScaleWidth      =   400
  15.    Top             =   1110
  16.    Width           =   6120
  17.    Begin VB.CommandButton ZoomButton 
  18.       Caption         =   "&Zoom to Insert"
  19.       Enabled         =   0   'False
  20.       Height          =   375
  21.       Left            =   4320
  22.       TabIndex        =   9
  23.       Top             =   3120
  24.       Width           =   1455
  25.    End
  26.    Begin VB.CommandButton EditButton 
  27.       Caption         =   "&Edit Attributes"
  28.       Enabled         =   0   'False
  29.       Height          =   375
  30.       Left            =   2520
  31.       TabIndex        =   8
  32.       Top             =   3120
  33.       Width           =   1695
  34.    End
  35.    Begin VB.CommandButton OutputButton 
  36.       Caption         =   "&Output..."
  37.       Enabled         =   0   'False
  38.       Height          =   375
  39.       Left            =   4320
  40.       TabIndex        =   6
  41.       Top             =   960
  42.       Width           =   1455
  43.    End
  44.    Begin VB.ListBox AttribList 
  45.       Height          =   1590
  46.       Left            =   2520
  47.       TabIndex        =   5
  48.       Top             =   1440
  49.       Width           =   3255
  50.    End
  51.    Begin VB.CommandButton GetAttribs 
  52.       Caption         =   "Get &Attributes"
  53.       Enabled         =   0   'False
  54.       Height          =   375
  55.       Left            =   2520
  56.       TabIndex        =   4
  57.       Top             =   960
  58.       Width           =   1695
  59.    End
  60.    Begin VB.CommandButton SelectAll 
  61.       Caption         =   "&Select All Inserts of Block"
  62.       Enabled         =   0   'False
  63.       Height          =   375
  64.       Left            =   240
  65.       TabIndex        =   3
  66.       Top             =   960
  67.       Width           =   2055
  68.    End
  69.    Begin VB.ListBox BlockList 
  70.       Height          =   1590
  71.       Left            =   240
  72.       Sorted          =   -1  'True
  73.       TabIndex        =   2
  74.       Top             =   1440
  75.       Width           =   2055
  76.    End
  77.    Begin VB.CommandButton GetBlocks 
  78.       Caption         =   "&Get Blocks in Current Drawing"
  79.       Height          =   375
  80.       Left            =   1800
  81.       TabIndex        =   0
  82.       Top             =   120
  83.       Width           =   2415
  84.    End
  85.    Begin MSComDlg.CommonDialog CommonDialog 
  86.       Left            =   5400
  87.       Top             =   120
  88.       _Version        =   65536
  89.       _ExtentX        =   847
  90.       _ExtentY        =   847
  91.       _StockProps     =   0
  92.    End
  93.    Begin VB.Label NumberLabel 
  94.       Height          =   255
  95.       Left            =   240
  96.       TabIndex        =   7
  97.       Top             =   3120
  98.       Width           =   2175
  99.    End
  100.    Begin VB.Label DrawingName 
  101.       Alignment       =   2  'Center
  102.       Caption         =   "<none>"
  103.       Height          =   255
  104.       Left            =   240
  105.       TabIndex        =   1
  106.       Top             =   600
  107.       Width           =   5535
  108.    End
  109. Attribute VB_Name = "MainForm"
  110. Attribute VB_Creatable = False
  111. Attribute VB_Exposed = False
  112. ' (C) Copyright 1997 by SoftSource.  All rights reserved.
  113. ' Sample Visual Basic code for working with Vdraft
  114. ' This code demonstrates getting block and attribute
  115. '   information out of a drawing
  116. ' the object we use to talk to Vdraft
  117. Dim vdraft As Object
  118. ' the drawing we're using
  119. Dim drawing As Object
  120. Private Sub AttribList_Click()
  121.     EditButton.Enabled = True
  122.     ZoomButton.Enabled = True
  123. End Sub
  124. Private Sub BlockList_Click()
  125.     Dim block As Object
  126.     ' tell the user how many inserts of selected block there are
  127.     blockname$ = BlockList.List(BlockList.ListIndex)
  128.     Set block = drawing.blocks.Item(blockname$)
  129.     insertcount% = block.inserts.Count
  130.     NumberLabel.Caption = Str$(insertcount%) + " inserts of block in drawing"
  131.     ' once they select a block, the buttons will do something
  132.     SelectAll.Enabled = True
  133.     GetAttribs.Enabled = block.HasAttributes
  134.     OutputButton.Enabled = False
  135.     AttribList.Clear
  136.     EditButton.Enabled = False
  137.     ZoomButton.Enabled = False
  138. End Sub
  139. Private Sub EditButton_Click()
  140.     Dim inserts As Object
  141.     ' find the selected insert
  142.     blockname$ = BlockList.List(BlockList.ListIndex)
  143.     Set inserts = drawing.blocks.Item(blockname$).inserts
  144.     ' display properties for selected insert
  145.     inserts(AttribList.ListIndex + 1).Dialog
  146. End Sub
  147. Private Sub Form_Load()
  148.     WindowOnTop hWnd
  149. End Sub
  150. Private Sub GetAttribs_Click()
  151.     Dim inserts, attribs As Object
  152.     MainForm.MousePointer = 11    ' hourglass
  153.     AttribList.Clear
  154.     EditButton.Enabled = False
  155.     ZoomButton.Enabled = False
  156.     ' get associated list of inserts from Vdraft
  157.     blockname$ = BlockList.List(BlockList.ListIndex)
  158.     Set inserts = drawing.blocks.Item(blockname$).inserts
  159.     If inserts.Count = 0 Then
  160.         Exit Sub
  161.     End If
  162.     ' build up attribute list
  163.     attribcount% = inserts(1).Attributes.Count
  164.     For i% = 1 To inserts.Count
  165.         Set attribs = inserts(i%).Attributes
  166.         output$ = attribs(1).Text
  167.         For j% = 2 To attribcount%
  168.             output$ = output$ + ", " + attribs(j%).Text
  169.         Next j%
  170.         AttribList.AddItem output$
  171.     Next i%
  172.     ' once they have attributes, they can be output
  173.     OutputButton.Enabled = True
  174.     MainForm.MousePointer = 1    ' default
  175. End Sub
  176. Private Sub GetBlocks_Click()
  177.     Dim blocks, block As Object
  178.     MainForm.MousePointer = 11    ' hourglass
  179.     BlockList.Clear
  180.     ' make sure we're talking to Vdraft
  181.     If vdraft Is Nothing Then
  182.         Set vdraft = CreateObject("Vdraft.Application")
  183.     End If
  184.     If vdraft.Documents.Count = 0 Then
  185.         MainForm.MousePointer = 1    ' default
  186.         Exit Sub
  187.     End If
  188.     ' get current drawing & display its name
  189.     Set drawing = vdraft.ActiveDocument
  190.     DrawingName.Caption = drawing.FullName
  191.     ' list all the blocks in the drawing
  192.     Set blocks = drawing.blocks
  193.     blockcount% = blocks.Count
  194.     For i% = 1 To blockcount%
  195.         Set block = blocks(i%)
  196.         ' don't list dimensions or hatches
  197.         If Not block.IsAnonymous Then
  198.             BlockList.AddItem blocks(i%)
  199.         End If
  200.     Next i%
  201.     MainForm.MousePointer = 1    ' default
  202. End Sub
  203. Private Sub OutputButton_Click()
  204.     Dim inserts, attribs As Object
  205.     MainForm.MousePointer = 11    ' hourglass
  206.     ' get associated list of inserts from Vdraft
  207.     blockname$ = BlockList.List(BlockList.ListIndex)
  208.     Set inserts = drawing.blocks.Item(blockname$).inserts
  209.     ' ask the user for a file name
  210.     On Error GoTo Abort
  211.     CommonDialog.Filter = "Attributes (*.att)"
  212.     CommonDialog.CancelError = True
  213.     CommonDialog.ShowSave
  214.     ' the following line should check if the user cancelled
  215.     If Len(CommonDialog.filename) = 0 Then
  216.         MainForm.MousePointer = 1    ' default
  217.         Exit Sub
  218.     End If
  219.     ' build up attribute list
  220.     Open CommonDialog.filename For Output As #1
  221.     attribcount% = inserts(1).Attributes.Count
  222.     For i% = 1 To inserts.Count
  223.         Set attribs = inserts(i%).Attributes
  224.         output$ = attribs(1).Text
  225.         For j% = 2 To attribcount%
  226.             output$ = output$ + ", " + attribs(j%).Text
  227.         Next j%
  228.         Print #1, output$
  229.     Next i%
  230.     Close #1
  231. Abort:
  232.     MainForm.MousePointer = 1    ' default
  233. End Sub
  234. Private Sub SelectAll_Click()
  235.     Dim block, inserts, selection As Object
  236.     MainForm.MousePointer = 11    ' hourglass
  237.     ' get associated list of inserts from Vdraft
  238.     blockname$ = BlockList.List(BlockList.ListIndex)
  239.     Set block = drawing.blocks.Item(blockname$)
  240.     Set inserts = block.inserts
  241.     ' group all selections under one command
  242.     Set Commands = drawing.Commands
  243.     Commands.Group "select.inserts " + blockname$
  244.     ' select all the inserts
  245.     Set selection = drawing.selection
  246.     For i% = 1 To inserts.Count
  247.         selection.Add inserts(i%)
  248.     Next i%
  249.     MainForm.MousePointer = 1    ' default
  250. End Sub
  251. Private Sub ZoomButton_Click()
  252.     Dim block, insert As Object
  253.     Dim offset, corner1, corner2 As Object
  254.     Dim center, view As Object
  255.     ' find the selected block
  256.     blockname$ = BlockList.List(BlockList.ListIndex)
  257.     Set block = drawing.blocks.Item(blockname$)
  258.     Set insert = block.inserts.Item(AttribList.ListIndex + 1)
  259.     ' start out with the extents of the block
  260.     Set corner1 = block.ExtentsMin
  261.     Set corner2 = block.ExtentsMax
  262.     ' adjust the insert point by the block's basepoint
  263.     ' so we know how much to offset the block extents by
  264.     Set offset = block.Where
  265.     offset.Detach   ' we want to change the vector but not the basepoint
  266.     offset.SubtractAway insert.Where
  267.     corner1.SubtractAway offset
  268.     corner2.SubtractAway offset
  269.     ' find the center & height/width of insert area
  270.     w# = corner2.x - corner1.x
  271.     h# = corner2.y - corner1.y
  272.     Set center = vdraft.NewVector(corner1.x + w# / 2, corner1.y + h# / 2)
  273.     ' change the current view so it just shows the insert
  274.     Set view = drawing.Views.ActiveView
  275.     view.center center
  276.     view.Width = 2 * w#
  277.     view.Height = 2 * h#
  278. End Sub
  279.