VBA to drop specific cell

I'm using a macro to insert a specific cell with CadInputQueue.SendKeyin "active cell cellname"

How can I drop this cell into it´s components immidiately after it is placed? Should I use CadInputQueue.SendCommand "DROP ELEMENT" in some way?

Parents
  • It ends up with a Cache contains no valid elements error.

     The code now looks like this:

     

    Sub SkruvM24()

    Dim oLastElem As Element

    CadInputQueue.SendKeyin "attach library R:\Bentley\Workspace\Standards\Cell\Mskruv.cel"

    CadInputQueue.SendKeyin "active cell M24"

    Set oLastElem = ActiveModelReference.GraphicalElementCache.GetLastValidElement

    CadInputQueue.SendCommand "drop element"

    CadInputQueue.SendKeyin "XY=0;selview all"

    RedrawAllViews

    End Sub

    The Set oLastElem = ActiveModelReference.GraphicalElementCache.GetLastValidElement line gets hilighted when I debug.
Reply
  • It ends up with a Cache contains no valid elements error.

     The code now looks like this:

     

    Sub SkruvM24()

    Dim oLastElem As Element

    CadInputQueue.SendKeyin "attach library R:\Bentley\Workspace\Standards\Cell\Mskruv.cel"

    CadInputQueue.SendKeyin "active cell M24"

    Set oLastElem = ActiveModelReference.GraphicalElementCache.GetLastValidElement

    CadInputQueue.SendCommand "drop element"

    CadInputQueue.SendKeyin "XY=0;selview all"

    RedrawAllViews

    End Sub

    The Set oLastElem = ActiveModelReference.GraphicalElementCache.GetLastValidElement line gets hilighted when I debug.
Children
  • Hi again

     Try this code instead:

    Sub SkruvM24()

    Dim oCellLib As String
    Dim oCellName As String
    Dim oMessage As CadInputMessage
    Dim pPoint As Point3d
    Dim oLastElem As Element

    ' Cell library to attach
    oCellLib = "R:\Bentley\Workspace\Standards\Cell\Mskruv.cel"

    'Cell name
    oCellName = "M24"

    'Attach a cell library
    AttachCellLibrary oCellLib

    ' Set a cell avtive
    ActiveSettings.CellName = oCellName

    ShowPrompt ("Place Cell")

    CadInputQueue.SendCommand "PLACE CELL"

    Set oMessage = CadInputQueue.GetInput(msdCadInputTypeDataPoint, msdCadInputTypeReset)

    If oMessage.InputType = msdCadInputTypeDataPoint Then

    pPoint = oMessage.point

    ElseIf oMessage.InputType = msdCadInputTypeReset Then

    CommandState.StartDefaultCommand

    End

    End If

    CadInputQueue.SendDataPoint pPoint, 1

    CadInputQueue.SendReset

    CadInputQueue.SendCommand "UPDATE VIEW EXTENDED 1"

    Set oLastElem = ActiveModelReference.GraphicalElementCache.GetLastValidElement

    CadInputQueue.SendCommand "drop element"

    CadInputQueue.SendDataPoint pPoint

    CadInputQueue.SendDataPoint pPoint

    ActiveModelReference.UnselectAllElements

    RedrawAllViews

    CommandState.StartDefaultCommand

    End Sub