CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2024 开发者帮助

CreateContent 方法 (ActiveX)

2024-5-18 19:07| 发布者: admin| 查看: 13| 评论: 0|原作者: admin|来自: AutoCAD

CreateContent 方法 (ActiveX)

在单元格中创建新内容。

支持的平台:仅限 Windows

签名

VBA:

RetVal = object.CreateContent(nRow, nCol, nIndex)
对象

类型: 表格

此方法应用到的对象。

nRow(n行)

访问:仅输入

类型:

要检查的单元格的行号。

nCol (英语:nCol)

访问:仅输入

类型:

要检查的单元格的列号。

n索引

访问:仅输入

类型:

用于创建新上下文的索引。

返回值 (RetVal)

类型:

已创建内容的 ID。

言论

没有其他评论。

例子

VBA:

Sub Example_ContentChange()
    ' This example adds a table in model space
    ' and manipulates its contents
    
    ' Note: One content is created for each cell by default;
    ' this function need to be called only to create additional contents.
    
    Dim MyModelSpace As AcadModelSpace
    Set MyModelSpace = ThisDrawing.ModelSpace
    Dim pt(2) As Double
    Dim MyTable As IAcadTable
    Dim sID As Long
    Dim newSID As Long
    Dim row As Long
    Dim col As Long
    
    ' Creates arbitrary cell points to check
    row = 2
    col = 2
    
    ' Creates the table with an arbitrary number of cells
    Set MyTable = MyModelSpace.AddTable(pt, 5, 5, 10, 30)
    MyTable.SetTextHeight acDataRow, 1
    MyTable.SetTextHeight acHeaderRow, 1
    MyTable.SetTextHeight acTitleRow, 1

    ZoomExtents

    If MyTable.IsEmpty(row, col) Then
        If MyTable.IsContentEditable(row, col) Then
            MsgBox "There is no content in the cell, but it is editable"
        End If
    End If

    ' Create some content in an arbitrary cell
    sID1 = MyTable.CreateContent(row, col, 0)
    sID2 = MyTable.CreateContent(row, col, 1)
    MyTable.SetTextString row, col, sID1, "Value1"
    MyTable.SetTextString row, col, sID2, "Value2"
    MyTable.Update
    
    MsgBox "The content IDs are " & vbLf & _
           "sID1: " & MyTable.GetTextString(row, col, sID1) & vbLf & _
           "sID2: " & MyTable.GetTextString(row, col, sID2)
 
    ' Move the content to another index
    MyTable.MoveContent row, col, sID2, sID1
    MyTable.Update
    MsgBox "Content order changed"
    
    MsgBox "The content IDs are " & vbLf & _
           "sID1: " & MyTable.GetTextString(row, col, sID1) & vbLf & _
           "sID2: " & MyTable.GetTextString(row, col, sID2)
    
    ' Check that the content has been deleted
    MyTable.DeleteContent row, col
    MyTable.Update
    MsgBox "Content removed"
    
    If MyTable.IsEmpty(row, col) Then
        If MyTable.IsContentEditable(row, col) Then
            MsgBox "There is no content in the cell, but it is editable"
        End If
    End If
End Sub

可视化 LISP:

(vl-load-com)
(defun c:Example_ContentChange()
    ;; This example adds a table in model space
    ;; and manipulates its contents
    (setq acadObj (vlax-get-acad-object)
          doc (vla-get-ActiveDocument acadObj))
    
    ;; Note: One content is created for each cell by default;
    ;; this function need to be called only to create additional contents.
    
    (setq pt (vlax-3d-point 0 0 0))
    
    ;; Creates arbitrary cell points to check
    (setq row 2
          col 2)
    
    ;; Creates the table with an arbitrary number of cells
    (setq modelSpace (vla-get-ModelSpace doc))   
    (setq MyTable (vla-AddTable modelSpace pt 5 5 10 30))
    (vla-SetTextHeight MyTable acDataRow 1)
    (vla-SetTextHeight MyTable acHeaderRow 1)
    (vla-SetTextHeight MyTable acTitleRow 1)
  
    (vla-Regen doc :vlax-true)
    (vla-ZoomExtents acadObj)

    (if (= (vla-IsEmpty MyTable row col) :vlax-true)
        (if (= (vla-IsContentEditable MyTable row col) :vlax-true)
            (alert "There is no content in the cell, but it is editable")
        )
    )

    ;; Create some content in an arbitrary cell
    (setq sID1 (vla-CreateContent MyTable row col 0))
    (setq sID2 (vla-CreateContent MyTable row col 1))
    (vla-SetTextString MyTable row col sID1 "Value1")
    (vla-SetTextString MyTable row col sID2 "Value2")
    (vla-Regen doc :vlax-true)

    (alert (strcat "The content IDs are "
                   "\nsID1: " (vla-GetTextString MyTable row col sID1)
                   "\nsID2: " (vla-GetTextString MyTable row col sID2)))
 
    ;; Move the content to another index
    (vla-MoveContent MyTable row col sID2 sID1)
    (vla-Regen doc :vlax-true)
    (alert "Content order changed")

    (alert (strcat "The content IDs are "
                   "\nsID1: " (vla-GetTextString MyTable row col sID1)
                   "\nsID2: " (vla-GetTextString MyTable row col sID2)))

    ;  Check that the content has been deleted
    (vla-DeleteContent MyTable row col)
    (vla-Regen doc :vlax-true)
    (alert "Content removed")
    
    (if (= (vla-IsEmpty MyTable row col) :vlax-true)
        (if (= (vla-IsContentEditable MyTable row col) :vlax-true)
            (alert "There is no content in the cell, but it is editable")
        )
    )
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-6-27 16:20

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部