| 
×
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册 
     (vl-load-com)
(defun c:Example_Add()
    ;; This example adds a block, dictionary, dimension style,
    ;; group, layer, registered application, selection set,
    ;; textstyle, view, viewport and UCS using the Add method.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
  
;; ADDBLOCK:
    ;; Create a new block called "New_Block"
    ;; Define the insertion point
    (setq insertionPnt (vlax-3d-point 0 0 0))
    
    ;; Add the block to the blocks collection
    (setq blocks (vla-get-Blocks doc))
    (setq blockObj (vla-Add blocks insertionPnt "New_Block"))
    (alert (strcat (vla-get-Name blockObj) " has been added."
                    "\nOrigin: " (rtos (vlax-safearray-get-element (vlax-variant-value (vla-get-Origin blockObj)) 0) 2 2) ", "
                                 (rtos (vlax-safearray-get-element (vlax-variant-value (vla-get-Origin blockObj)) 1) 2 2) ", "
                                 (rtos (vlax-safearray-get-element (vlax-variant-value (vla-get-Origin blockObj)) 2) 2 2)
           )
    )
    
;; ADDDICTIONARY:
    ;; Create a new dictionary called "New_Dictionary"
    ;; Add the dictionary to the dictionaries collection
    (setq dictionaries (vla-get-Dictionaries doc))
    (setq dictObj (vla-Add dictionaries "New_Dictionary"))
    (alert (strcat (vla-get-Name dictObj) " has been added."))
;; ADDDIMSTYLE:
    ;; Create a new dimension style called "New_Dimstyle" in current drawing
    
    ;; Add the dimstyle to the dimstyles collection
    (setq dimStyles (vla-get-DimStyles doc))
    (setq dimStyleObj (vla-Add dimStyles "New_Dimstyle"))
    (alert (strcat (vla-get-Name dimStyleObj) " has been added."))
    
;; ADDGROUP:
    ;; Create a new group called "New_Group" in current drawing
    
    ;; Add the group to the groups collection
    (setq groups (vla-get-Groups doc))
    (setq groupObj (vla-Add dimStyles "New_Group"))
    (alert (strcat (vla-get-Name groupObj) " has been added."))
    
;; ADDLAYER:
    ;; This example creates a new layer called "New_Layer"
    
    ;; Add the layer to the layers collection
    (setq layers (vla-get-Layers doc))
    (setq layerObj (vla-Add layers "New_Layer"))
    
    ;; Make the new layer the active layer for the drawing
    (vla-put-ActiveLayer doc layerObj)
    
    ;; Display the status of the new layer
    (alert (strcat (vla-get-Name layerObj) " has been added."
                   "\nLayerOn Status: " (if (= (vla-get-LayerOn layerObj) :vlax-true) "1" "0")
                   "\nFreeze Status: " (if (= (vla-get-Freeze layerObj) :vlax-true) "1" "0")
                   "\nLock Status: "  (if (= (vla-get-Lock layerObj) :vlax-true) "1" "0")
                   "\nColor: " (itoa (vla-get-Color layerObj))
           )
    )
    
;; ADDREGISTEREDAPP:
    ;; Create a registered application named "New_RegApp" in current drawing
    
    ;; Add the registered application to the registered applications collection
    (setq regApps (vla-get-RegisteredApplications doc))
    (setq regAppObj (vla-Add regApps "New_RegApp"))
    (alert (strcat (vla-get-Name regAppObj) " has been added."))
;; ADDSELECTIONSET:
    ;; Create a selectionset named "New_SelectionSet" in current drawing
    
    ;; Add the selection set to the selection sets collection
    (setq ssets (vla-get-SelectionSets doc))
    (setq ssetObj (vla-Add ssets "New_SelectionSet"))
    (alert (strcat (vla-get-Name ssetObj) " has been added."
                    "\nThe number of items in the selection set is " (itoa (vla-get-Count ssetObj))
           )
    )
    
;; ADDTEXTSTYLE:
    ;; Create a textstyle named "New_Textstyle" in current drawing
    
    ;; Add the textstyle to the textstyles collection
    (setq textStyles (vla-get-TextStyles doc))
    (setq txtStyleObj (vla-Add textStyles "New_Textstyle"))
    (alert (strcat (vla-get-Name txtStyleObj) " has been added."
                    "\nHeight: " (rtos (vla-get-Height txtStyleObj) 2 2)
                    "\nWidth: " (rtos (vla-get-Width txtStyleObj) 2 2)
           )
    )
    
;; ADDVIEW:
    ;; Create a view named "New_View" in current drawing
    
    ;; Add the view to the views collection
    (setq views (vla-get-Views doc))
    (setq viewObj (vla-Add views "New_View"))
    (alert (strcat (vla-get-Name viewObj) " has been added."
                    "\nHeight: " (rtos (vla-get-Height viewObj) 2 2)
                    "\nWidth: " (rtos (vla-get-Width viewObj) 2 2)
           )
    )
    
;; ADDVIEWPORT:
    ;; Create a viewport named "New_Viewport" in current drawing
    
    ;; Add the viewport to the viewports collection
    (setq viewports (vla-get-Viewports doc))
    (setq vportObj (vla-Add viewports "New_Viewport"))
    (alert (strcat (vla-get-Name vportObj) " has been added."
                    "\nGridOn Status: " (if (= (vla-get-GridOn vportObj) :vlax-true) "1" "0")
                    "\nOrthoOn Status: " (if (= (vla-get-OrthoOn vportObj) :vlax-true) "1" "0")
                    "\nSnapOn Status: " (if (= (vla-get-SnapOn vportObj) :vlax-true) "1" "0")
           )
    )  
    
;; ADDUCS:
    ;; Create a UCS named "New_UCS" in current drawing
  
    ;; Define the UCS
    (setq origin (vlax-3d-point 4 5 3)
          xAxisPnt (vlax-3d-point 5 5 3)
          yAxisPnt (vlax-3d-point 4 6 4))
  
    ;; Add the UCS to the UserCoordinatesSystems collection
    (setq UCSs (vla-get-UserCoordinateSystems doc))
    (setq ucsObj (vla-Add UCSs origin xAxisPnt yAxisPnt "New_UCS"))
    (alert (strcat (vla-get-Name ucsObj) " has been added."
                    "\nOrigin: " (rtos (vlax-safearray-get-element (vlax-variant-value (vla-get-Origin ucsObj)) 0) 2 2) ", "
                                 (rtos (vlax-safearray-get-element (vlax-variant-value (vla-get-Origin ucsObj)) 1) 2 2) ", "
                                 (rtos (vlax-safearray-get-element (vlax-variant-value (vla-get-Origin ucsObj)) 2) 2 2)
           )
    )  
;; ADDMATERIAL:
    ;; Creates a material named "New_UCS" in the current drawing  
    (setq oMaterials (vla-get-Materials doc))
    (setq oMaterial (vla-Add oMaterials "TestMaterial"))
    (vla-put-Description oMaterial "This example demonstrates how to add a material to a database.")
    (vla-put-ActiveMaterial doc oMaterial)
    ;; Display information about the material
    (alert (strcat (vla-get-Name oMaterial) " has been added."
                    "\nName: " (vla-get-Name oMaterial)
                    "\nDescription: " (vla-get-Description oMaterial)
           )
    )
)
 |