Keith™ 发表于 2008-4-1 14:38:26

不确定我明白你想做什么...你想在列表中选择的布局中进入纸空间吗?如果是这样,当您从列表中选择多个布局时,您会产生问题。
我之前提到过,您可以将标题块过滤到选择集中,并且只对您选择的块进行操作。
如果块存在,此实用程序将返回它,否则它不返回任何内容。在对其进行操作之前,您必须验证块是否确实存在。
Function GetBlockReferenceByLayout(ByVal strBlockName As String, ByVal strLayoutName As String) As AcadBlockReference
'setup variables
Dim BLCollect As AcadSelectionSet
Dim BlkRef As AcadBlockReference
Dim GCode(1) As Integer
Dim GData(1) As Variant
Dim GPCode As Variant
Dim GPData As Variant
'filter for selection set
GCode(0) = 0
GData(0) = "Insert"
GCode(1) = 2
GData(1) = strBlockName
GPCode = GCode
GPData = GData
'create selection set
Set BLCollect = ThisDrawing.SelectionSets.Add("BLOCKREF")
'add items to selection set
BLCollect.Select acSelectionSetAll, , , GPCode, GPData
'loop through all items in selection set
For Each BlkRef In BLCollect
    'compare layout name
    If UCase(ThisDrawing.ObjectIdToObject(BlkRef.OwnerID).layout.Name) = UCase(strLayoutName) Then
      'return the reference
      Set GetBlockReferenceByLayout = BlkRef
      Exit For 'exit the 'for' loop since we have the title block. This assumes only a single block in each layout
    End If
Next BlkRef
'delete the selection set
BLCollect.Delete
'clear the variable
Set BLCollect = Nothing
End Function

用法应采用以下格式...
Dim blkObject As AcadBlockReference
Set blkObject = GetBlockReferenceByLayout("titleblock", "layout1")
If blkObject = Nothing Then
MsgBox "titleblock was not found in layout1"
Else
'do other stuff here to blkObject
End If

hardwired 发表于 2008-4-1 15:27:16

我不想去选择的布局,我已经强制程序在加载时转到paperspace,但现在不需要使用你的代码,但在它之前,它只会转到正常绘图中使用的最后一个布局,这就是为什么我希望当前布局在列表框中突出显示,因为最初程序只做了一个布局(当前布局)。但是与您提供的代码一样,我不必在物理上循环浏览布局,我不再需要它,我需要做的就是在列表框中没有选择任何布局的错误陷阱。
但是为了将来的参考和我自己对知识的渴望,我将如何编写列表框以突出显示当前布局?
出于某种原因,您在列表框中为选择所有内容提供的代码将不再起作用,它只选择一个 - 对代码的唯一更改是重命名控件并将其ListStyle属性更改为1 - fmListStyleOption。

Keith™ 发表于 2008-4-1 16:09:40

multiselect必须设置为frmMultiSelectMulti,否则将失败
要在填充列表框时突出显示当前布局,请检查布局名称是否与当前添加的布局名称匹配。如果是,则高亮显示。请记住,从列表框索引来看,列表框的计数是-1。
With ListBox1
'populate the listbox
For Each layout In layouts
   .AddItem layout.Name
'if the current layout matches the layout just added then select it
   If layout.Name = ThisDrawing.ActiveLayout.Name Then
    ListBox.Selected(.ListCount - 1) = True
   End If
Next

hardwired 发表于 2008-4-2 05:48:22

再次感谢..
现在我需要整理这个 全选 复选框.
我注意到,如果我删除您提供的以下代码:
Private Sub LayoutLIST_Change()
ReDim SelectedLayouts(0)
'loop through the listbox..
For X = 0 To LayoutLIST.ListCount - 1
'if an item is selected
    If LayoutLIST.Selected(X) = True Then
    'then increment our array and add it to the array..
      ReDim Preserve SelectedLayouts(UBound(SelectedLayouts) + 1)
      SelectedLayouts(UBound(SelectedLayouts)) = LayoutLIST.List(X)
    End If
Next X
End Sub
...从列表框的更改事件中,选择您提供的代码:
Private Sub SelectAll_CHK_Click()
For X = 0 To LayoutLIST.ListCount - 1
    LayoutLIST.Selected(X) = SelectAll_CHK.Value
Next X
End Sub
.....工程。但是,当然,我需要从列表框的更改事件中设置数组,那么除了您最初给出的方式之外,还有其他方法可以选择列表框中的所有条目吗?
这是我在这个程序上的最后一个障碍,好吧,就目前而言,我相信我会找到其他方法来改进它或添加功能,但现在,就是这样。

Keith™ 发表于 2008-4-2 08:37:12

我不明白你想完成什么,但代码如张贴的工作。当您使用SelectAll_CHK_Click事件选择项目时,它将触发LayoutLIST_Change事件,不是一次,而是针对所做的每个更改触发一次。
页: 1 [2]
查看完整版本: 布局和列表框以及其他L字。