找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1360|回复: 4

[每日一码] Example Add Method

[复制链接]

已领礼包: 1268个

财富等级: 财源广进

发表于 2014-12-14 19:36:18 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
  1. (vl-load-com)
  2. (defun c:Example_Add()
  3.     ;; This example adds a block, dictionary, dimension style,
  4.     ;; group, layer, registered application, selection set,
  5.     ;; textstyle, view, viewport and UCS using the Add method.
  6.     (setq acadObj (vlax-get-acad-object))
  7.     (setq doc (vla-get-ActiveDocument acadObj))
  8.   
  9. ;; ADDBLOCK:
  10.     ;; Create a new block called "New_Block"

  11.     ;; Define the insertion point
  12.     (setq insertionPnt (vlax-3d-point 0 0 0))
  13.    
  14.     ;; Add the block to the blocks collection
  15.     (setq blocks (vla-get-Blocks doc))
  16.     (setq blockObj (vla-Add blocks insertionPnt "New_Block"))
  17.     (alert (strcat (vla-get-Name blockObj) " has been added."
  18.                     "\nOrigin: " (rtos (vlax-safearray-get-element (vlax-variant-value (vla-get-Origin blockObj)) 0) 2 2) ", "
  19.                                  (rtos (vlax-safearray-get-element (vlax-variant-value (vla-get-Origin blockObj)) 1) 2 2) ", "
  20.                                  (rtos (vlax-safearray-get-element (vlax-variant-value (vla-get-Origin blockObj)) 2) 2 2)
  21.            )
  22.     )
  23.    
  24. ;; ADDDICTIONARY:
  25.     ;; Create a new dictionary called "New_Dictionary"

  26.     ;; Add the dictionary to the dictionaries collection
  27.     (setq dictionaries (vla-get-Dictionaries doc))
  28.     (setq dictObj (vla-Add dictionaries "New_Dictionary"))
  29.     (alert (strcat (vla-get-Name dictObj) " has been added."))

  30. ;; ADDDIMSTYLE:
  31.     ;; Create a new dimension style called "New_Dimstyle" in current drawing
  32.    
  33.     ;; Add the dimstyle to the dimstyles collection
  34.     (setq dimStyles (vla-get-DimStyles doc))
  35.     (setq dimStyleObj (vla-Add dimStyles "New_Dimstyle"))
  36.     (alert (strcat (vla-get-Name dimStyleObj) " has been added."))
  37.    
  38. ;; ADDGROUP:
  39.     ;; Create a new group called "New_Group" in current drawing
  40.    
  41.     ;; Add the group to the groups collection
  42.     (setq groups (vla-get-Groups doc))
  43.     (setq groupObj (vla-Add dimStyles "New_Group"))
  44.     (alert (strcat (vla-get-Name groupObj) " has been added."))
  45.    
  46. ;; ADDLAYER:
  47.     ;; This example creates a new layer called "New_Layer"
  48.    
  49.     ;; Add the layer to the layers collection
  50.     (setq layers (vla-get-Layers doc))
  51.     (setq layerObj (vla-Add layers "New_Layer"))
  52.    
  53.     ;; Make the new layer the active layer for the drawing
  54.     (vla-put-ActiveLayer doc layerObj)
  55.    
  56.     ;; Display the status of the new layer
  57.     (alert (strcat (vla-get-Name layerObj) " has been added."
  58.                    "\nLayerOn Status: " (if (= (vla-get-LayerOn layerObj) :vlax-true) "1" "0")
  59.                    "\nFreeze Status: " (if (= (vla-get-Freeze layerObj) :vlax-true) "1" "0")
  60.                    "\nLock Status: "  (if (= (vla-get-Lock layerObj) :vlax-true) "1" "0")
  61.                    "\nColor: " (itoa (vla-get-Color layerObj))
  62.            )
  63.     )
  64.    
  65. ;; ADDREGISTEREDAPP:
  66.     ;; Create a registered application named "New_RegApp" in current drawing
  67.    
  68.     ;; Add the registered application to the registered applications collection
  69.     (setq regApps (vla-get-RegisteredApplications doc))
  70.     (setq regAppObj (vla-Add regApps "New_RegApp"))
  71.     (alert (strcat (vla-get-Name regAppObj) " has been added."))

  72. ;; ADDSELECTIONSET:
  73.     ;; Create a selectionset named "New_SelectionSet" in current drawing
  74.    
  75.     ;; Add the selection set to the selection sets collection
  76.     (setq ssets (vla-get-SelectionSets doc))
  77.     (setq ssetObj (vla-Add ssets "New_SelectionSet"))
  78.     (alert (strcat (vla-get-Name ssetObj) " has been added."
  79.                     "\nThe number of items in the selection set is " (itoa (vla-get-Count ssetObj))
  80.            )
  81.     )
  82.    
  83. ;; ADDTEXTSTYLE:
  84.     ;; Create a textstyle named "New_Textstyle" in current drawing
  85.    
  86.     ;; Add the textstyle to the textstyles collection
  87.     (setq textStyles (vla-get-TextStyles doc))
  88.     (setq txtStyleObj (vla-Add textStyles "New_Textstyle"))
  89.     (alert (strcat (vla-get-Name txtStyleObj) " has been added."
  90.                     "\nHeight: " (rtos (vla-get-Height txtStyleObj) 2 2)
  91.                     "\nWidth: " (rtos (vla-get-Width txtStyleObj) 2 2)
  92.            )
  93.     )
  94.    
  95. ;; ADDVIEW:
  96.     ;; Create a view named "New_View" in current drawing
  97.    
  98.     ;; Add the view to the views collection
  99.     (setq views (vla-get-Views doc))
  100.     (setq viewObj (vla-Add views "New_View"))
  101.     (alert (strcat (vla-get-Name viewObj) " has been added."
  102.                     "\nHeight: " (rtos (vla-get-Height viewObj) 2 2)
  103.                     "\nWidth: " (rtos (vla-get-Width viewObj) 2 2)
  104.            )
  105.     )
  106.    
  107. ;; ADDVIEWPORT:
  108.     ;; Create a viewport named "New_Viewport" in current drawing
  109.    
  110.     ;; Add the viewport to the viewports collection
  111.     (setq viewports (vla-get-Viewports doc))
  112.     (setq vportObj (vla-Add viewports "New_Viewport"))
  113.     (alert (strcat (vla-get-Name vportObj) " has been added."
  114.                     "\nGridOn Status: " (if (= (vla-get-GridOn vportObj) :vlax-true) "1" "0")
  115.                     "\nOrthoOn Status: " (if (= (vla-get-OrthoOn vportObj) :vlax-true) "1" "0")
  116.                     "\nSnapOn Status: " (if (= (vla-get-SnapOn vportObj) :vlax-true) "1" "0")
  117.            )
  118.     )  
  119.    
  120. ;; ADDUCS:
  121.     ;; Create a UCS named "New_UCS" in current drawing
  122.   
  123.     ;; Define the UCS
  124.     (setq origin (vlax-3d-point 4 5 3)
  125.           xAxisPnt (vlax-3d-point 5 5 3)
  126.           yAxisPnt (vlax-3d-point 4 6 4))
  127.   
  128.     ;; Add the UCS to the UserCoordinatesSystems collection
  129.     (setq UCSs (vla-get-UserCoordinateSystems doc))
  130.     (setq ucsObj (vla-Add UCSs origin xAxisPnt yAxisPnt "New_UCS"))
  131.     (alert (strcat (vla-get-Name ucsObj) " has been added."
  132.                     "\nOrigin: " (rtos (vlax-safearray-get-element (vlax-variant-value (vla-get-Origin ucsObj)) 0) 2 2) ", "
  133.                                  (rtos (vlax-safearray-get-element (vlax-variant-value (vla-get-Origin ucsObj)) 1) 2 2) ", "
  134.                                  (rtos (vlax-safearray-get-element (vlax-variant-value (vla-get-Origin ucsObj)) 2) 2 2)
  135.            )
  136.     )  

  137. ;; ADDMATERIAL:
  138.     ;; Creates a material named "New_UCS" in the current drawing  
  139.     (setq oMaterials (vla-get-Materials doc))
  140.     (setq oMaterial (vla-Add oMaterials "TestMaterial"))
  141.     (vla-put-Description oMaterial "This example demonstrates how to add a material to a database.")
  142.     (vla-put-ActiveMaterial doc oMaterial)

  143.     ;; Display information about the material
  144.     (alert (strcat (vla-get-Name oMaterial) " has been added."
  145.                     "\nName: " (vla-get-Name oMaterial)
  146.                     "\nDescription: " (vla-get-Description oMaterial)
  147.            )
  148.     )
  149. )
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 604个

财富等级: 财运亨通

发表于 2014-12-14 19:50:06 来自手机 | 显示全部楼层
向楼主学习
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2014-12-14 20:12:20 | 显示全部楼层
今天热闹,停不下来的节奏。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 6468个

财富等级: 富甲天下

发表于 2014-12-25 17:47:38 | 显示全部楼层
第一个不用回复的每日一码。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1094个

财富等级: 财源广进

发表于 2021-8-3 00:22:32 | 显示全部楼层
感谢楼主分享Example Add Method
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-27 06:42 , Processed in 0.169215 second(s), 36 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表