Author Topic: Finding blocks in an xref, possible?  (Read 6777 times)

0 Members and 1 Guest are viewing this topic.

Aerdvark

  • Guest
Finding blocks in an xref, possible?
« on: March 03, 2010, 01:17:48 AM »
This link got me thinking:

http://www.theswamp.org/index.php?topic=24251.0

Now I am wondering, is there some command in AUtoCAD that allows it's user to search an xref for a specific block?
It is a bit hard for me to explain my goal but to give a short Idea:
- I have a drawing, with an xref attached to it
- The xref itself contains various blocks, I only need the block "test" within a specific area (select by crossing / window)
- Once the blocks are retrieved I need each insertion point
- In my current dwg I need to place another block on top of it, maybe with an offset

Anyone knows a way to do this? Thanks in advance.
This is my routine that I use now, but it only works on the drawing itself, so not on a Xref.

I believe the problem is that the "ssget" part don't work on Xref, that is for shure. I would need a "nentsel" but thats only working for 1 entity.

(Author of the lisp is a well known member of this forum, I wonder how long it will take Lee to notice :-) )

Code: [Select]
(defun c:BLOCKONBLOCK  (/ *error* vl ov ss i bLst rot pt pt2)  ;; Always Localise the Variables!

  ;; Error Handler in case the user hits Esc
 
  (defun *error* (msg)
   
    (if ov (mapcar 'setvar vl ov)) ; reset Sys vars
   
    (princ (strcat "\n<< Error: " msg " >>")) ; Print Error Message
   
    (princ) ; Exit Cleanly

    ) ; End Error Handler


  (setq vl '("CMDECHO" "OSMODE") ; Sys Var list
       
        ov (mapcar 'getvar vl)) ; Get Old values
 
  (mapcar 'setvar vl '(0 0)) ; Turn off CMDECHO & OSMODE
 
  (print "Please Select blocks...") ; Prompt
 
  (if  ; If a SelectionSet is picked
   
    (setq ss (ssget '((0 . "INSERT")))) ;; Filter for Blocks

    (progn
 
      (setq i (sslength ss))  ; get number of items in SelectionSet

      (while (not (minusp (setq i (1- i)))) ; While i is not Negative

        (setq bLst (entget (ssname ss i)))  ; get Block Entity

        (setq pt (cdr (assoc 10 bLst))   ; Insertion Point
             
              rot (cdr (assoc 50 bLst))) ; Rotation

(setq pt2 (polar pt (+ rot pi) dist)) ; Define New point where dist is the offset to insertion

(setq rotdgr (/ (* rot 180) pi))

        (command "-insert" block pt2 "1." "1." rotdgr) ; Insert Block at new point


        ) ; End While

      ) ; End Progn

    (princ "\n<!> No Blocks Selected <!>") ; Else no Blocks were Picked

    ) ; end If

  (mapcar 'setvar vl ov) ; reset Sys Vars

  (princ) ; Exit Cleanly

  ) ; end function

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Finding blocks in an xref, possible?
« Reply #1 on: March 03, 2010, 02:41:08 AM »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Aerdvark

  • Guest
Re: Finding blocks in an xref, possible?
« Reply #2 on: March 03, 2010, 04:16:19 AM »
Maybe this will help you.

[ http://www.theswamp.org/index.php?topic=27786.0 ]

Hello T.Willey,

Thanks for the reply!
It seems that the routine erases the selected entity. That could be modified in something else, okay. But when selecting a block in an xref, it selects the entity in the block... not what I need.

Can we take it step by step? (One question at the time...)

First question: is it possible to get a block insertion point when the block is in an xref? I think that this can only be done with objectdbx. I read some nice things about that but it is too hard for me.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Finding blocks in an xref, possible?
« Reply #3 on: March 03, 2010, 08:39:20 AM »
Not sure if you wanted to get the blocks by selection or just get a list, but in any case, this might help  :-)

I'm not happy with my GetNested function, I'm sure it could be written more elegantly...

Code: [Select]
[color=RED]([/color][color=BLUE]defun[/color] GetNestedBlocks [color=RED]([/color]bName [color=BLUE]/[/color] itemp GetName GetNested block[color=RED])[/color]
  [color=RED]([/color][color=BLUE]vl-load-com[/color][color=RED])[/color]
  [color=#990099];; Lee Mac  ~  03.03.10[/color]

  [color=RED]([/color][color=BLUE]setq[/color] *blks* [color=RED]([/color][color=BLUE]vla-get-Blocks[/color]
                 [color=RED]([/color][color=BLUE]vla-get-ActiveDocument[/color]
                   [color=RED]([/color][color=BLUE]vlax-get-acad-object[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color]
 

  [color=RED]([/color][color=BLUE]defun[/color] itemp [color=RED]([/color]coll item [color=BLUE]/[/color] rtn[color=RED])[/color]
    [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]not[/color] [color=RED]([/color][color=BLUE]vl-catch-all-error-p[/color]
               [color=RED]([/color][color=BLUE]setq[/color] rtn
                 [color=RED]([/color][color=BLUE]vl-catch-all-apply[/color]
                   [color=RED]([/color][color=BLUE]function[/color] vla-item[color=RED])[/color] [color=RED]([/color][color=BLUE]list[/color] coll item[color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color]
      rtn[color=RED])[/color][color=RED])[/color]
 

  [color=RED]([/color][color=BLUE]defun[/color] GetName [color=RED]([/color]obj[color=RED])[/color]
    [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]vlax-property-available-p[/color] obj [color=DARKRED]'[/color]EffectiveName[color=RED])[/color]
      [color=RED]([/color][color=BLUE]vla-get-EffectiveName[/color] obj[color=RED])[/color]
      [color=RED]([/color][color=BLUE]vla-get-Name[/color] obj[color=RED])[/color][color=RED])[/color][color=RED])[/color]
 

  [color=RED]([/color][color=BLUE]defun[/color] GetNested [color=RED]([/color]obj [color=BLUE]/[/color] nest[color=RED])[/color]   
    [color=RED]([/color][color=BLUE]vlax-for[/color] sub_obj obj
      [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]eq[/color] [color=#A52A2A]"AcDbBlockReference"[/color] [color=RED]([/color][color=BLUE]vla-get-ObjectName[/color] sub_obj[color=RED])[/color][color=RED])[/color]
        [color=RED]([/color][color=BLUE]setq[/color] nest
          [color=RED]([/color][color=BLUE]append[/color] nest
            [color=RED]([/color][color=BLUE]list[/color] sub_obj
              [color=RED]([/color]GetNested
                [color=RED]([/color]itemp *blks* [color=RED]([/color]GetName sub_obj[color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color]
   
    [color=RED]([/color][color=BLUE]vl-remove[/color] [color=DARKRED]'[/color][color=BLUE]nil[/color] nest[color=RED])[/color][color=RED])[/color]


  [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]setq[/color] block [color=RED]([/color]itemp *blks* bName[color=RED])[/color][color=RED])[/color]
    [color=RED]([/color]GetNested block[color=RED])[/color][color=RED])[/color][color=RED])[/color]


[color=RED]([/color][color=BLUE]defun[/color] c:test [color=RED]([/color][color=BLUE]/[/color] ent[color=RED])[/color]

  [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]and[/color] [color=RED]([/color][color=BLUE]setq[/color] ent [color=RED]([/color][color=BLUE]car[/color] [color=RED]([/color][color=BLUE]entsel[/color] [color=#A52A2A]"\nSelect Block : "[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color]
           [color=RED]([/color][color=BLUE]eq[/color] [color=#A52A2A]"INSERT"[/color] [color=RED]([/color][color=BLUE]cdr[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]0[/color] [color=RED]([/color][color=BLUE]entget[/color] ent[color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color]
   
    [color=RED]([/color]GetNestedBlocks [color=RED]([/color][color=BLUE]cdr[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]2[/color] [color=RED]([/color][color=BLUE]entget[/color] ent[color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color]
« Last Edit: March 03, 2010, 09:46:45 AM by Lee Mac »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Finding blocks in an xref, possible?
« Reply #4 on: March 03, 2010, 10:56:54 AM »
My code allows you select as nested as you want, but it will also give you all the entities that it is nested within, so you can just step up until you find the block, and not an xref.  I don't have time to help right now though.

If you are good at matrix math, and/or vector math, I think it is possible to translate the insertion point of a nested block, to the current ucs.  I'm not that person though.  No ObjectDBX needed.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Aerdvark

  • Guest
Re: Finding blocks in an xref, possible?
« Reply #5 on: March 04, 2010, 01:54:37 AM »
My code allows you select as nested as you want, but it will also give you all the entities that it is nested within, so you can just step up until you find the block, and not an xref.  I don't have time to help right now though.

If you are good at matrix math, and/or vector math, I think it is possible to translate the insertion point of a nested block, to the current ucs.  I'm not that person though.  No ObjectDBX needed.

T.Willey:
I am not that good programmer yet, let alone math.
Maybe (if you find the time for it) you can tell me how to step up to get the block..?

@ Lee:
If you try the code in the first post (it's yours, maybe you know it's function without trying) you will see how it works.

A little note: I use the code together with a macro.
In the macro there are 2 variables stated: "dist" and "block".

The code does this, when in a drawing with blocks (not blocks in xref):

command: <test> -->macro says (setq block "abc") & (setq dist 10)

1. Grab a bunch of blocks <enter>

Let's say I have selected 10 blocks with different names.
After the enter, all of those blocks insertion points are calculated.
Then there is put a new block ("abc") put on the insertion block of the selected blocks.
The direction is also the same as the block selected.
The variable distance allows me to offset the insertion points.

Well, all of this is working great, but I allways need to open an xref to apply this code.
Then I need to filter my newly created blocks out of the xref and paste them in my dwg.

So I figured: why not scan the xref for blocks and then do the same trick?

You did once try to help me but we did not find a solution.
Maybe now?

See old link:
http://www.cadtutor.net/forum/showthread.php?t=36963&page=2


Aerdvark

  • Guest
Re: Finding blocks in an xref, possible?
« Reply #6 on: March 04, 2010, 05:28:50 PM »
Nobody?

xiaxiang

  • Guest
Re: Finding blocks in an xref, possible?
« Reply #7 on: February 16, 2013, 10:33:57 PM »
Not sure if you wanted to get the blocks by selection or just get a list, but in any case, this might help  :-)

I'm not happy with my GetNested function, I'm sure it could be written more elegantly...

Code: [Select]
[color=RED]([/color][color=BLUE]defun[/color] GetNestedBlocks [color=RED]([/color]bName [color=BLUE]/[/color] itemp GetName GetNested block[color=RED])[/color]
  [color=RED]([/color][color=BLUE]vl-load-com[/color][color=RED])[/color]
  [color=#990099];; Lee Mac  ~  03.03.10[/color]

  [color=RED]([/color][color=BLUE]setq[/color] *blks* [color=RED]([/color][color=BLUE]vla-get-Blocks[/color]
                 [color=RED]([/color][color=BLUE]vla-get-ActiveDocument[/color]
                   [color=RED]([/color][color=BLUE]vlax-get-acad-object[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color]
 

  [color=RED]([/color][color=BLUE]defun[/color] itemp [color=RED]([/color]coll item [color=BLUE]/[/color] rtn[color=RED])[/color]
    [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]not[/color] [color=RED]([/color][color=BLUE]vl-catch-all-error-p[/color]
               [color=RED]([/color][color=BLUE]setq[/color] rtn
                 [color=RED]([/color][color=BLUE]vl-catch-all-apply[/color]
                   [color=RED]([/color][color=BLUE]function[/color] vla-item[color=RED])[/color] [color=RED]([/color][color=BLUE]list[/color] coll item[color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color]
      rtn[color=RED])[/color][color=RED])[/color]
 

  [color=RED]([/color][color=BLUE]defun[/color] GetName [color=RED]([/color]obj[color=RED])[/color]
    [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]vlax-property-available-p[/color] obj [color=DARKRED]'[/color]EffectiveName[color=RED])[/color]
      [color=RED]([/color][color=BLUE]vla-get-EffectiveName[/color] obj[color=RED])[/color]
      [color=RED]([/color][color=BLUE]vla-get-Name[/color] obj[color=RED])[/color][color=RED])[/color][color=RED])[/color]
 

  [color=RED]([/color][color=BLUE]defun[/color] GetNested [color=RED]([/color]obj [color=BLUE]/[/color] nest[color=RED])[/color]   
    [color=RED]([/color][color=BLUE]vlax-for[/color] sub_obj obj
      [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]eq[/color] [color=#A52A2A]"AcDbBlockReference"[/color] [color=RED]([/color][color=BLUE]vla-get-ObjectName[/color] sub_obj[color=RED])[/color][color=RED])[/color]
        [color=RED]([/color][color=BLUE]setq[/color] nest
          [color=RED]([/color][color=BLUE]append[/color] nest
            [color=RED]([/color][color=BLUE]list[/color] sub_obj
              [color=RED]([/color]GetNested
                [color=RED]([/color]itemp *blks* [color=RED]([/color]GetName sub_obj[color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color]
   
    [color=RED]([/color][color=BLUE]vl-remove[/color] [color=DARKRED]'[/color][color=BLUE]nil[/color] nest[color=RED])[/color][color=RED])[/color]


  [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]setq[/color] block [color=RED]([/color]itemp *blks* bName[color=RED])[/color][color=RED])[/color]
    [color=RED]([/color]GetNested block[color=RED])[/color][color=RED])[/color][color=RED])[/color]


[color=RED]([/color][color=BLUE]defun[/color] c:test [color=RED]([/color][color=BLUE]/[/color] ent[color=RED])[/color]

  [color=RED]([/color][color=BLUE]if[/color] [color=RED]([/color][color=BLUE]and[/color] [color=RED]([/color][color=BLUE]setq[/color] ent [color=RED]([/color][color=BLUE]car[/color] [color=RED]([/color][color=BLUE]entsel[/color] [color=#A52A2A]"\nSelect Block : "[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color]
           [color=RED]([/color][color=BLUE]eq[/color] [color=#A52A2A]"INSERT"[/color] [color=RED]([/color][color=BLUE]cdr[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]0[/color] [color=RED]([/color][color=BLUE]entget[/color] ent[color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color]
   
    [color=RED]([/color]GetNestedBlocks [color=RED]([/color][color=BLUE]cdr[/color] [color=RED]([/color][color=BLUE]assoc[/color] [color=#009900]2[/color] [color=RED]([/color][color=BLUE]entget[/color] ent[color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color][color=RED])[/color]

Oh no,what a confusion it is!
Someone help me?

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Finding blocks in an xref, possible?
« Reply #8 on: February 17, 2013, 04:57:30 AM »
I think it is due to an upgrade in the Swamp's forum engine. Previously it was possible to include formatting (e.g. colour) inside the code tags. So some of the old code tags (which were done with manual colour formatting) now display the colour formatting tags inside (instead of how they should appear).
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.