See the top rated post in this thread. Click here

Results 1 to 10 of 10

Thread: Nested block and coordinates

  1. #1
    Member
    Join Date
    2022-10
    Posts
    12
    Login to Give a bone
    0

    Question Nested block and coordinates

    Hello there,
    I'm facing problem working with nested blocks.

    I have block - usually nested at third level (if I cound correctly, that block I can select directly is 1st level, than block editor goes to 2nd level and only there I can pick my block and open it as 3rd level) that I would like to know its coordinates (basically insertion point, specifically the Z elevation). I tried nentsel and working it but I do not understand much the syntax and information I am getting.
    As far as I can tell, I'm getting coordinates relative to what is happening inside of blocks (so Z says it is -24 when I can tell by exploding that it is 1200something). But if I try to also entsel and figure out coordinates from block, main block (1st level) is inserted to 0,0,0 so I dont know how to connect those different coordinates. I would like to have actual coordinate of this nested block in context of drawing so that I can use coordinates to build next steps with them.

    I've looked into couple of LISPs but they mostly list out block info into command line or external file and I am having hard time to extract just few bits I might need. Could anyone dumb it down for me?

    TLDR - block X nested in block B which is in block A - I would like coordinates of block X in context of actual drawing as I would like to work with those coordinates to do further steps in my routine (using them to add select or add other objects).

  2. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,397
    Login to Give a bone
    0

    Default Re: Nested block and coordinates

    It's not really clear what you want. I suggest that you post a sample file and describe what steps you are taking and what you want to achieve.
    C:> ED WORKING....

  3. #3
    Member
    Join Date
    2016-10
    Posts
    7
    Login to Give a bone
    0

    Default Re: Nested block and coordinates

    You can transform the insertionpoint with the refgeom function by gile found here:
    https://www.theswamp.org/index.php?t...1150#msg331150

    Its complicated stuff, but if you insert the block ename it returns a matrix to use on the insertionpoint to convert it to the point actual point you want.

  4. #4
    Member
    Join Date
    2016-10
    Posts
    7
    Login to Give a bone
    0

    Default Re: Nested block and coordinates

    Quote Originally Posted by robske736291 View Post
    You can transform the insertionpoint with the refgeom function by gile found here:

    Its complicated stuff, but if you insert the block ename it returns a matrix to use on the insertionpoint to convert it to the point actual point you want.

    Ok, it removed my link to theswamp... index.php?topic=27508.msg331150#msg331150
    You can also find it if you google for refgeom...

  5. #5
    Member
    Join Date
    2022-10
    Posts
    12
    Login to Give a bone
    0

    Default Re: Nested block and coordinates

    I've attached simplified upload friendly version of what I am working with.

    I have block A that contains couple of smaller things (I've placed just rectangles to put something in) and block B that is the main item. Block B is made out of some parts I don't need to work with (named that block "legs") and Block C. Block C is object from which I want to know its insertion point with coordinates relevant to being in drawing and not in block editor.


    @robske736291 - I'll try to have a look, but as you say, it is bit complex.
    Attached Files Attached Files

  6. #6
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,397
    Login to Give a bone
    0

    Default Re: Nested block and coordinates

    Quote Originally Posted by robske736291 View Post
    Ok, it removed my link to theswamp... index.php?topic=27508.msg331150#msg331150
    You can also find it if you google for refgeom...
    Sorry, but our anti-spam software does that if you don't have more than 5 posts. We get a lot of spammers creating a new account just so they can post a link to their website.
    I'll repost it.
    https://www.theswamp.org/index.php?t...1150#msg331150
    C:> ED WORKING....

  7. #7
    Member
    Join Date
    2016-10
    Posts
    7
    Login to Give a bone
    0

    Default Re: Nested block and coordinates

    Funny that you pick an example with all the base points at 0,0,0 .

    I wrote an getInsertionPoint function to find all the nested points.
    Its a recursive function that transforms the points each time it is nested.
    That way in the end you should get the absolute coordinates of the blocks insertion point.

    It returns a list with all the block names it is nested in so you can find the one you want.
    Code:
    (defun c:test (/ ent)
    	(setq ent (car (entsel)))
    	(setq insertionPoints (getInsertionPoints nil ent)) ; Get insertion points
    
    	(foreach pnt insertionPoints ; Draw them to show that is works
    		(entmakex (list '(0 . "POINT") (cons 10 (cadr pnt))))
    	)
    
    	insertionPoints ; Return info
    )
    
    (defun getInsertionPoints (prefix ent / blockName ent enx mat nestedBlocks thisBlock)
    	(setq enx (entget ent))
    	(setq blockName (cdr (assoc 2 enx))) ; Block Name
    	(setq mat (Mat:refgeom ent)) ; Transfromation matrix for this block
    	(setq thisBlock ; Insertion Point for this block
    		(list
    			(cond (prefix (strcat prefix ":" blockName)) (blockName)) ; Block name with prefix
    			(trans (cdr (assoc 10 enx)) (cdr (assoc 210 enx)) 0) ; Insertion Point
    		)
    	)
    
    	(if (setq ent (tblobjname "BLOCK" blockName))
    		(while (and ent (setq ent (entnext ent))) ; loop though items inside block
    			(if (= (cdr (assoc 0 (entget ent))) "INSERT") ; If a nested block is found
    				(progn
    					(setq nestedBlocks
    						(mapcar
    							(function
    								(lambda (blk) ; Go through items retuned from getInsertionPoints
    									(list
    										(car blk) ; Keep block name the same
    										(mapcar '+ (Mat:mxv (car mat) (cadr blk)) '(0 0 0) (cadr mat)) ; Transform with refgeom matrix
    									)
    								)
    							)
    							(getInsertionPoints (car thisBlock) ent) ; Go deeper
    						)
    					)
    				)
    			)
    		)
    	)
    	(cons thisBlock nestedblocks)
    )
    
    ;;;-----------------------------------------------------------------------------;;
    ;;; RefGeom - gile                                                              ;;
    ;;; Returns a list whose first item is a 3x3 transformation matrix and          ;;
    ;;; second item the object insertion point in its parent (xref, block or space) ;;
    ;;;-----------------------------------------------------------------------------;;
    (defun Mat:refgeom (ent / ang enx mat ocs)
    	(setq enx (entget ent)
    				ang (cdr (assoc 050 enx))
    				ocs (cdr (assoc 210 enx)))
    	(list
    		(setq mat
    						(Mat:mxm
    							(mapcar
    								(function (lambda (v) (trans v 0 ocs t)))
    								'(
    									(1.0 0.0 0.0)
    									(0.0 1.0 0.0)
    									(0.0 0.0 1.0)
    								)
    							)
    							(Mat:mxm
    								(list
    									(list (cos ang) (- (sin ang)) 0.0)
    									(list (sin ang) (cos ang) 0.0)
    									'(0.0 0.0 1.0)
    								)
    								(list
    									(list (cdr (assoc 41 enx)) 0.0 0.0)
    									(list 0.0 (cdr (assoc 42 enx)) 0.0)
    									(list 0.0 0.0 (cdr (assoc 43 enx)))
    								)
    							)
    						)
    					)
    		(mapcar '-
    			(trans (cdr (assoc 10 enx)) ocs 0)
    			(Mat:mxv mat (cdr (assoc 10 (tblsearch "block" (cdr (assoc 2 enx))))))
    		)
    	)
    )
    
    ;;;-----------------------------------------------------------;;
    ;;; Matrix x Vector - Vladimir Nesterovsky                    ;;
    ;;; Args: m - nxn matrix, v - vector in R^n                   ;;
    ;;;-----------------------------------------------------------;;
    (defun Mat:mxv (m v)
    	(mapcar (function (lambda (r) (apply '+ (mapcar '* r v)))) m)
    )
    
    ;;;-----------------------------------------------------------;;
    ;;; Matrix x Matrix - Vladimir Nesterovsky                    ;;
    ;;; Args: m,n - nxn matrices                                  ;;
    ;;;-----------------------------------------------------------;;
    (defun Mat:mxm (m n)
    	((lambda (a) (mapcar (function (lambda (r) (Mat:mxv a r))) m)) (Mat:trp n))
    )
    
    ;;;-----------------------------------------------------------;;
    ;;; Matrix Transpose - Doug Wilson                            ;;
    ;;; Args: m - nxn matrix                                      ;;
    ;;;-----------------------------------------------------------;;
    (defun Mat:trp (m)
    	(apply 'mapcar (cons 'list m))
    )
    
    (princ)
    - - - Updated - - -

    Quote Originally Posted by Ed Jobe View Post
    Sorry, but our anti-spam software does that if you don't have more than 5 posts. We get a lot of spammers creating a new account just so they can post a link to their website.
    I'll repost it.
    https://www.theswamp.org/index.php?t...1150#msg331150
    I understand, also editing posts doesn't work probably because of the same reason.
    Guess I'll have to post more then

  8. #8
    Member
    Join Date
    2022-10
    Posts
    12
    Login to Give a bone
    0

    Default Re: Nested block and coordinates

    @robske736291 Thank you for the code!
    There is lot of 0,0,0 in the work process I'm dealing with and I feel it maybe adds bit of difficulty to the task, so that is why I picked it. It is somewhat new to me as I previously worked somewhere where we would not nest blocks like this, but it has its own logic here which seems reasonable enough.

    (("Block A" (0.0 0.0 0.0)) ("Block A:Block B" (0.0 0.0 0.0)) ("Block A:Block B:legs" (0.0 0.0 0.0)))
    I'm getting this and what I am interested in is actually Block C which is not here. It would probably be "Block A:Block B:Block C". But I think using what I've made in my attempts and mostly from what you've given me here, I should be able to piece it together. So once again thank you for the help.

    @Ed Jobe thank you for reposting the link.

  9. #9
    Member
    Join Date
    2016-10
    Posts
    7
    Login to Give a bone
    1

    Default Re: Nested block and coordinates

    Ah yes, I didn't add the nested items to a list but replaced the variable each time.
    I've added append and now it should work:
    Code:
    (defun getInsertionPoints (prefix ent / blockName ent enx mat nestedBlocks thisBlock)
    	(setq enx (entget ent))
    	(setq blockName (cdr (assoc 2 enx))) ; Block Name
    	(setq mat (Mat:refgeom ent)) ; Transfromation matrix for this block
    	(setq thisBlock ; Insertion Point for this block
    		(list
    			(cond (prefix (strcat prefix ":" blockName)) (blockName)) ; Block name with prefix
    			(trans (cdr (assoc 10 enx)) (cdr (assoc 210 enx)) 0) ; Insertion Point
    		)
    	)
    
    	(if (setq ent (tblobjname "BLOCK" blockName))
    		(while (and ent (setq ent (entnext ent))) ; loop though items inside block
    			(if (= (cdr (assoc 0 (entget ent))) "INSERT") ; If a nested block is found
    				(progn
    					(setq nestedBlocks
    						(append
    							(mapcar
    								(function
    									(lambda (blk) ; Go through items retuned from getInsertionPoints
    										(list
    											(car blk) ; Keep block name the same
    											(mapcar '+ (Mat:mxv (car mat) (cadr blk)) '(0 0 0) (cadr mat)) ; Transform with refgeom matrix
    										)
    									)
    								)
    								(getInsertionPoints (car thisBlock) ent) ; Go deeper
    							)
    							nestedBlocks
    						)
    					)
    				)
    			)
    		)
    	)
    	(cons thisBlock nestedblocks)
    )

  10. #10
    Member
    Join Date
    2022-10
    Posts
    12
    Login to Give a bone
    0

    Default Re: Nested block and coordinates

    Absolutely amazing!

Similar Threads

  1. 2014: DWG Nested Inside Detail Comp. > Nested Inside Profile > Nested Inside Window
    By edu.rocha.tavares in forum Revit Architecture - Families
    Replies: 5
    Last Post: 2013-11-26, 06:46 PM
  2. 2013: How do I export to IFC with project coordinates and not real world coordinates?
    By m.knutsson in forum Revit Architecture - General
    Replies: 2
    Last Post: 2013-10-15, 06:54 AM
  3. Project Coordinates, Shared Coordinates, and the new Survey Point
    By Wes Macaulay in forum Revit - Platform
    Replies: 59
    Last Post: 2012-07-05, 06:20 PM
  4. Replies: 0
    Last Post: 2007-09-30, 02:56 PM
  5. How do I translate Nested Block coordinates?
    By danderson.71652 in forum VBA/COM Interop
    Replies: 0
    Last Post: 2006-02-09, 04:21 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
  •