need some starts help

Discussion in 'AutoCAD' started by Joshua Verdin, May 19, 2004.

  1. I need to know how to get the insert point of a block that hax already been
    inserted. I cant seem to figure out which to use Acadblockref or block.item?
    The obj browser wasn't much help.
     
    Joshua Verdin, May 19, 2004
    #1
  2. You're going to use the InsertionPoint property of the AcadBlockReference
    object. Look up the example code for InsertionPoint -- it's for a text
    object but the principle is the same. To reverse it and get the insert
    point out, you'll have to use a Variant variable.


    HTH,
    James
     
    James Belshan, May 19, 2004
    #2
  3. :)
    Wow, James I see your right on top of things man. But do you mind giveing me
    some more help?

    I am a VB programer but not fimilar with this API I am having just some
    trouble obtaining want I want. I got the example and that helps some but
    instead of a text object I need a block object right? which i dont seem to
    be able to access. Here's what I got.......

    MsgBox ThisDrawing.Blocks.Count
    MsgBox ThisDrawing.Blocks.ObjectID
    MsgBox ThisDrawing.Blocks.ObjectName
    MsgBox ThisDrawing.Blocks.OwnerID
    MsgBox ThisDrawing.Blocks.Handle

    Dim myblock As AcadBlockReference
    Dim varIpoint As Variant
    myblock = ??????????????????

    varIpoint = myblock.InsertionPoint
    MsgBox myblock.InsertionPoint

    problem is I don't know what to set myBlock to? I don't think "thisdrawing"
    is the right class to look under is it?


    PS: I like to use msgbox to test returns alot!
     
    Joshua Verdin, May 19, 2004
    #3
  4. Joshua Verdin

    Mark Propst Guest

    A "Block" is the definition of the object.
    An "Insert" or "BlockReference" is an instance of the definition in model or
    paperspace.

    Depends what block(insert) you want to examine.
    Is it every insert or just ones with a certain name?
    You might want to review the Acad object model in the help files.
    You can either iterate every object in model and or paper space to get the
    inserts
    Dim oBlkRef as AcadBlockReference
    Dim oEnt as AcadEntity

    For Each oEnt in oModelSpace
    if Type of oent is AcadBlockReference then
    Set oBlkRef = oEnt
    msgbox oBlkRef.Name
    whatever

    or you can use a filtered selection set.
    'get filtered set - review help on filtering
    'then once you have the selection
    For each oBlkRef in filteredSet1
    msgbox oBlkRef.name
    whatever
     
    Mark Propst, May 19, 2004
    #4
  5. Joshua Verdin

    MNafo Guest

    You can get your block variable by direct select on screen for example:
    Dim BasPnt As Variant
    ThisDrawing.Utility.GetEntity myblock , BasPnt, "Select a block"
    Now, myblock is referencing the selected block in the drawing.
    You can also obtain a reference to this block by searching it:
    Set doc = ThisDrawing.Application.ActiveDocument
    Set MSpace = doc.ModelSpace
    Dim elem As AcadEntity
    For Each elem In MSpace
    With elem
    If StrComp(.EntityName, "AcDbBlockReference", 1) = 0 Then
    'or .Name="Your block name..." then
    Set myblock=elem
    exit for
    End If
    End With
    Next elem
    MsgBox myblock.InsertionPoint is not correct because this variable is a 3D point, an array of doubles. You can also see this by adding this variable with "Add watch" command, at runtime. I always use this method to see the type of variables and what they contains.
    Print your variable like this:
    MsgBox "x: " & myblock.InsertionPoint(0) & " y: " & myblock.InsertionPoint(1) & " z: " & myblock.InsertionPoint(2)
    Hope this help...
     
    MNafo, May 19, 2004
    #5
  6. Thanks guys this should be enough to get me started....
     
    Joshua Verdin, May 19, 2004
    #6
  7. Joshua Verdin

    bcoward Guest

    Joshua,

    You write.."problem is I don't know what to set myBlock to? I don't think "thisdrawing" is the right class to look under is it?

    To save you some time and let the swelling go down on your head I'd advise that you take time and review the object model for the new environment you've stepped into. If you've been doing VB a while, written your own VBA object model, or been in the Dot Net arena you know that within any new environment resides a base class structure. Take some time and envelope yourself within the AutoCAD object model and you'll save yourself weeks of unproductive effort in hours of time.

    Just my .02

    Regards,

    Bob Coward
    CADS, Inc

    800-366-0946
     
    bcoward, May 19, 2004
    #7
  8. Bob,

    Every class structure is different, this is true. Unfortunately, I have an
    overwhelming amount work and school. I am sure the object model
    documentation is an absolutely exhilarating piece of literature, lol.
    Unfortunately I have not had the time or the concentration which is minimal
    and often over never there at all. I appreciate the suggestion and will read
    it ASAP.

    Thanks for the help.... ;-)

    "thisdrawing" is the right class to look under is it?
    that you take time and review the object model for the new environment
    you've stepped into. If you've been doing VB a while, written your own VBA
    object model, or been in the Dot Net arena you know that within any new
    environment resides a base class structure. Take some time and envelope
    yourself within the AutoCAD object model and you'll save yourself weeks of
    unproductive effort in hours of time.
     
    Joshua Verdin, May 19, 2004
    #8
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.