Jump to content

how do i get a particular block in a layout with Visual LISP


GroundWolf61

Recommended Posts

Hi everybody,

 

I need help.

I cant figure out how to get the ent name form a block in a layout.

Each layout has a titleblock ("SAL-TEKENBLAD_TITELBLOK" is the EffectiveName) and i want to make a list of all the layouts with the ent names.

 

THX,

GW61

 

 

(vlax-for LYT (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
	(setq ENT (vlax-vla-object->ename (vla-item (vla-get-blocks LYT) "SAL-TEKENBLAD_TITELBLOK")))
	(setq NAM (vla-get-name lyt))
	(setq LST (cons (list NAM ENT) LST))
);end vlax-for
Link to comment
Share on other sites

I Usually just use ssget to get ent name of stuff.

 

(if (setq SS (ssget "X" '((0 . "INSERT") (2 . "SAL-TEKENBLAD_TITELBLOK"))))
  (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))

 

This will get you a selection set of all SAL-TEKENBLAD_TITELBLOK in the drawing.

If you want to get a particular titleblock you can further limit it down to a specific layout. 

by adding (410 . "Tab Name")

 

(setq SS (ssget "X" '((0 . "INSERT") (2 . "SAL-TEKENBLAD_TITELBLOK") (410 . "Sheet 3"))))

 

 

  • Like 1
Link to comment
Share on other sites

This will create a selection set of a named block, see the answer from Lee Mac 

 

 

 

(setq ss (ssget "_X" '((0 . "INSERT") (2 . "SAL-TEKENBLAD_TITELBLOK"))))

 

Then to get the entity name

 

(setq entname (ssname ss 0))

 

And to get the entity description

 

(setq MyEnt (entget (ssname ss 0)))

 

 

 

 

-Edit-

Mhupp was typing as I was.... good idea to add in in case the block is also on other tabs

 

 

Edited by Steven P
Link to comment
Share on other sites

3 minutes ago, mhupp said:

I Usually just use ssget to get ent name of stuff.

 

(if (setq SS (ssget "X" '((0 . "INSERT") (2 . "SAL-TEKENBLAD_TITELBLOK"))))
  (foreach blk (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))

 

This will get you a selection set of all SAL-TEKENBLAD_TITELBLOK in the drawing.

If you want to get a particular titleblock you can further limit it down to a specific layout. 

by adding (410 . "Tab Name")

 

(setq SS (ssget "X" '((0 . "INSERT") (2 . "SAL-TEKENBLAD_TITELBLOK") (410 . "Sheet 3"))))

 

 

i need it in visual lisp but thx 

so i can change de active doc 

my goal is to get all layouts and ent names title blocks form every open dwg

Link to comment
Share on other sites

54 minutes ago, GroundWolf61 said:

i need it in visual lisp but thx

 

Look at what ronjonp is doing here then. will prob need to do a wcmatch for the titleblock name.

 

Link to comment
Share on other sites

Since in the intial post, you mention "EffectiveName", in case your title block is dynamic block, you need more complicate routines.

Working with multiple drawing also not simple, especially, in lisp.

Anyway I think you should solve the issue with a given parameter as an AcadDocument first. Not ActiveDocument, but an AcadDocument.

Another issue is your code: this one is wrong: the layout doesn't have Blocks collection property to get any named item from it:

(vla-item (vla-get-blocks LYT) "SAL-TEKENBLAD_TITELBLOK")

Instead, a layout has Block property and you got to loop through all the AcadEntity drawn in the layout via that block to find the right inserted block reference.

Edited by Linh
Link to comment
Share on other sites

58 minutes ago, Steven P said:

Just a question, for my curiosity, how are you looping through the open drawings?

Edited by GroundWolf61
Link to comment
Share on other sites

57 minutes ago, Steven P said:

Just a question, for my curiosity, how are you looping through the open drawings?

(defun C:SVLAY(/)
	(HB:SV_LAYOUT)
);end defun

(defun HB:SV_LAYOUT ( / DWG NDWG LST NLST L NL DL DL_LST)
	(foreach DWG (HB:SV_DWG_LIST)
		(setq NDWG DWG)
		(setq LST (getdrawinglayouts NDWG))
		(setq NLST (vl-remove (nth 0 LST) LST))
		(foreach L NLST
			(setq NL L)
			(setq DL (list NDWG NL))
			(setq DL_LST (cons DL DL_LST))
		);end foreach
	);end foreach	
	DL_LST
);end defun HB:SV_LAYOUT

(defun HB:SV_DWG_LIST ( / obj ACdocuments doccount i pathlist item path)
	(vl-load-com)
	(setq obj (vlax-get-acad-object))
	(setq ACdocuments (vla-get-documents obj))
	(setq doccount (vla-get-count acdocuments))
	(setq i 0)
	(setq pathlist'())
	(repeat doccount
		(setq item (vla-item acdocuments i))
		(setq path (vla-get-fullname item))
		(if (/= "" path)
			(setq pathlist (cons path pathlist))
		);end if
		(setq i (+ i 1))
	);end repeat
	pathlist
);end defun HB:SV_DWG_LIST

(defun getdrawinglayouts ( dwg / doc idx rtn )
    (if (setq doc (LM:getdocumentobject dwg))
        (progn
            (vlax-for lyt (vla-get-layouts doc)
                (setq rtn (cons (vla-get-name lyt) rtn)
                      idx (cons (vla-get-taborder lyt) idx)
                )
            )
            (vlax-release-object doc)
            (mapcar '(lambda ( n ) (nth n rtn)) (vl-sort-i idx '<))
        )
    )
)
 
(defun LM:getdocumentobject ( dwg / app dbx dwl err vrs )
    (cond
        (   (not (setq dwg (findfile dwg))) nil)
        (   (cdr
                (assoc (strcase dwg)
                    (vlax-for doc (vla-get-documents (setq app (vlax-get-acad-object)))
                        (setq dwl (cons (cons (strcase (vla-get-fullname doc)) doc) dwl))
                    )
                )
            )
        )
        (   (progn
                (setq dbx
                    (vl-catch-all-apply 'vla-getinterfaceobject
                        (list app
                            (if (< (setq vrs (atoi (getvar 'acadver))) 16)
                                "objectdbx.axdbdocument"
                                (strcat "objectdbx.axdbdocument." (itoa vrs))
                            )
                        )
                    )
                )
                (or (null dbx) (vl-catch-all-error-p dbx))
            )
            (prompt "\nUnable to interface with ObjectDBX.")
        )
        (   (vl-catch-all-error-p (setq err (vl-catch-all-apply 'vla-open (list dbx dwg))))
            (prompt (strcat "\n" (vl-catch-all-error-message err)))
        )
        (   dbx   )
    )
)
 
(vl-load-com) (princ)

 

  • Like 1
Link to comment
Share on other sites

Nice....

 

The reason I asked was that I haven't seen an effective way to have an open drawing interrogate or modify another open drawing. You can use a script on any closed drawings (there are some examples out there), some like scriptwriter,  Lee Macs. or Jeff Saunters will do it all in the background and you can write a script to open, operate on and close a drawing - and here you can use any LISP commands you want, but I have struggled to find a way to do that on an open drawing by LISP - the problem being that LISPS run on the drawing that started them off, and once you move from that the LISP won't keep running in the next drawing.

 

Depending what you want to do once you have the title block info I would be tempted to do it all on closed drawings, select the ones you want and do it all with a script

(scriptwriter, Lee Mac, Jeff Saunter, or mine (below) should all be able to do that)

 

 

 

 

  • Like 1
Link to comment
Share on other sites

HB:SV_DWG_LIST loops through the documents collection, get the document object, don't grab it but take the drawing path only.

Then, with the drawing path, Lee Mac function is used to get the document object back.

It is like you get the number, then you divide it to 2.5848, then using a function to get back the number by multiply with that 2.5848

Edited by Linh
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...