Solved! Go to solution

Register a class of objects

Hello all,

Is it possible to register own class of objects (set of primitives) and then to add objects of this class to SE draft document?

Kind regards, Pavel.

Accepted by topic author PavelD
‎04-12-2016 04:28 AM

Re: Register a class of objects

[ Edited ]

You don't need to register new objects (and I even don't know, if its possible) for your purpose. You should look at the Block object, which allows to create a Block object consisting of multiple primitves and then adding BlockOccurrences to your draft document.


Here is some sample code:

    ' DFT: Create a new block, if it does not exist in the document
    ' Check, if the block 'eval' already exists in the current document
    Dim objDoc As DraftDocument = objApp.ActiveDocument
    Dim blockExists As Boolean = False
    Dim objBlock As Block = Nothing
    For Each objBlock In objDoc.Blocks
      If objBlock.Name = "eval" Then
        blockExists = True
        Exit For
      End If
    ' Create a new block, if it does not exist
    If Not blockExists Then
      ' (1) Start the block creation
      objBlock = objDoc.Blocks.Add("eval", 0.026, 0) ' Block origin is lower right corner
      ' (1.1) Add all geometric primitives to the block
      ' Two rectangles on top of each other:
      ' Upper Rect: 26 x 6 mm (with text in it)
      ' Lower Rect: 26 x 10 mm (with label in it)
      Dim objLines As Lines2d = objBlock.DefaultView.Lines2d
      Dim L1 As Line2d = objLines.AddBy2Points(0, 0, 0.026, 0)
      Dim L2 As Line2d = objLines.AddBy2Points(0.026, 0, 0.026, 0.01)
      Dim L3 As Line2d = objLines.AddBy2Points(0.026, 0.01, 0, 0.01)
      Dim L4 As Line2d = objLines.AddBy2Points(0, 0.01, 0, 0)
      Dim L5 As Line2d = objLines.AddBy2Points(0.026, 0.01, 0.026, 0.016)
      Dim L6 As Line2d = objLines.AddBy2Points(0.026, 0.016, 0, 0.016)
      Dim L7 As Line2d = objLines.AddBy2Points(0, 0.016, 0, 0.01)
      ' (1.2) Create relations between the primitives
      Dim objRels As Relations2d = objBlock.DefaultView.Relations2d
      ' (1.2.1) Connect the end points of the lines
      objRels.AddKeypoint(L1, igLineEnd, L2, igLineStart)
      objRels.AddKeypoint(L2, igLineEnd, L3, igLineStart)
      objRels.AddKeypoint(L3, igLineEnd, L4, igLineStart)
      objRels.AddKeypoint(L4, igLineEnd, L1, igLineStart)
      objRels.AddKeypoint(L2, igLineEnd, L5, igLineStart)
      objRels.AddKeypoint(L5, igLineEnd, L6, igLineStart)
      objRels.AddKeypoint(L6, igLineEnd, L7, igLineStart)
      objRels.AddKeypoint(L7, igLineEnd, L4, igLineStart)
      ' (1.2.2) Make some lines horizontal
      ' (1.2.3)Make some lines vertical
      ' (1.3) Add a text to the block
      Dim objTextBox As TextBox = objBlock.DefaultView.TextBoxes.AddByTwoPoints(0, 0.01, 0, 0.026, 0.016, 0)
      objTextBox.Text = "NOTE EXAMEN"
      objTextBox.HorizontalAlignment = TextHorizontalAlignmentConstants.igTextHzAlignCenter
      ' (1.4) Add a label to the block
      objBlock.DefaultView.BlockLabels.Add("Evaluation", "x", "Evaluation Note", 0.013, 0.005, SolidEdgeDraft.BlockLabelOriginLocationConstants.igBlockLabelMiddleCenter, True, False, True, True, 0)

      ' (2) Add an occurrence of the block
      Dim objSheet As Sheet = objDoc.ActiveSheet
      Dim objBlockOcc As BlockOccurrence = objSheet.BlockOccurrences.Add("eval", 0.25, 0.32)
      ' (3) Change the label text
      objBlockOcc.BlockLabelOccurrences.Item(1).value = "18/20"
    End If

Re: Register a class of objects

Thank you for reply!
Am I right that for control and changing a Block I should use BlockOccurrence Object methods: GetOrigin, Rotate, Scale etc.?

Re: Register a class of objects


The properties and methods of the BlockOccurrence object define the appearance of each individual instance of a block.

Changing the block itself will affect ALL instances (BlockOccurrence) of the block.

Re: Register a class of objects

Thank you!