乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 28|回复: 1

加载线型

[复制链接]
jLm

1

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2004-5-14 12:58:12 | 显示全部楼层 |阅读模式
谁能告诉我如何将ThisDrawing中的线型表与线型名称的列表或Excel电子表格进行比较,并加载尚未在ThisDrawing中的线型表?我正在处理我的第一个VBA例程,所以你可能不得不为我哑口无言。谢谢

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

0

主题

27

帖子

2

银币

初来乍到

Rank: 1

铜币
27
发表于 2004-5-16 23:52:12 | 显示全部楼层
我可能会避开excel或任何外部列表等。你的第一个VBA项目。
以下示例摘自acad开发人员帮助文件。
它的基本功能是:从acad.lin文件中加载特定线型(在本例中为“中心”)。
  1. Sub Example_Load()
  2.     ' This example attempts to load the linetype "CENTER" from
  3.     ' the acad.lin file. If the linetype already exists, then
  4.     ' a message is displayed.
  5.    
  6.     Dim linetypeName As String
  7.     linetypeName = "CENTER"
  8.    
  9.     ' Load "CENTER" line type from acad.lin file
  10.     On Error Resume Next    ' trap any load errors
  11.     ThisDrawing.Linetypes.Load linetypeName, "acad.lin"
  12.    
  13.     ' If the name already exists, then notify user
  14.     If Err.Description = "Duplicate record name" Then
  15.         MsgBox "A line type named '" & linetypeName & "' already exists.", , "Load Example"
  16.     End If
  17.    
  18. End Sub

以下代码将列出当前图形中加载的所有线型。
但是,没有办法知道当前/默认的线型文件是什么。
(至少据我所知没有,或者至少有一堆代码来比较线型结构和线型文件等。等等。等等等等。除非真的需要。)
当前图形中的线型列表将放入名为ListBox1的列表框中。因此,您需要创建一个具有该名称的listbaox的表单,或者更改为您选择的名称。
  1. Sub ListLinetypes()
  2.     Dim objLinetype As AcadLineType
  3.     Dim iCounter As Integer
  4.     Dim i As Variant
  5.     Dim MyList() As String
  6.     iCounter = 0
  7.     For Each objLinetype In ThisDrawing.Linetypes
  8. '   check if linetype comes from an xref linetype name will contain "|"
  9.         If InStrRev(objLinetype.Name, "|") = 0 Then
  10.             ReDim Preserve MyList(iCounter)
  11.             MyList(iCounter) = objLinetype.Name
  12.             iCounter = iCounter + 1
  13.         End If
  14.     Next
  15. '   sort list order, calls the SortArray function
  16.     SortArray MyList
  17. '   put the sorted list in the ListBox
  18.     For i = LBound(MyList) To UBound(MyList)
  19.         ListBox1.AddItem MyList(i)
  20.     Next
  21. End Sub

以下代码用于对列表进行排序。
将代码放入模块中。
  1. Option Explicit
  2. 'begin array sort
  3. Public Sub SortArray(StringArray() As String)
  4.     Dim loopOuter As Integer
  5.     Dim loopInner As Integer
  6.     Dim i As Integer
  7.     For loopOuter = UBound(StringArray) To _
  8.       LBound(StringArray) Step -1
  9.         For loopInner = 0 To loopOuter - 1
  10.             If UCase(StringArray(loopInner)) > _
  11.               UCase(StringArray(loopInner + 1)) Then
  12.                 Swap StringArray(loopInner), _
  13.                   StringArray(loopInner + 1)
  14.             End If
  15.         Next loopInner
  16.     Next loopOuter
  17. End Sub
  18. Private Sub Swap(a As String, b As String)
  19.     Dim c As String: c = a: a = b: b = c
  20. End Sub
  21. 'End array sort

因此,您可能想尝试的基本任务是。
创建包含2个列表框的窗体。其中一个可以包含图形中当前加载的所有线型。第二个列表框可以包含选定线型文件中可用的线型列表。
为简单起见,您可能希望在默认线型文件中编码。
然后添加一个按钮,以从可用列表中加载要加载到图形中的选定线型。则该线型应出现在当前线型列表中。
接下来,您可能希望添加另一个按钮,打开“选择文件”对话框,浏览并选择您选择的线型文件。
希望一切都有意义,都有好处。
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-15 17:41 , Processed in 0.501436 second(s), 67 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表