How to attach a block outline to the crosshair.

Discussion in 'AutoCAD' started by joanne, Oct 19, 2004.

  1. joanne

    joanne Guest

    Hi,

    When using the InsertBlock method, is there any way to attach the block to the crosshair for picking the insert point ? Is it possible to use VBA to let an object follow the crosshair like using the command -insert. Thanks!

    Joan
     
    joanne, Oct 19, 2004
    #1
  2. joanne

    AKS Guest

    There is a method to do this as demonstrated below, but be
    forewarned that the technique was developed out of total
    ignorance and would probably cause the more informed to
    gasp in contempt. The example is coded to function only in modelspace.

    Option Explicit
    Sub PlacePrntArea()
    Dim blockRefObj As AcadBlockReference
    Dim returnPnt As Variant
    Dim strPnt As String
    Dim PrntWidthX As Double
    Dim PrntHeightY As Double
    Dim OrthoState As Variant
    Dim PScale As Double
    PScale = 96
    ThisDrawing.ActiveLayout.GetPaperSize PrntWidthX, PrntHeightY
    PrntHeightY = PScale * PrntHeightY / 24.5
    PrntWidthX = PScale * PrntWidthX / 24.5
    Dim sysVarName As String
    sysVarName = "ORTHOMODE"
    OrthoState = ThisDrawing.GetVariable(sysVarName)
    ThisDrawing.SetVariable (sysVarName), 0
    On Error GoTo BugOut
    CreatePrntAreaBlk
    ' Return a point to locate printarea within the current view field
    returnPnt = ThisDrawing.Utility.GetPoint(, "Tap once in the view from which to plot.")
    strPnt = CStr(returnPnt(0)) & "," & CStr(returnPnt(1)) & "," & CStr(returnPnt(2)) & vbCr
    Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(returnPnt, "PrntAreaBlk", PrntWidthX, PrntHeightY, 1#, 0)
    ThisDrawing.SendCommand ("M" & vbCr & "L" & vbCr & vbCr & strPnt)
    BugOut:
    ThisDrawing.SetVariable (sysVarName), OrthoState
    End Sub

    Private Sub CreatePrntAreaBlk()
    Dim blkObj As AcadBlock
    Dim insPnt(0 To 2) As Double
    Dim plineObj As AcadLWPolyline
    Dim pts(0 To 9) As Double
    Dim blockRefObj As AcadBlockReference
    insPnt(0) = 0#: insPnt(1) = 0#: insPnt(2) = 0#
    Set blkObj = ThisDrawing.Blocks.Add(insPnt, "PrntAreaBlk")
    pts(0) = 0: pts(1) = 0
    pts(2) = 0: pts(3) = 1
    pts(4) = 1: pts(5) = 1
    pts(6) = 1: pts(7) = 0
    pts(8) = 0: pts(9) = 0
    Set plineObj = blkObj.AddLightWeightPolyline(pts)
    plineObj.color = 1
    End Sub
     
    AKS, Oct 19, 2004
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.