Author Topic: Retrieve a blocks insertion point when the block is in an xref...  (Read 2216 times)

0 Members and 1 Guest are viewing this topic.

Aerdvark

  • Guest
I was off topic here: http://www.theswamp.org/index.php?topic=34277.msg409429#msg409429 so as promised I will ask again.

Basically this is the question: Is there a way to retrieve a blocks insertion point when the block itself is in an xref?
And if possible, can that be done multiple times, for when there are 100 block in the xref?

At this point I have some routines that place blocks over other blocks, using the insertion points to insert and align.
All works nice and there are no problems besides some extra "handling": when "done" I only need to "copy and paste" the newly created blocks into a clean *.dwg.
What I do is lock all the layers that do not contain any of my new blocks, use [ctrl]+[shift]+[c] to copy with a basepoint.
Opening a new *.dwg and paste with basepoint.

I thought when having the clean *.dwg and attaching the *.dwg with all the blocks would be a faster way, just need to attach / detach the xref.

That's why my question came up. But I do not know if it can be done, for the solutions I can make start with "Nentsel".
This only returns the data of a nested entity but not of a block...

I am not asking for code, at least not yet, but only for some info where to look or what to look for.

Thank you in advance for helping me out.

pBe

  • Bull Frog
  • Posts: 402
Re: Retrieve a blocks insertion point when the block is in an xref...
« Reply #1 on: November 16, 2010, 10:35:24 AM »
Code: [Select]

(defun c:test (/ blocks filter_lst)
  (setq blocks (ssget "_x" '((0 . "INSERT")))
filter_lst (vl-remove-if 'listp
  (mapcar 'cadr (ssnamex blocks))))
(if blocks
  (foreach blk_name filter_lst
(if
  (vlax-property-available-p (vlax-ename->vla-object blk_name) 'Path)
  (progn
(princ (strcat "\nXref Name: " (vla-get-name (vlax-ename->vla-object blk_name))))
  (princ "\nInsertion point: ")(print  (cdr (assoc 10 (entget blk_name))))))
)
)(princ)
  )


try this.. not thoroughly tested


alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Retrieve a blocks insertion point when the block is in an xref...
« Reply #2 on: November 16, 2010, 10:54:08 AM »
Code: [Select]
(cdr (assoc 10 (entget (car (last (nentsel))))))
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

pBe

  • Bull Frog
  • Posts: 402
Re: Retrieve a blocks insertion point when the block is in an xref...
« Reply #3 on: November 16, 2010, 09:57:51 PM »
Silly me.. i misunderstood the question..

you can try this one.. it checks the xref pathname... access the file via DBX retrieve modelspace objects
filter blocks.. extract effectivename and inserpoint point data and make a list like this..

("BLOCK_NAME1" (34.56 54.88 0.0) "BLOCK_NAME2" (23.54 56.32 0.0))

Code: [Select]
(defun c:test2 (/ blocks filter_lst blk_list )
  (setq blocks (ssget "_x" '((0 . "INSERT"))) blk_list nil
filter_lst (vl-remove-if 'listp
  (mapcar 'cadr (ssnamex blocks))))
(if blocks
  (foreach blk_name filter_lst
(if
  (vlax-property-available-p (vlax-ename->vla-object blk_name) 'Path)
(progn
  (setq blockToProcess (cons (vla-get-path (vlax-ename->vla-object blk_name)) blockToProcess))
(RunDBX  blockToProcess)
)
  )
)
  )
  (print blk_list)(princ)
  )

(defun RunDBX  (blockToProcess / fileNames myDoc)
 (vl-load-com)
 (cond ((and blockToProcess
             (setq DbxFile (vla-GetInterfaceObject
                          (vlax-Get-Acad-Object)
                          (strcat "ObjectDBX.AxDbDocument." (substr (getvar 'AcadVer) 1 2)))))
        (foreach XrefBlock  blockToProcess
         (vla-Open DbxFile XrefBlock)
(setq This_Block (vla-get-modelspace  DbxFile))
      (vlax-for blks This_Block
(cond
  ((eq (vla-get-objectname blks)  "AcDbBlockReference")
(setq blk_list (cons (vlax-safearray->list (variant-value (vla-get-InsertionPoint blks))) blk_list)
blk_list (cons (vla-get-name blks) blk_list))))
)
          )
        (setq DbxFile (vl-catch-all-apply 'vlax-Release-Object (list DbxFile))))
        (blockToProcess (princ "\nUnable to create ObjectDBX document."))
        (T (princ "\nNo matching filenames found.")))
 (princ))

Hope i got it right this time.. is this what you're asking about?


You can use the varaible blk_list for your subroutine to insert the blocks from the xref .. and make sure you have those blocks included in the search path..
and i apologize for the crudeness of the code.. its obvious that it doesnt included error trapping

You can use this as reference  :-)