如何在 VBA 中找到可用于语法的选项

How to find the options available for syntax in VBA

我不确定标题的适当术语。如果我的标题不好,请提出修改建议

情况

我是 运行 AutoCAD 通过 Excel 的 VBA。作为编码的一部分,我在 AutoCAD 中对基本尺寸样式进行硬编码。我没有使用注释尺寸样式。我的计划是根据需要复制基本尺寸样式,并根据需要更改比例因子。

问题

我发现 this snippit of code 这基本上给了我遵循的想法。问题是我想设置每个维度选项。我知道如果我查看 AutoCAD,我可以在手动设置样式或查看尺寸的属性 window 时看到很多不同的选项。它们有很多,这些位置的名称是为了便于阅读,不一定等于它们的 VBA 名称的确切语法。我可以去哪里或者我应该阅读什么来确定在“.”之后可以使用哪些名称。 ?

我还发现,在执行此操作时,某些值不是典型值,而是非常特殊的术语。 IE。 acAbove,acHorzCentered?我应该在哪里查看潜在价值是什么?经过一个小时左右的搜索,我偶然发现了 this site,它为我提供了箭头的潜在值,但我希望有比 google+猜测搜索词+点击随机结果更快更直接的方法。

到目前为止我尝试了什么

GOOGLE 在 wazoo 上搜索以获得链接

Horizontal Options (useful results but random discovery)

Creating Dimensions (not what I was looking for)

我当前的代码:

Dim DimStyle As AcadDimStyle


Set DimStyle = DWGFILE.DimStyles.Add("mm-0001")

With DimStyle
    .Color = acByLayer
    .ExtensionLineExtend = 2
    .Arrowhead1Type = acArrowDefault
    .Arrowhead2Type = acArrowDefault
    .ArrowheadSize = 3
    .TextColor = acWhite
    .TextHeight = 2.5
    .UnitsFormat = asDimLDecimal
    .PrimaryUnitsPrecision = acDimPrecicisionZero
    .TextGap = 2
    .LinearScaleFactor = 1
    .ExtensionLineOffset = 2
    .VerticalTextPosition = acAbove
    .HorizontalTextPosition = acHorzCentered
End With

Set DimStyle = DGWFile.DimStyle.Add("mm-" & Format(DimScale, "0000"))

'todo list
'copy base dimstyle to new name
'change scale factor in new name

摘要

您如何找到我可以与 Dimstyle(又名 AcadDymStyle)一起使用的所有尺寸选项的综合列表,例如:

.Color
.ExtensionLineExtend
.Arrowhead1Type

如何找到它们可以相等的值的综合列表,例如

.VerticalTextPosition = acAbove
.VerticalTextPosition = acBelow

现在在我的具体示例中它是 autocad,但我认为这是非常通用的,因为我在 Excel 中为类似的事情撞墙,最终找到了一些随机的代码碰巧使用了正在寻找的术语。因此,虽然 autoCAD 特定的答案将对我在这个特定案例中有很大帮助。我也在寻找一般情况,当我也处理 Excel 东西时,它也有望让我的脑袋免于瘀伤。

更新

所以我在 ObjectBrowser (F2) 中四处寻找。我可以在 类 下找到 AcadDimStyle,我可以在相邻的 window 中看到一堆成员,我假设它们是我可以在“.”之后使用的东西。 Thins 似乎是一个很好的起点。我在这个问题中举个例子,让我对我的具体案例感到困惑的部分是,并不是所有的东西都在“。”之后使用。正在显示在此列表中。

从屏幕截图来看,没有以下证据:

.Color
.ExtensionLineExtend
.Arrowhead1Type

我是不是漏掉了什么?

AutoCAD 中的标注样式有些特殊。

而其他符号 table 记录对象(例如 Text Style object) have ActiveX properties & methods pertinent to the AutoCAD element that they represent (for example, a Text Style object has fontfile, height, obliqueangle properties), a Dimension Style object 仅具有符号 table 记录所需的最少属性数:对父对象的引用、唯一标识符 (句柄/对象 ID) 和名称。

相反,尺寸样式的属性存储在 DIMSTYLE 符号 table 内的 DXF 数据中,并且,如果尺寸样式处于活动状态,则由标注样式系统变量(DIMPOSTDIMAPOSTDIMBLKDIMSCALEDIMASZDIMEXO 等)- 您可以使用 AutoCAD SETVAR命令通过以下方式获取此类系统变量的完整列表:

Command: SETVAR
Enter variable name or [?]: ?
Enter variable(s) to list <*>: DIM*

现在,虽然您可以使用 tblsearch 函数在 AutoLISP 中访问由 DIMSTYLE 符号 table 记录保存的 DXF 数据,这可能会产生如下所示的关联列表:

_$ (tblsearch "dimstyle" "standard")

(
    (0 . "DIMSTYLE")
    (2 . "Standard")
    (70 . 0)
    (3 . "")
    (4 . "")
    (5 . "ClosedBlank")
    (6 . "")
    (7 . "")
    (40 . 1.0)
    (41 . 1.0)
    (42 . 1.0)
    (43 . 0.0)
    (44 . 0.2)
    (45 . 0.0)
    (46 . 0.0)
    (47 . 0.0)
    (48 . 0.0)
    (140 . 1.0)
    (141 . -1.0)
    (142 . 0.0)
    (143 . 25.4)
    (144 . 1.0)
    (145 . 0.0)
    (146 . 1.0)
    (147 . 1.0)
    (71 . 0)
    (72 . 0)
    (73 . 1)
    (74 . 1)
    (75 . 0)
    (76 . 0)
    (77 . 0)
    (78 . 0)
    (170 . 0)
    (171 . 2)
    (172 . 0)
    (173 . 0)
    (174 . 0)
    (175 . 0)
    (176 . 256)
    (177 . 256)
    (178 . 0)
    (270 . 2)
    (271 . 2)
    (272 . 2)
    (273 . 2)
    (274 . 2)
    (340 . <Entity name: 7ffff703910>)
    (275 . 0)
    (280 . 0)
    (281 . 0)
    (282 . 0)
    (283 . 1)
    (284 . 0)
    (285 . 0)
    (286 . 0)
    (287 . 3)
    (288 . 0)
)

据我所知,无法通过 VBA 访问此数据。

但是,由于控制 Dimension 对象自身外观的各个属性可以覆盖用于创建它们的 Dimension Style,因此此类 dimension 对象具有相应的 ActiveX 属性每个可配置的尺寸样式设置。可以找到这些属性的参考 here.

TL;DR

因此,在以编程方式创建和配置新的尺寸样式时,您有以下三种选择:

  1. 临时创建一个维度对象,配置properties accordingly, and then use the CopyFrom方法将此类属性复制到您的新维度样式。

  2. 相应地设置各种尺寸样式系统变量的值(使用 SetVariable method of the AutoCAD Document object) and then use the CopyFrom method with the AutoCAD Document 对象作为 SourceObject 参数,以便将此类属性复制到新的尺寸样式。

  3. 在单独的模板绘图中配置尺寸样式并使用 CopyObjects method through an ObjectDBX interface to import the Dimension Style into your target drawing. I demonstrate this method in my Steal from Drawing 应用程序 - 此应用程序的代码是 AutoLISP,但可以轻松移植到 VBA。