CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2023 开发者帮助

DistanceToReal 方法 (ActiveX)

2024-5-18 18:55| 发布者: admin| 查看: 78| 评论: 0|原作者: admin|来自: AutoCAD

DistanceToReal 方法 (ActiveX)

将字符串的距离转换为实数(双精度)值。

支持的平台:仅限 Windows

签名

VBA:

RetVal = DistanceToReal(Distance, Unit)
对象

类型: 实用程序

此方法应用到的对象。

距离

访问:仅输入

类型:字符串

以字符串值表示的距离。

单位

访问:仅输入

类型:枚举AcUnits

要将字符串转换为的单位。

  • acDefaultUnits
  • acScientific
  • acDecimal
  • acEngineering
  • acArchitectural
  • acFractional

返回值 (RetVal)

类型:

以实数表示的距离。

言论

没有其他评论。

例子

VBA:

Sub Example_DistanceToReal()
    ' This example passes several different distances in
    ' different units to be converted to real values.
    
    Dim distAsString As String
    Dim unit As Long
    Dim distAsReal As Double
    
    ' Convert the distance to a real in scientific units
    unit = acScientific
    distAsString = "1.75E+01"
    distAsReal = ThisDrawing.Utility.DistanceToReal(distAsString, unit)
    MsgBox "1.75E+01 converts to " & distAsReal & " in scientific units.", , "DistanceToReal Example"
    
    ' Convert the distance to a real in decimal units
    unit = acDecimal
    distAsString = "17.5"
    distAsReal = ThisDrawing.Utility.DistanceToReal(distAsString, unit)
    MsgBox "1.75 converts to " & distAsReal & " in decimal units.", , "DistanceToReal Example"
    
    ' Convert the distance to a real in engineering units
    unit = acEngineering
    distAsString = "1'-5.50"""
    distAsReal = ThisDrawing.Utility.DistanceToReal(distAsString, unit)
    MsgBox "1'-5.50"" converts to " & distAsReal & " in engineering units.", , "DistanceToReal Example"
    
    ' Convert the distance to a real in architectural units
    unit = acArchitectural
    distAsString = "1'-5 1/2"""
    distAsReal = ThisDrawing.Utility.DistanceToReal(distAsString, unit)
    MsgBox "1'-5 1/2"" converts to " & distAsReal & " in architectural units.", , "DistanceToReal Example"
    
    ' Convert the distance to a real in fractional units
    unit = acFractional
    distAsString = "17 1/2"
    distAsReal = ThisDrawing.Utility.DistanceToReal(distAsString, unit)
    MsgBox "1'-5 1/2"" converts to " & distAsReal & " in fractional units.", , "DistanceToReal Example"
    
End Sub

可视化 LISP:

(vl-load-com)
(defun c:Example_DistanceToReal()
    ;; This example passes several different distances in
    ;; different units to be converted to real values.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
  
    ;; Convert the distance to a real in scientific units
    (setq unit acScientific
          distAsString "1.75E+01"
          distAsReal (vla-DistanceToReal (vla-get-Utility doc) distAsString unit))
    (alert (strcat "1.75E+01 converts to " (rtos distAsReal 2) " in scientific units."))
    
    ;; Convert the distance to a real in decimal units
    (setq unit acDecimal
          distAsString "17.5"
	         distAsReal (vla-DistanceToReal (vla-get-Utility doc) distAsString unit))
    (alert (strcat "17.5 converts to " (rtos distAsReal 2) " in decimal units."))
    
    ;; Convert the distance to a real in engineering units
    (setq unit acEngineering
          distAsString "1'-5.50\""
	         distAsReal (vla-DistanceToReal (vla-get-Utility doc) distAsString unit))
    (alert (strcat "1'-5.50\" converts to " (rtos distAsReal 2) " in engineering units."))
    
    ;; Convert the distance to a real in architectural units
    (setq unit acArchitectural
          distAsString "1'-5 1/2\""
	         distAsReal (vla-DistanceToReal (vla-get-Utility doc) distAsString unit))
    (alert (strcat "1'-5 1/2\" converts to " (rtos distAsReal 2) " in architectural units."))
    
    ;; Convert the distance to a real in fractional units
    (setq unit acFractional
          distAsString "17 1/2"
	         distAsReal (vla-DistanceToReal (vla-get-Utility doc) distAsString unit))
    (alert (strcat "17 1/2 converts to " (rtos distAsReal 2) " in fractional units."))
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1   苏公网安备32011402011833)

GMT+8, 2024-12-15 11:34

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部