{"id":834,"date":"2024-06-24T08:50:13","date_gmt":"2024-06-24T00:50:13","guid":{"rendered":"http:\/\/www.wyrcad.com\/?p=834"},"modified":"2024-06-25T08:46:24","modified_gmt":"2024-06-25T00:46:24","slug":"autocad-%e4%b8%ba%e5%9b%be%e5%85%83%e6%b7%bb%e5%8a%a0%e6%89%a9%e5%b1%95%e6%95%b0%e6%8d%aexdata","status":"publish","type":"post","link":"https:\/\/www.wyrcad.com\/?p=834","title":{"rendered":"AutoCAD \u5411\u56fe\u5143\u6dfb\u52a0\u6269\u5c55\u6570\u636e(XData)"},"content":{"rendered":"\n<p>&#8216;\u7ed1\u5b9a AutoCAD<br>Dim I As Integer, J As Integer<br>Dim oAutoCAD As Object \u2018AutoCAD Application \u672c\u8eab<br>Call BindAutoCAD(True)<br>Dim oDraw As Object \u2018AutoCAD \u591a\u6587\u6863\u4e4b\u4e00<\/p>\n\n\n\n<p>&#8216;\u6253\u5f00\u5e76\u7ed1\u5b9a\u6587\u4ef6 D:\/Test.dwg<br>Set oDraw = oAutoCAD.Application.Documents.Open(&#8220;D:\/Test.dwg&#8221;)<\/p>\n\n\n\n<p>&#8216;\u7ed1\u5b9a Microsoft Excel<br>Dim oExcel As Object &#8216;Microsoft Excel Application \u672c\u8eab<br>Call BindExcel(True)<br>Dim oBook As Object &#8216;Microsoft Excel \u591a\u5de5\u4f5c\u8584\u4e4b\u4e00<br>Dim oSheet As Object &#8216;\u5de5\u4f5c\u8584\u7684\u5de5\u4f5c\u8868\u4e4b\u4e00<\/p>\n\n\n\n<p>&#8216;\u6253\u5f00\u5e76\u7ed1\u5b9a\u6587\u4ef6 D:\/Test.xls<br>Set oBook = oExcel.Application.WorkBooks.Open(&#8220;D:\/Test.xls&#8221;)<\/p>\n\n\n\n<p>&#8216;\u7ed1\u5b9a\u5df2\u6709\u5de5\u4f5c\u8868 Sheet1<br>Set oSheet = oBook.Sheets(&#8220;Sheet1&#8221;)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"605\" height=\"286\" src=\"https:\/\/www.wyrcad.com\/wp-content\/uploads\/2024\/06\/Sheet.jpg\" alt=\"\" class=\"wp-image-846\" srcset=\"https:\/\/www.wyrcad.com\/wp-content\/uploads\/2024\/06\/Sheet.jpg 605w, https:\/\/www.wyrcad.com\/wp-content\/uploads\/2024\/06\/Sheet-300x142.jpg 300w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/figure>\n\n\n\n<p>&#8216;\u5c4f\u5e55\u9009\u62e9\u56fe\u5143<br>Dim PointPicked As Variant<br>Dim oEntity As Object<br>oDraw.Activate<br>oDraw.Utility.GetEntity oEntity, PointPicked<\/p>\n\n\n\n<p>&#8216;\u6307\u5411 TargetRow \u884c\u7b2c\u4e00\u5217<br>Dim TargetRow As Integer<br>TargetRow = <a href=\"https:\/\/www.wyrcad.com\/?p=806\">MaxRow<\/a>(oSheet) &#8216;\u6709\u6587\u5b57\u7684\u6700\u5927\u884c<br>oSheet.Cells(TargetRow, 1).Select<\/p>\n\n\n\n<p>&#8216;\u6dfb\u52a0\u6269\u5c55\u6570\u636e<br>For J = <a href=\"https:\/\/www.wyrcad.com\/?p=806\">MinColumn<\/a>(oSheet) To <a href=\"https:\/\/www.wyrcad.com\/?p=806\">MaxColumn<\/a>(oSheet)<br>If <a href=\"https:\/\/www.wyrcad.com\/?p=826\">IsInteger<\/a>(oSheet.Cells(1, J)) And _<br><a href=\"https:\/\/www.wyrcad.com\/?p=826\">IsInRange<\/a>(oSheet.Cells(1, J), 1000, 1071, True) And _<br>Not oSheet.Cells(TargetRow, J) = &#8220;&#8221; Then &#8216;\u5141\u8bb8\u7b49\u4e8e\u4e0a\u4e0b\u754c<br>Dim iCount As Integer<br>iCount = iCount + 1<br>ReDim Preserve iTypeArray(0 To iCount \u2013 1)<br>ReDim Preserve sValueArray(0 To iCount \u2013 1)<br>iTypeArray(iCount \u2013 1) = oSheet.Cells(1, J)<br>sValueArray(iCount \u2013 1) = oSheet.Cells(TargetRow, J) &#8216;\u65b0\u6570\u636e\u884c\u4f4d\u4e8e\u6700\u540e<br>End If<br>Next J<br>&#8216;Debug.Print <a href=\"https:\/\/www.wyrcad.com\/?p=798\">IsEmptyArray<\/a>(iTypeArray)<br>&#8216;Debug.Print <a href=\"https:\/\/www.wyrcad.com\/?p=798\">IsEmptyArray<\/a>(sValueArray)<br>If AttachXData(oEntity, iTypeArray(), sValueArray()) Then<br>Debug.Print &#8220;Attached.&#8221;<br>Else<br>Debug.Print &#8220;Not attached.&#8221;<br>End If<\/p>\n\n\n\n<p>Public Function AttachXData(ByVal oEntity As Object, ByRef iType() As Integer, ByRef sValue() As String) As Boolean<br>Dim I As Integer, J As Integer<br>AttachXData = False<br>If Not IsObject(oEntity) Then Exit Function<br>If Not IsArray(iType) Then Exit Function<br>If Not IsArray(sValue) Then Exit Function<br>If Not LBound(iType) = LBound(sValue) Then Exit Function<br>If Not UBound(iType) = UBound(sValue) Then Exit Function<br>If Not <a href=\"https:\/\/www.wyrcad.com\/?p=798\">IsInArray<\/a>(&#8220;1001&#8221;, iType) Then Exit Function<br>If Not iType(LBound(iType)) = &#8220;1001&#8221; Then Exit Function<br>For J = LBound(iType) To UBound(iType)<br>If Not <a href=\"https:\/\/www.wyrcad.com\/?p=826\">IsInteger<\/a>(iType(J)) Then Exit Function<br>If Trim(sValue(J)) = &#8220;&#8221; Then Exit Function<br>Select Case iType(J)<br>Case 1001 &#8216;\u6392\u7b2c\u4e00<br>If <a href=\"https:\/\/www.wyrcad.com\/?p=785\">CountStr<\/a>(False, sValue(J), &#8220;|&#8221;) &gt; 0 Then Exit Function &#8216;Only one appname is allowed when attaching.<br>Case 1000, 1002, 1003, 1004, 1005 &#8216;1002\/1004 \u6570\u636e\u7279\u6b8a<br>&#8216;Nothing<br>Case 1010, 1011, 1012, 1013 &#8216;\u4e09\u7ef4<br>For I = 1 To <a href=\"https:\/\/www.wyrcad.com\/?p=785\">CountStr<\/a>(False, sValue(J), &#8220;|&#8221;) + 1<br>If Not <a href=\"https:\/\/www.wyrcad.com\/?p=785\">CountStr<\/a>(False, <a href=\"https:\/\/www.wyrcad.com\/?p=785\">ExtractDivide<\/a>(&#8220;|&#8221;, sValue(J), I), &#8220;,&#8221;) = 2 Then Exit Function &#8216;The data format is as nnn,nnn,nnn.<br>If Not IsNumeric(<a href=\"https:\/\/www.wyrcad.com\/?p=785\">ExtractDivide<\/a>(&#8220;,&#8221;, <a href=\"https:\/\/www.wyrcad.com\/?p=785\">ExtractDivide<\/a>(&#8220;|&#8221;, sValue(J), I), 1)) Then Exit Function<br>If Not IsNumeric(<a href=\"https:\/\/www.wyrcad.com\/?p=785\">ExtractDivide<\/a>(&#8220;,&#8221;, <a href=\"https:\/\/www.wyrcad.com\/?p=785\">ExtractDivide<\/a>(&#8220;|&#8221;, sValue(J), I), 2)) Then Exit Function<br>If Not IsNumeric(<a href=\"https:\/\/www.wyrcad.com\/?p=785\">ExtractDivide<\/a>(&#8220;,&#8221;, <a href=\"https:\/\/www.wyrcad.com\/?p=785\">ExtractDivide<\/a>(&#8220;|&#8221;, sValue(J), I), 3)) Then Exit Function<br>Next I<br>Case 1040, 1041, 1042<br>For I = 1 To <a href=\"https:\/\/www.wyrcad.com\/?p=785\">CountStr<\/a>(False, sValue(J), &#8220;|&#8221;) + 1<br>If Not IsNumeric(<a href=\"https:\/\/www.wyrcad.com\/?p=785\">ExtractDivide<\/a>(&#8220;|&#8221;, sValue(J), I)) Then Exit Function<br>Next I<br>Case 1070, 1071<br>For I = 1 To <a href=\"https:\/\/www.wyrcad.com\/?p=785\">CountStr<\/a>(False, sValue(J), &#8220;|&#8221;) + 1<br>If Not IsInteger(<a href=\"https:\/\/www.wyrcad.com\/?p=785\">ExtractDivide<\/a>(&#8220;|&#8221;, sValue(J), I)) Then Exit Function<br>Next I<br>Case Else<br>&#8216;Nothing<br>End Select<br>Next J<br>&#8216;DXF \u7ec4\u7801\u503c \u6269\u5c55\u6570\u636e\u5185\u5bb9<br>&#8216;1000 \u5b57\u7b26\u4e32, \u6269\u5c55\u6570\u636e\u4e2d\u7684\u5b57\u7b26\u4e32\u53ef\u957f\u8fbe 255 \u5b57\u8282\uff08\u7b2c 256 \u5b57\u8282\u662f\u4e3a\u7a7a\u5b57\u7b26\u4fdd\u7559\u7684\uff09<br>&#8216;1001 \u5e94\u7528\u7a0b\u5e8f\u540d, \u5e94\u7528\u540d\u79f0\u53ef\u957f\u8fbe 31 \u5b57\u8282\uff08\u7b2c 32 \u5b57\u8282\u662f\u4e3a\u7a7a\u5b57\u7b26\u4fdd\u7559\u7684\uff09\uff0c\u800c\u4e14\u5fc5\u987b\u7b26\u5408\u7b26\u53f7\u8868\u7684\u540d\u79f0\u89c4\u5219\uff08\u5982\u56fe\u5c42\u540d\u79f0\uff09\u3002\u5e94\u7528\u540d\u79f0\u53ef\u5305\u542b\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u4e13\u7528\u5b57\u7b26 $\uff08\u7f8e\u5143\u7b26\u53f7\uff09\u3001-\uff08\u8fde\u5b57\u7b26\uff09\u4ee5\u53ca _\uff08\u4e0b\u5212\u7ebf\uff09\uff0c\u4f46\u4e0d\u80fd\u5305\u542b\u7a7a\u683c<br>&#8216;1002 \u63a7\u5236\u5b57\u7b26\u4e32, \u6269\u5c55\u6570\u636e\u7684\u63a7\u5236\u5b57\u7b26\u4e32\u53ef\u4ee5\u662f&#8221;{&#8220;\u6216&#8221;}&#8221;\u3002\u8fd9\u4e9b\u5927\u62ec\u53f7\u4f7f\u5e94\u7528\u53ef\u4ee5\u901a\u8fc7\u5c06\u6269\u5c55\u6570\u636e\u7ec6\u5206\u4e3a\u8868\u6765\u7ec4\u7ec7\u5b83\u4eec\u3002\u5de6\u62ec\u53f7\u5f00\u59cb\u4e00\u4e2a\u8868\uff0c\u53f3\u62ec\u53f7\u7ed3\u675f\u6700\u65b0\u7684\u8868\u3002\u8868\u662f\u53ef\u4ee5\u5d4c\u5957\u7684<br>&#8216;1003 \u56fe\u5c42\u540d, \u4e0e\u6269\u5c55\u6570\u636e\u76f8\u5173\u8054\u7684\u56fe\u5c42\u540d\u79f0, \u987b\u662f\u5df2\u6709\u5c42<br>&#8216;1004 \u4e8c\u8fdb\u5236\u6570\u636e, \u4e8c\u8fdb\u5236\u6570\u636e\u88ab\u7ec4\u7ec7\u4e3a\u53ef\u53d8\u957f\u5ea6\u7684\u6570\u636e\u5757\uff0c\u5b83\u53ef\u5728\u6709 ads_binary \u7ed3\u6784\u7684 ObjectARX \u4e2d\u5904\u7406\u3002\u6570\u636e\u5757\u7684\u6700\u5927\u957f\u5ea6\u4e3a 127 \u5b57\u8282<br>&#8216;1005 \u6570\u636e\u5e93\u5bf9\u8c61\u53e5\u67c4, \u56fe\u5f62\u6570\u636e\u5e93\u4e2d\u7684\u56fe\u5143\u53e5\u67c4<br>&#8216;1010 \u4e09\u7ef4\u70b9\uff08X, Y, Z\uff09, \u4e00\u4e2a\u70b9\u4e2d\u7684\u4e09\u4e2a\u5b9e\u6570\u503c<br>&#8216;1011 \u4e09\u7ef4\u7a7a\u95f4\u4f4d\u7f6e, \u4e0e\u7b80\u5355\u7684\u4e09\u7ef4\u70b9\u4e0d\u540c\uff0c\u5176 WCS \u5750\u6807\u968f\u6269\u5c55\u6570\u636e\u6240\u5c5e\u7684\u7236\u56fe\u5143\u79fb\u52a8\u3001\u6bd4\u4f8b\u7f29\u653e\u3001\u65cb\u8f6c\u548c\u955c\u50cf\u3002\u5f53\u5bf9\u7236\u56fe\u5143\u4f7f\u7528 STRETCH \u547d\u4ee4\u5e76\u4e14\u6b64\u70b9\u4f4d\u4e8e\u9009\u62e9\u7a97\u53e3\u4e2d\u65f6\uff0c\u8be5 WCS \u7684\u4f4d\u7f6e\u4e5f\u4f1a\u88ab\u62c9\u4f38<br>&#8216;1012 \u4e09\u7ef4\u7a7a\u95f4\u8ddd\u79bb, \u4e00\u4e2a\u968f\u7740\u7236\u56fe\u5143\u6bd4\u4f8b\u7f29\u653e\u3001\u65cb\u8f6c\u6216\u955c\u50cf\u7684\u4e09\u7ef4\u70b9\uff0c\u4f46\u4e0d\u53ef\u62c9\u4f38\u6216\u79fb\u52a8<br>&#8216;1013 \u4e09\u7ef4\u7a7a\u95f4\u65b9\u5411, \u4e00\u4e2a\u968f\u7740\u7236\u56fe\u5143\u65cb\u8f6c\u6216\u955c\u50cf\u7684\u4e09\u7ef4\u70b9\uff0c\u4f46\u4e0d\u53ef\u6bd4\u4f8b\u7f29\u653e\u3001\u62c9\u4f38\u6216\u79fb\u52a8\u3002\u5176 WCS \u65b9\u5411\u662f\u4e00\u4e2a\u5355\u4f4d\u957f\u5ea6\u7684\u89c4\u683c\u5316\u5411\u91cf<br>&#8216;1040 \u6d6e\u70b9\u6570, \u4e00\u4e2a\u5b9e\u6570\u503c<br>&#8216;1041 \u8ddd\u79bb\u503c, \u4e00\u4e2a\u968f\u7740\u7236\u56fe\u5143\u6bd4\u4f8b\u7f29\u653e\u7684\u5b9e\u6570\u503c<br>&#8216;1042 \u6bd4\u4f8b\u7cfb\u6570, \u4e00\u4e2a\u968f\u7740\u7236\u56fe\u5143\u6bd4\u4f8b\u7f29\u653e\u7684\u5b9e\u6570\u503c<br>&#8216;1070 \u6574\u6570, \u4e00\u4e2a 16 \u4f4d\u6574\u6570\uff08\u5e26\u7b26\u53f7\u6216\u4e0d\u5e26\u7b26\u53f7\uff09<br>&#8216;1071 \u957f\u6574\u6570, \u4e00\u4e2a 32 \u4f4d\u5e26\u7b26\u53f7\u7684\uff08\u957f\uff09\u6574\u6570\u3002\u5982\u679c 1071 \u7ec4\u7801\u4e2d\u51fa\u73b0\u77ed\u6574\u6570\u6216\u5b9e\u6570\u503c\uff0c\u5219\u88ab\u8f6c\u6362\u4e3a\u4e00\u4e2a\u957f\u6574\u6570\uff1b\u5982\u679c\u7ec4\u7801\u503c\u975e\u6cd5\uff08\u4f8b\u5982\u4e00\u4e2a\u5b57\u7b26\u4e32\uff09\uff0c\u5219\u5c06\u88ab\u8f6c\u6362\u4e3a\u957f\u6574\u6570\u5f62\u5f0f\u7684\u96f6 (0L)<br>Dim iCount As Integer<br>For J = LBound(iType) To UBound(iType)<br>iCount = iCount + 1<br>iCount = iCount + <a href=\"https:\/\/www.wyrcad.com\/?p=785\">CountStr<\/a>(False, sValue(J), &#8220;|&#8221;)<br>Next J<br>If iCount = 0 Then Exit Function<br>&#8216; Initialize all the xdata values. Note that first data in the list should be application name and first datatype code should be 1001<br>ReDim DataType(0 To iCount \u2013 1) As Integer<br>ReDim DataValue(0 To iCount \u2013 1) As Variant<br>iCount = 0 &#8216;\u91cd\u7f6e<br>Dim ThreeDim(0 To 2) As Double<br>For J = LBound(iType) To UBound(iType)<br>For I = 1 To <a href=\"https:\/\/www.wyrcad.com\/?p=785\">CountStr<\/a>(False, sValue(J), &#8220;|&#8221;) + 1<br>iCount = iCount + 1<br>DataType(iCount \u2013 1) = iType(J)<br>&#8216;Debug.Print DataType(iCount \u2013 1)<br>If iType(J) = 1010 Or iType(J) = 1011 Or iType(J) = 1012 Or iType(J) = 1013 Then &#8216;\u4e09\u7ef4<br>ThreeDim(0) = <a href=\"https:\/\/www.wyrcad.com\/?p=785\">ExtractDivide<\/a>(&#8220;,&#8221;, <a href=\"https:\/\/www.wyrcad.com\/?p=785\">ExtractDivide<\/a>(&#8220;|&#8221;, sValue(J), I), 1)<br>ThreeDim(1) = <a href=\"https:\/\/www.wyrcad.com\/?p=785\">ExtractDivide<\/a>(&#8220;,&#8221;, <a href=\"https:\/\/www.wyrcad.com\/?p=785\">ExtractDivide<\/a>(&#8220;|&#8221;, sValue(J), I), 2)<br>ThreeDim(2) = <a href=\"https:\/\/www.wyrcad.com\/?p=785\">ExtractDivide<\/a>(&#8220;,&#8221;, <a href=\"https:\/\/www.wyrcad.com\/?p=785\">ExtractDivide<\/a>(&#8220;|&#8221;, sValue(J), I), 3)<br>&#8216;Debug.Print ThreeDim(0)<br>&#8216;Debug.Print ThreeDim(1)<br>&#8216;Debug.Print ThreeDim(2)<br>DataValue(iCount \u2013 1) = ThreeDim<br>Else<br>DataValue(iCount \u2013 1) = <a href=\"https:\/\/www.wyrcad.com\/?p=785\">ExtractDivide<\/a>(&#8220;|&#8221;, sValue(J), I)<br>&#8216;Debug.Print DataValue(iCount \u2013 1)<br>End If<br>Next I<br>Next J<br>&#8216; Attach the xdata to the entity<br>oEntity.SetXData DataType, DataValue<br>AttachXData = True<br>End Function<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8216;\u7ed1\u5b9a AutoCADDim I As Integer, J As IntegerDim oAut &hellip; <a href=\"https:\/\/www.wyrcad.com\/?p=834\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cAutoCAD \u5411\u56fe\u5143\u6dfb\u52a0\u6269\u5c55\u6570\u636e(XData)\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[24,17],"class_list":["post-834","post","type-post","status-publish","format-standard","hentry","category-bianchengyuandi","tag-vb","tag-biancheng"],"_links":{"self":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=834"}],"version-history":[{"count":13,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/834\/revisions"}],"predecessor-version":[{"id":886,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/834\/revisions\/886"}],"wp:attachment":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}