TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: adalea03 on January 12, 2007, 10:57:28 PM
-
Can I map an instance of a block to the layout it resides on?
If so, point me in the right direction, please.
What little I have so far is listed below.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; conditions: * multiple layuot tabs
;;; * (1) instance of title block inserted on some but not all layuot tabs
;;; goal : associate each title block (entity or object) with its respective layout
;;; so the end user can select the target title block by its associated
;;; layout name from a dialog list_box ragardless of the 'current' layuot status
;;; assumed info requirements:
;;; * list of layouts and/or layout blocks
;;; * list of entity names or object IDs of each instance of title block
;;; * etc. , etc. , ...
;;; problem : how to develop and report the assoiations so correct selection
;;; can be made by the end user
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun map-titleblocks-2-layouts (/ current-doc current-layout layout-list ps-layouts)
(setq current-doc (vla-get-activedocument (vlax-get-acad-object)))
(setq current-layout (vlax-get-property current-doc 'ActiveLayout))
(setq layout-list nil)
(vlax-for xi (vla-get-layouts current-doc)
(setq layout-list (cons (list
(vlax-get-property xi 'TabOrder)
(vlax-get-property xi 'Name)
(vlax-get-property xi 'Block)) layout-list)))
(setq ps-layouts nil)
(foreach xi (cdr (vl-sort (mapcar 'car layout-list) '<))
(foreach ix layout-list
(if (= xi (car ix))
(setq ps-layouts (append ps-layouts (list ix))) nil)))
;;; I'm stuck
)
Thank you,
Tony
-
Have you played with dictionaries or Xrecords ?
-
Just to expand the idea.
Each insert has a unique immutable handle.
You may be able to add a dictionary to each layout referencing the handle < or Name > of it's designated block instance. [ depending on the setup, this may be able to be automated ]
The layouts could then be iterated, extracting the referenced handle < or Name > which could then be programmatically selected.
-
maybe i didn't understanding the question. is there only one title block in each layout? if so, (ssget "X" (list (cons 0 "INSERT") (cons 2 blkName) (cons 410 layoutName)) should select that block, right?
-
Kelie, I wasn't too sure either ...
could even select if the blocks were different but similarly named.
-
While not 'fluent' in X-records I have had success using that tecnique.
I will try
"...(ssget "X" (list (cons 0 "INSERT") (cons 2 blkName) (cons 410 layoutName)) ..."
first.
Thank you, Kerry, Kelly.
Tony
-
Oh, by the way Kelie, it was
one instance of the title block on some but not all layouts.
Tony
-
The solution was much simpler than I had expected.
(setq my-tblks (ss2lst (ssget "X" (list (cons 0 "INSERT") (cons 2 "A-1117PP-3")))))
(setq my-tblk-lst
(mapcar '(lambda (x) (list (cdr (assoc 410 (entget x))) x)) my-tblks))
Thank you for all for your suggestions.
Tony
-
I thought that may have been what you wanted.
My answer was aimed at the original question ; ie
.. map an instance of a block to the layout it resides on?
which in itself is also an interesting idea if the block names were unique.
.. good to see your problem resolved.