home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form MainForm
- Caption = "Blocks/Attributes"
- ClientHeight = 3615
- ClientLeft = 555
- ClientTop = 1455
- ClientWidth = 6000
- Height = 4020
- Icon = "MainForm.frx":0000
- Left = 495
- LinkTopic = "Form1"
- ScaleHeight = 241
- ScaleMode = 3 'Pixel
- ScaleWidth = 400
- Top = 1110
- Width = 6120
- Begin VB.CommandButton ZoomButton
- Caption = "&Zoom to Insert"
- Enabled = 0 'False
- Height = 375
- Left = 4320
- TabIndex = 9
- Top = 3120
- Width = 1455
- End
- Begin VB.CommandButton EditButton
- Caption = "&Edit Attributes"
- Enabled = 0 'False
- Height = 375
- Left = 2520
- TabIndex = 8
- Top = 3120
- Width = 1695
- End
- Begin VB.CommandButton OutputButton
- Caption = "&Output..."
- Enabled = 0 'False
- Height = 375
- Left = 4320
- TabIndex = 6
- Top = 960
- Width = 1455
- End
- Begin VB.ListBox AttribList
- Height = 1590
- Left = 2520
- TabIndex = 5
- Top = 1440
- Width = 3255
- End
- Begin VB.CommandButton GetAttribs
- Caption = "Get &Attributes"
- Enabled = 0 'False
- Height = 375
- Left = 2520
- TabIndex = 4
- Top = 960
- Width = 1695
- End
- Begin VB.CommandButton SelectAll
- Caption = "&Select All Inserts of Block"
- Enabled = 0 'False
- Height = 375
- Left = 240
- TabIndex = 3
- Top = 960
- Width = 2055
- End
- Begin VB.ListBox BlockList
- Height = 1590
- Left = 240
- Sorted = -1 'True
- TabIndex = 2
- Top = 1440
- Width = 2055
- End
- Begin VB.CommandButton GetBlocks
- Caption = "&Get Blocks in Current Drawing"
- Height = 375
- Left = 1800
- TabIndex = 0
- Top = 120
- Width = 2415
- End
- Begin MSComDlg.CommonDialog CommonDialog
- Left = 5400
- Top = 120
- _Version = 65536
- _ExtentX = 847
- _ExtentY = 847
- _StockProps = 0
- End
- Begin VB.Label NumberLabel
- Height = 255
- Left = 240
- TabIndex = 7
- Top = 3120
- Width = 2175
- End
- Begin VB.Label DrawingName
- Alignment = 2 'Center
- Caption = "<none>"
- Height = 255
- Left = 240
- TabIndex = 1
- Top = 600
- Width = 5535
- End
- Attribute VB_Name = "MainForm"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- ' (C) Copyright 1997 by SoftSource. All rights reserved.
- ' Sample Visual Basic code for working with Vdraft
- ' This code demonstrates getting block and attribute
- ' information out of a drawing
- ' the object we use to talk to Vdraft
- Dim vdraft As Object
- ' the drawing we're using
- Dim drawing As Object
- Private Sub AttribList_Click()
- EditButton.Enabled = True
- ZoomButton.Enabled = True
- End Sub
- Private Sub BlockList_Click()
- Dim block As Object
- ' tell the user how many inserts of selected block there are
- blockname$ = BlockList.List(BlockList.ListIndex)
- Set block = drawing.blocks.Item(blockname$)
- insertcount% = block.inserts.Count
- NumberLabel.Caption = Str$(insertcount%) + " inserts of block in drawing"
- ' once they select a block, the buttons will do something
- SelectAll.Enabled = True
- GetAttribs.Enabled = block.HasAttributes
- OutputButton.Enabled = False
- AttribList.Clear
- EditButton.Enabled = False
- ZoomButton.Enabled = False
- End Sub
- Private Sub EditButton_Click()
- Dim inserts As Object
- ' find the selected insert
- blockname$ = BlockList.List(BlockList.ListIndex)
- Set inserts = drawing.blocks.Item(blockname$).inserts
- ' display properties for selected insert
- inserts(AttribList.ListIndex + 1).Dialog
- End Sub
- Private Sub Form_Load()
- WindowOnTop hWnd
- End Sub
- Private Sub GetAttribs_Click()
- Dim inserts, attribs As Object
- MainForm.MousePointer = 11 ' hourglass
- AttribList.Clear
- EditButton.Enabled = False
- ZoomButton.Enabled = False
- ' get associated list of inserts from Vdraft
- blockname$ = BlockList.List(BlockList.ListIndex)
- Set inserts = drawing.blocks.Item(blockname$).inserts
- If inserts.Count = 0 Then
- Exit Sub
- End If
- ' build up attribute list
- attribcount% = inserts(1).Attributes.Count
- For i% = 1 To inserts.Count
- Set attribs = inserts(i%).Attributes
- output$ = attribs(1).Text
- For j% = 2 To attribcount%
- output$ = output$ + ", " + attribs(j%).Text
- Next j%
- AttribList.AddItem output$
- Next i%
- ' once they have attributes, they can be output
- OutputButton.Enabled = True
- MainForm.MousePointer = 1 ' default
- End Sub
- Private Sub GetBlocks_Click()
- Dim blocks, block As Object
- MainForm.MousePointer = 11 ' hourglass
- BlockList.Clear
- ' make sure we're talking to Vdraft
- If vdraft Is Nothing Then
- Set vdraft = CreateObject("Vdraft.Application")
- End If
- If vdraft.Documents.Count = 0 Then
- MainForm.MousePointer = 1 ' default
- Exit Sub
- End If
- ' get current drawing & display its name
- Set drawing = vdraft.ActiveDocument
- DrawingName.Caption = drawing.FullName
- ' list all the blocks in the drawing
- Set blocks = drawing.blocks
- blockcount% = blocks.Count
- For i% = 1 To blockcount%
- Set block = blocks(i%)
- ' don't list dimensions or hatches
- If Not block.IsAnonymous Then
- BlockList.AddItem blocks(i%)
- End If
- Next i%
- MainForm.MousePointer = 1 ' default
- End Sub
- Private Sub OutputButton_Click()
- Dim inserts, attribs As Object
- MainForm.MousePointer = 11 ' hourglass
- ' get associated list of inserts from Vdraft
- blockname$ = BlockList.List(BlockList.ListIndex)
- Set inserts = drawing.blocks.Item(blockname$).inserts
- ' ask the user for a file name
- On Error GoTo Abort
- CommonDialog.Filter = "Attributes (*.att)"
- CommonDialog.CancelError = True
- CommonDialog.ShowSave
- ' the following line should check if the user cancelled
- If Len(CommonDialog.filename) = 0 Then
- MainForm.MousePointer = 1 ' default
- Exit Sub
- End If
- ' build up attribute list
- Open CommonDialog.filename For Output As #1
- attribcount% = inserts(1).Attributes.Count
- For i% = 1 To inserts.Count
- Set attribs = inserts(i%).Attributes
- output$ = attribs(1).Text
- For j% = 2 To attribcount%
- output$ = output$ + ", " + attribs(j%).Text
- Next j%
- Print #1, output$
- Next i%
- Close #1
- Abort:
- MainForm.MousePointer = 1 ' default
- End Sub
- Private Sub SelectAll_Click()
- Dim block, inserts, selection As Object
- MainForm.MousePointer = 11 ' hourglass
- ' get associated list of inserts from Vdraft
- blockname$ = BlockList.List(BlockList.ListIndex)
- Set block = drawing.blocks.Item(blockname$)
- Set inserts = block.inserts
- ' group all selections under one command
- Set Commands = drawing.Commands
- Commands.Group "select.inserts " + blockname$
- ' select all the inserts
- Set selection = drawing.selection
- For i% = 1 To inserts.Count
- selection.Add inserts(i%)
- Next i%
- MainForm.MousePointer = 1 ' default
- End Sub
- Private Sub ZoomButton_Click()
- Dim block, insert As Object
- Dim offset, corner1, corner2 As Object
- Dim center, view As Object
- ' find the selected block
- blockname$ = BlockList.List(BlockList.ListIndex)
- Set block = drawing.blocks.Item(blockname$)
- Set insert = block.inserts.Item(AttribList.ListIndex + 1)
- ' start out with the extents of the block
- Set corner1 = block.ExtentsMin
- Set corner2 = block.ExtentsMax
- ' adjust the insert point by the block's basepoint
- ' so we know how much to offset the block extents by
- Set offset = block.Where
- offset.Detach ' we want to change the vector but not the basepoint
- offset.SubtractAway insert.Where
- corner1.SubtractAway offset
- corner2.SubtractAway offset
- ' find the center & height/width of insert area
- w# = corner2.x - corner1.x
- h# = corner2.y - corner1.y
- Set center = vdraft.NewVector(corner1.x + w# / 2, corner1.y + h# / 2)
- ' change the current view so it just shows the insert
- Set view = drawing.Views.ActiveView
- view.center center
- view.Width = 2 * w#
- view.Height = 2 * h#
- End Sub
-