{"id":19822,"date":"2025-04-06T14:31:51","date_gmt":"2025-04-06T06:31:51","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=19822"},"modified":"2025-04-27T13:34:41","modified_gmt":"2025-04-27T05:34:41","slug":"objectarx-2025%ef%bc%88c%ef%bc%89%e5%88%9b%e5%bb%ba%e5%b8%a6%e5%b1%9e%e6%80%a7%e7%9a%84%e5%9d%97%e5%ae%9a%e4%b9%89-acdbattributedefinition","status":"publish","type":"post","link":"https:\/\/blog.iyatt.com\/?p=19822","title":{"rendered":"ObjectARX 2025\uff08C++\uff09\u521b\u5efa\u5e26\u5c5e\u6027\u7684\u5757\u5b9a\u4e49 AcDbAttributeDefinition"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title ez-toc-toggle\" style=\"cursor:pointer\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.iyatt.com\/?p=19822\/#%E7%8E%AF%E5%A2%83\" >\u73af\u5883<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.iyatt.com\/?p=19822\/#%E5%AE%9E%E7%8E%B0\" >\u5b9e\u73b0<\/a><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E7%8E%AF%E5%A2%83\"><\/span>\u73af\u5883<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>AutoCAD \u673a\u68b0\u7248 2025<br \/>\nObjectARX 2025<br \/>\nVS 2022\uff08ISO C++14\uff09<\/p>\n<p>\u73af\u5883\u914d\u7f6e\u53c2\u8003\uff1a<a href=\"https:\/\/blog.iyatt.com\/?p=16480\">https:\/\/blog.iyatt.com\/?p=16480<\/a><br \/>\n\u5757\u5c5e\u6027\u4f7f\u7528\u53c2\u8003\uff1a<a href=\"https:\/\/blog.iyatt.com\/?p=19800\">https:\/\/blog.iyatt.com\/?p=19800<\/a><\/p>\n<h1><span class=\"ez-toc-section\" id=\"%E5%AE%9E%E7%8E%B0\"><\/span>\u5b9e\u73b0<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>CreateBlockWithAttribute.hpp<\/p>\n<pre><code class=\"language-cpp\">#pragma once\nclass CreateBlockWithAttribute\n{\npublic:\n    static void createBlock();\n};<\/code><\/pre>\n<p>CreateBlockWithAttribute.cpp<\/p>\n<pre><code class=\"language-cpp\">#include &quot;stdafx.h&quot;\n#include &quot;CreateBlockWithAttribute.hpp&quot;\n\nvoid CreateBlockWithAttribute::createBlock()\n{\n    \/\/ \u83b7\u53d6\u6570\u636e\u5e93\u5757\u8868\n    AcDbBlockTable* pBlockTable = nullptr;\n    acdbHostApplicationServices()-&gt;workingDatabase()-&gt;getBlockTable(pBlockTable, AcDb::kForWrite);\n\n    \/\/ \u521b\u5efa\u65b0\u7684\u5757\u8868\u8bb0\u5f55\n    AcDbBlockTableRecord* pBlockTableRecord = new AcDbBlockTableRecord();\n\n    \/\/ \u7528\u6237\u8f93\u5165\u5757\u540d\u79f0\n    AcString blockName;\n    if (acedGetString(Adesk::kFalse, L&quot;\\n\u8bf7\u8f93\u5165\u56fe\u5757\u540d\u79f0&quot;, blockName) != RTNORM)\n    {\n        pBlockTable-&gt;close();\n        delete pBlockTableRecord;\n        return;\n    }\n    pBlockTableRecord-&gt;setName(blockName.kACharPtr());\n\n    \/\/ \u5c06\u5757\u8868\u8bb0\u5f55\u6dfb\u52a0\u5230\u5757\u8868\u4e2d\n    pBlockTable-&gt;add(pBlockTableRecord);\n    pBlockTable-&gt;close();\n\n    \/\/ \u5411\u5757\u8bb0\u5f55\u4e2d\u6dfb\u52a0\u5b9e\u4f53\n    AcDbCircle* pCircle = new AcDbCircle(AcGePoint3d::kOrigin, AcGeVector3d(0, 0, 1), 10); \/\/ \u5706\n    AcDbAttributeDefinition* pAttributeDefinition = new AcDbAttributeDefinition(\n        AcGePoint3d::kOrigin, \/\/ \u63d2\u5165\u70b9\uff1a\u539f\u70b9\n        L&quot;1&quot;, \/\/\u9ed8\u8ba4\n        L&quot;\u5e8f\u53f7&quot;, \/\/ \u6807\u8bb0\n        L&quot;\u5e8f\u53f7\u6570\u503c&quot; \/\/ \u63d0\u793a\n    );\n    pAttributeDefinition-&gt;setHorizontalMode(AcDb::kTextCenter); \/\/ \u6c34\u5e73\u5c45\u4e2d\n    pAttributeDefinition-&gt;setVerticalMode(AcDb::kTextVertMid); \/\/ \u5782\u76f4\u5c45\u4e2d\n\n    pBlockTableRecord-&gt;appendAcDbEntity(pCircle);\n    pBlockTableRecord-&gt;appendAcDbEntity(pAttributeDefinition);\n\n    pCircle-&gt;close();\n    pAttributeDefinition-&gt;close();\n    pBlockTableRecord-&gt;close();\n}<\/code><\/pre>\n<p>\u5728 acrxEntryPoint.cpp \u4e2d\u5f15\u7528\u5934\u6587\u4ef6\uff0c\u5e76\u5728 On_kInitAppMsg \u65b9\u6cd5\u91cc\u8c03\u7528<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/04\/image-1743920990336.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 992px; --smush-placeholder-aspect-ratio: 992\/612;\" \/><\/p>\n<p>\u8c03\u8bd5\u8fd0\u884c\uff0c\u8f93\u5165\u8981\u8bbe\u7f6e\u7684\u5757\u540d\u8fdb\u884c\u521b\u5efa<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/04\/image-1743920741685.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 299px; --smush-placeholder-aspect-ratio: 299\/144;\" \/><\/p>\n<p>\u53ef\u4ee5\u63d2\u5165\u4f7f\u7528<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/04\/image-1743920797957.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 533px; --smush-placeholder-aspect-ratio: 533\/760;\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u73af\u5883 AutoCAD \u673a\u68b0\u7248 2025 ObjectARX 2025 VS 2022\uff08ISO C++14\uff09 \u73af [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"_lmt_disableupdate":"no","_lmt_disable":"no","footnotes":""},"categories":[1,616,589,618,621],"tags":[],"class_list":["post-19822","post","type-post","status-publish","format-standard","hentry","category-all","category-autocad","category-c-c","category-cad-cam","category-objectarx"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/19822","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=19822"}],"version-history":[{"count":5,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/19822\/revisions"}],"predecessor-version":[{"id":19891,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/19822\/revisions\/19891"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=19822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=19822"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=19822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}