Results 1 to 10 of 10

Thread: Search entire drawing for block references at once

  1. #1
    All AUGI, all the time
    Join Date
    2003-10
    Posts
    706
    Login to Give a bone
    0

    Default Search entire drawing for block references at once

    Do I have to search Model Space and search Paper Space seperately in order to find a block reference in the current drawing or is there a way to search both objects (model space/paper space) at the same time? Right now I use "for each ObjectID in ...BlockTableRecord.ModelSpace...." and it works good but I then need to do the exact same code for Paperspace. Is there a better, easier way?

    Thanks in advance

  2. #2
    AUGI Addict
    Join Date
    2015-12
    Posts
    2,095
    Login to Give a bone
    0

    Default Re: Search entire drawing for block references at once

    Short of selection sets, I don't think so. But it shouldn't be too bad with some short-circuit logic to control how far down into the testing each loop goes.

  3. #3
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Search entire drawing for block references at once

    You could always use LISP to set a global variable, and call your .NET command method passing the variable.

    Code:
    (defun c:FOO ()
      (if (setq *ss* (ssget "_x" '((0 . "INSERT") (2 . "BlockName"))))
        (progn
          (if (not YourDotNetCommand)
            (command "._netload" "FilePath\\YourDotNetCommand"))
          (YourDotNetCommand *ss*)))
      (princ))
    Hope this helps!
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  4. #4
    Active Member
    Join Date
    2009-08
    Posts
    93
    Login to Give a bone
    0

    Default Re: Search entire drawing for block references at once

    You can use the block's BlockTableRecord.GetBlockReferenceIds method which will return an ObjectIdCollection of the BlockReferences ObjectIds

    Here is simple example getting all of the blockreferences of a block named "C" and printing to the command line if it is in Model or paper.



    Code:
            <CommandMethod("GetBlockRefs")> _
            Public Sub GetBlockRefs()
    
                Dim doc As Document = Application.DocumentManager.MdiActiveDocument
                Dim db As Database = doc.Database
                Dim ed As Editor = doc.Editor
    
                Using trx As Transaction = db.TransactionManager.StartTransaction()
    
                    Dim bt As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
                    Dim btr As BlockTableRecord = bt("C").GetObject(OpenMode.ForRead)
                    Dim objIds As ObjectIdCollection = btr.GetBlockReferenceIds(True, False)
    
                    For Each objId As ObjectId In objIds
    
                        Dim ent As Entity = objId.GetObject(OpenMode.ForRead)
                        Dim btrOwner As BlockTableRecord = ent.BlockId.GetObject(OpenMode.ForRead)
                        ed.WriteMessage(vbCrLf & btrOwner.Name)
    
                    Next
    
                    trx.Commit()
    
                End Using
    
            End Sub

  5. #5
    Active Member
    Join Date
    2009-08
    Posts
    93
    Login to Give a bone
    0

    Default Re: Search entire drawing for block references at once

    Who is "christopher.259266" where did that name come from?

  6. #6
    All AUGI, all the time
    Join Date
    2003-10
    Posts
    706
    Login to Give a bone
    0

    Default Re: Search entire drawing for block references at once

    Quote Originally Posted by christopher.259266 View Post
    Who is "christopher.259266" where did that name come from?
    nice plug BTW ...and more importantly, thanks for the code. I haven't tried it yet but it appears as if it grabs any certain block reference named "C" regardless of its space.. right? Can I assume that once you "have it" you can manipulate its dynamic and attribute properties once "obtained"?

  7. #7
    Active Member
    Join Date
    2009-08
    Posts
    93
    Login to Give a bone
    0

    Default Re: Search entire drawing for block references at once

    Quote Originally Posted by Coolmo View Post
    nice plug BTW ...and more importantly, thanks for the code. I haven't tried it yet but it appears as if it grabs any certain block reference named "C" regardless of its space.. right? Can I assume that once you "have it" you can manipulate its dynamic and attribute properties once "obtained"?
    They switched a bunch of people's usernames. I have no idea.

    but it appears as if it grabs any certain block reference named "C" regardless of its space.. right?
    Yes grabs all blockreferences created from block definition.

    Can I assume that once you "have it" you can manipulate its dynamic and attribute properties once "obtained"?
    Yes/No
    If it is a dynamic block and you change any of the dynamic properties it will create a anonymous block.
    Then you must use GetAnonymousBlockIds instead of GetBlockReferenceIds in code above or maybe need to use both.

  8. #8
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,719
    Login to Give a bone
    0

    Default Re: Search entire drawing for block references at once

    Quote Originally Posted by christopher.259266 View Post
    Who is "christopher.259266" where did that name come from?
    This may help to clarify:
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  9. #9
    Active Member
    Join Date
    2009-08
    Posts
    93
    Login to Give a bone
    0

    Default Re: Search entire drawing for block references at once

    Thanks,
    As you can see still have not fixed it

  10. #10
    Active Member
    Join Date
    2006-08
    Location
    Brisbane : GMT+10
    Posts
    87
    Login to Give a bone
    0

    Default Re: Search entire drawing for block references at once

    Quote Originally Posted by christopher.259266 View Post
    Thanks,
    As you can see still have not fixed it

    If ability was boolean property the options would be competent and AuGi

Similar Threads

  1. Replies: 0
    Last Post: 2015-03-20, 10:57 AM
  2. 2013: Displaying entire drawing name on top of Autocad
    By sovby254640 in forum AutoCAD General
    Replies: 3
    Last Post: 2013-08-14, 05:47 PM
  3. Search and lookup feature for part references.
    By Wish List System in forum AutoCAD Wish List
    Replies: 1
    Last Post: 2012-10-17, 03:45 PM
  4. Replies: 2
    Last Post: 2011-05-23, 12:03 PM
  5. ADT '05 doesn't plot entire drawing
    By gregb in forum ACA General
    Replies: 4
    Last Post: 2007-12-03, 03:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •