Block References - Found a Quicker Way!

Discussion in 'AutoCAD' started by MLL, Jul 16, 2004.

  1. MLL

    MLL Guest

    I made a new discovery so I thought I would share it with everyone. I am inserting a block, which exists in another drawing, into my current drawing. I am adding this block to the drawing several times at different locations. After I define the block reference with the entire path to the other drawing one time, the next time I insert the same block again I do not need the entire path, I just need the block name which is the filename prefix (dwg name without extension). This is where serious time savings takes place. Using the entire path every time makes it run 3 times slower! I attached a code snippet using the faster method. Enjoy!
     
    MLL, Jul 16, 2004
    #1
  2. MLL

    Joe Sutphin Guest

    I couldn't help myself [of course I didn't get a chance to test this].

    Public Function Insert_Shape_As_Block(Shape As String, InsertionPoint() As
    Double, dblScale As Double, dblRot As Double) As AcadBlockReference
    Dim BlockRefObj As AcadBlockReference

    'symbol drawings "CCI_SymP01.dwg", "CCI_SymP02.dwg",
    "CCI_SymP03.dwg",..."CCI_SymP10.dwg"
    Shape = Format(Shape, "00")

    'Check if the Block Already exists in the Drawing
    For Each BlockRefObj In ThisDrawing.Blocks
    If BlockRefObj.Name = "CCI_SymP" & Shape Then
    Set Insert_Shape_As_Block =
    ThisDrawing.ModelSpace.InsertBlock(InsertionPoint, "CCI_SymP" & Shape,
    dblScale, dblScale, dblScale, dblRot)
    Exit Function
    End If
    Next BlockRefObj

    'the block does NOT exist so use the entire path to add the block from the
    other drawing into this drawing
    Set Insert_Shape_As_Block =
    ThisDrawing.ModelSpace.InsertBlock(InsertionPoint, "CCI_SymP" & Shape &
    ".dwg", dblScale, dblScale, dblScale, dblRot)
    End Function

    Joe
    --

    inserting a block, which exists in another drawing, into my current drawing.
    I am adding this block to the drawing several times at different locations.
    After I define the block reference with the entire path to the other drawing
    one time, the next time I insert the same block again I do not need the
    entire path, I just need the block name which is the filename prefix (dwg
    name without extension). This is where serious time savings takes place.
    Using the entire path every time makes it run 3 times slower! I attached a
    code snippet using the faster method. Enjoy!
     
    Joe Sutphin, Jul 16, 2004
    #2
  3. MLL

    x Guest

    Using the entire path every time makes it run 3 times slower!
    I believe it: you have redefined that block everytime! Using the entire
    path, you make autocad read the Wblock from HD and to re-define the block
    stored in the drawing everytime
     
    x, Jul 16, 2004
    #3
  4. If this is about how to get your code to run faster, then one thing you can
    do
    to speed it up a bit, is to use the Item() method of the Blocks collection,
    and
    just trap the error that occurs if the block is not in the drawing:

    Dim ABlock As AcadBlock
    Dim AName As String
    AName = "SomeBlockName"
    On Error Resume Next
    Set ABlock = ThisDrawing.Blocks(AName)
    If Err then ' block was not found
    Err.Clear
    AName = "d:\path\filename.dwg" ' insert from file
    End If
    On Error Goto 0





    inserting a block, which exists in another drawing, into my current drawing.
    I am adding this block to the drawing several times at different locations.
    After I define the block reference with the entire path to the other drawing
    one time, the next time I insert the same block again I do not need the
    entire path, I just need the block name which is the filename prefix (dwg
    name without extension). This is where serious time savings takes place.
    Using the entire path every time makes it run 3 times slower! I attached a
    code snippet using the faster method. Enjoy!
     
    Tony Tanzillo, Jul 16, 2004
    #4
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.