See the top rated post in this thread. Click here

Results 1 to 7 of 7

Thread: Block at Layout

  1. #1
    Member eblanco_74's Avatar
    Join Date
    2005-12
    Posts
    18
    Login to Give a bone
    0

    Default Block at Layout

    How can I find out which layout is a block inserted. I've already made a list of all my layouts and also the name of the specific block I want the data from. Can anybody help me!

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

    Default Re: Block at Layout

    Quote Originally Posted by eblanco_74 View Post
    How can I find out which layout is a block inserted.
    Consider the TBLSEARCH function if querying the active document.



    Quote Originally Posted by eblanco_74 View Post
    I've already made a list of all my layouts and also the name of the specific block I want the data from.
    How did you accomplish that exactly?

    It's a lot easier to help when you post your code... Stab in the dark (supports OBDX):

    Code:
    (vl-load-com)
    
    (defun _FindBlock (doc blockName / layoutName layouts)
      ;; Example: (_FindBlock acdoc "foo")
      (setq blockName (strcase blockName))
      (vlax-for layout (vla-get-layouts acdoc)
        (vlax-for x (vla-get-block layout)
          (if
            (and
              (= "AcDbBlockReference" (vla-get-objectname x))
              (= blockName (strcase (vla-get-name x)))
              (not (vl-position
                     (setq layoutName (vla-get-name layout))
                     layouts
                   )
              )
            )
            (setq layouts (cons layoutName layouts))
          )
        )
      )
      layouts
    )


    HTH
    "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

  3. #3
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    1

    Default Re: Block at Layout

    Another way and should obtain the Dynamic Block names as well

    Code:
    (defun _FindBlockLocation (Blockname / ly lst)
      ;;    Tharwat 11.July.2014    ;;
      (vlax-for x (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
        (if (eq (vla-get-isLayout x) :vlax-true)
          (vlax-for o x
            (if
              (and
                (eq (vla-get-objectname o) "AcDbBlockReference")
                (eq (strcase (vla-get-effectivename o)) (strcase BlockName))
                (not (member (setq ly (vla-get-name (vla-get-layout x))) lst))
              )
               (setq lst (cons ly lst))
            )
          )
        )
      )
      (reverse lst)
    )(vl-load-com)

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

    Default Re: Block at Layout

    Quote Originally Posted by Tharwat View Post
    Another way and should obtain the Dynamic Block names as well
    ... And removes ObjectDBX support for batch operations.
    "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

  5. #5
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    1

    Default Re: Block at Layout

    Quote Originally Posted by BlackBox View Post
    ... And removes ObjectDBX support for batch operations.


    Cheers

  6. #6
    Member eblanco_74's Avatar
    Join Date
    2005-12
    Posts
    18
    Login to Give a bone
    0

    Default Re: Block at Layout

    BlackBox/Tharwat:

    Thanks a lot for your fast response. I really appreciate and it helped me a lot. I should had post the code but I was working on it (and still am) and does not had nothing concrete by the time but your codes "showed me the light" and here's what I've done. At the end what I need it's a list of attributes from a block (a title block) that's inserted on each layouts and the layout name itself. Any suggestions will be appreciated

    Sorry. I did not know how to insert my code other than this...

    Code:
    (defun c:sds_index ()
      (setq	accdoc	   (vla-get-activedocument (vlax-get-acad-object))
    	blks	   (vla-get-blocks accdoc)
    	lst-att-ly '()
    	) ;_ end of setq
      (vlax-for x blks
        (if	(and
    	  (= (vla-get-isLayout x) :vlax-true)
    	  (/= (vla-get-name x) "*Model_Space")
    	  ) ;_ end of and
          (vlax-for	o x
    	(if
    	  (and
    	    (= (vla-get-objectname o) "AcDbBlockReference")
    	    (= (strcase (vla-get-effectivename o)) "SDS_FDS-TITLE_BLK")
    	    ) ;_ end of and
    	   (setq lst-att-ly
    		  (cons
    		    (cons
    		      (vla-get-taborder (setq lay-obj (vla-get-layout x)))
    		      (cons (vla-get-name lay-obj) (index-get_att o "DSCP"))
    		      ) ;_ end of cons
    		    lst-att-ly
    		    ) ;_ end of cons
    		 ) ;_ end of setq
    	   ) ;_ end of if
    	) ;_ end of vlax-for
          ) ;_ end of if
        ) ;_ end of vlax-for
      (setq lst-att-ly (vl-sort lst-att-ly (function (lambda (e1 e2) (< (car e1) (car e2))))))
      ) ;_ end of defun
    
    (defun index-get_att (blk tag /)
      (setq	atts (vlax-invoke blk "getattributes")
    	ct-a (length atts)
    	ct   0
    	) ;_ end of setq
      (while (> ct-a ct)
        (setq att	 (nth ct atts)
    	  nm-att (vla-get-tagstring att)
    	  ) ;_ end of setq
        (if	(= nm-att tag)
          (progn
    	(setq value (vla-get-textstring att)
    	      ct    ct-a
    	      ) ;_ end of setq
    	) ;_ end of progn
          (setq ct (1+ ct))
          ) ;_ end of if
        ) ;_ end of while
      value
      ) ;_ end of defun
    Last edited by BlackBox; 2014-07-15 at 07:42 PM. Reason: Added [CODE] Tags

  7. #7
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Block at Layout

    Try this ..

    Code:
    (defun c:Test (/ atts lst ok ly l)
      ;;    Tharwat 15.July.2014    ;;
      (vlax-for x (vla-get-blocks
                    (vla-get-activedocument (vlax-get-acad-object))
                  )
        (if (and (eq (vla-get-isLayout x) :vlax-true)
                 (not
                   (eq (setq ly (vla-get-name (vla-get-layout x))) "Model")
                 )
            )
          (progn
            (setq lst nil)
            (vlax-for o x
              (if
                (and
                  (eq (vla-get-objectname o) "AcDbBlockReference")
                  (eq (strcase (vla-get-effectivename o))
                      "SDS_FDS-TITLE_BLK"
                  )
                  (setq atts (vlax-invoke o 'GetAttributes))
                )
                 (foreach e atts
                   (if (eq (strcase (vla-get-tagstring e)) "DSCP")
                     (setq lst (cons (vla-get-textstring e) lst))
                   )
                 )
              )
            )
            (if lst
              (setq l (cons (list ly lst) l)
              )
            )
          )
        )
      )
      (if l
        (progn
          (foreach it l
            (print it)
          )
          (textscr)
        )
      )
      (princ)
    )
    (vl-load-com)

Similar Threads

  1. match orientation layout to a block
    By Wish List System in forum AutoCAD Wish List
    Replies: 6
    Last Post: 2013-05-29, 06:07 AM
  2. Old layout block does not want new attributes
    By Kristjankk in forum Dynamic Blocks - Technical
    Replies: 2
    Last Post: 2010-08-16, 02:39 PM
  3. Title Block on each Layout Tab- best method?
    By rbdome in forum AutoCAD LT - General
    Replies: 3
    Last Post: 2010-02-07, 11:31 AM
  4. Insert block into layout
    By cgerhardt in forum VBA/COM Interop
    Replies: 6
    Last Post: 2006-11-29, 04:10 PM
  5. block count only in current space/layout
    By VBOYAJI in forum AutoLISP
    Replies: 25
    Last Post: 2006-07-07, 05:40 PM

Tags for this Thread

Posting Permissions

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