CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

相关分类

IsURL Method (ActiveX)

2023-1-4 05:42| 发布者: admin| 查看: 644| 评论: 0|来自: AutoCAD

摘要: 验证给定的 URL。

验证给定的 URL。

支持的平台:仅窗口

签名

工 务 局:

RetVal = object.IsURL(URL)
对象

类型:实用工具

此方法适用的对象。

本地文件

访问:仅输入

类型:字符串

要验证的网址。

返回值(RetVal)

类型:布尔

  • True:字符串表示有效的 URL。
  • False:字符串不是有效的 URL。

言论

“有效”URL的定义取决于应用程序,因为给定的第三方应用程序可能对支持所有Internet协议不感兴趣。例如,尝试将用户连接到网站的应用程序可能不需要提供对 FTP 站点的访问。在此假设应用程序中,如果输入以“http://”、“https://”、“ftp://”或“file:///”以外的内容开头的 URL,则将返回 avalue。False

此方法对 AutoCAD 的默认功能支持 FTP、HTTP、HTTPS 和 FILE 协议。

例子

工 务 局:

Sub Example_IsRemoteFile()
    ' This example will prompt the user for a URL to download and will verify that
    ' a proper URL was entered.  After downloading, the example will attempt to load
    ' the downloaded URL as a drawing.
    '
    ' * Note: Remember to delete the downloaded file from your disk drive when finished.
    
    Dim Utility As AcadUtility
    Dim URL As String, DestFile As String, FileURL As String
    
    Set Utility = ThisDrawing.Utility   ' Connect to Utility object
    
GETURL:
    ' Prompt user for a URL to download.  This should be a URL to an AutoCAD drawing file.
    URL = Utility.GetString(False, vbLf & "Enter the complete URL of the file you wish to download: ")
    
    URL = Trim(URL)                     ' Get rid of blank spaces
    
    If URL = "" Then Exit Sub           ' Did user cancel

    ' Determine if user entered a valid URL; if not, prompt again
    If Not (Utility.IsURL(URL)) Then
        MsgBox "The URL you entered is not valid.  Make sure the syntax is a valid URL."
        GoTo GETURL
    End If
        
    ' Download URL
    Utility.GetRemoteFile URL, DestFile, True
    
    ' Display downloaded file information
    MsgBox URL & " was downloaded to: " & DestFile
   
    ' Use IsRemoteFile to determine if this file was downloaded from a URL.
    ' If it was, display the URL it was downloaded from
    '
    ' * Note: Although the results that IsRemoteFile will return are already known
    ' since the file was just downloaded it is important to know how this
    ' method can be used.
    If Utility.IsRemoteFile(DestFile, FileURL) Then
        MsgBox "The file: " & DestFile & " is a downloaded file and was downloaded from: " & FileURL
    Else
        MsgBox "The file: " & DestFile & " is not a downloaded file."
    End If

End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_IsRemoteFile()
    ;; This example will prompt the user for a URL to download and will verify that
    ;; a proper URL was entered.  After downloading, the example will provide information
    ;; about the downloaded drawing.
    ;;
    ;; * Note: Remember to delete the downloaded file from your disk drive when finished.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))

    (setq Utility (vla-get-Utility doc))   ;; Connect to Utility object
    
    ;; Prompt user for a URL to download.  This should be a URL to an AutoCAD drawing file.
    (setq URL (vla-GetString Utility :vlax-false "Enter the complete URL of the file you wish to download: "))
  
    (if (/= URL "")
        (progn
	           (if (= (vla-IsURL Utility URL) :vlax-false)
	               (alert "The URL you entered is not valid.  Make sure the syntax is a valid URL.")
	               (progn
	                   ;; Download URL
	                   (vla-GetRemoteFile Utility URL 'DestFile :vlax-true)
		    
	                   ;; Display downloaded file information
	                   (alert (strcat URL " was downloaded to: " DestFile "\n"))

	                   ;; Use IsRemoteFile to determine if this file was downloaded from a URL.
	                   ;; If it was, display the URL it was downloaded from
	                   ;;
	                   ;; * Note: Although the results that IsRemoteFile will return are already known
	                   ;; since the file was just downloaded it is important to know how this
	                   ;; method can be used.
	                   (if (= (vla-IsRemoteFile Utility DestFile URL) :vlax-true)
	                       (alert (strcat "The file: " DestFile " is a downloaded file and was downloaded from: " URL))
	                       (alert (strcat "The file: " DestFile " is not a downloaded file."))
	                   )
	               )
	           )
	       )
    )
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-12 19:52

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部