Having trouble selecting the title block

Having trouble selecting the title block

angelinabrown0123
Advocate Advocate
1,534 Views
26 Replies
Message 1 of 27

Having trouble selecting the title block

angelinabrown0123
Advocate
Advocate

please help,

I am trying to print by selecting the title block, my block name is "MyBox" but it is not getting selected, please fix this code in selecting the block.

0 Likes
Accepted solutions (2)
1,535 Views
26 Replies
Replies (26)
Message 2 of 27

ronjonp
Mentor
Mentor
Accepted solution

It's because your titleblock is dynamic and the actual name is '*U9'. 

 

Change your filter to this: 

(setq ss (ssget '((0 . "INSERT") (2 . "MyBox,`*U*"))))
0 Likes
Message 3 of 27

angelinabrown0123
Advocate
Advocate

That worked great, Thank you very much! 

0 Likes
Message 4 of 27

ronjonp
Mentor
Mentor

@angelinabrown0123 wrote:

That worked great, Thank you very much! 


Glad to help! 🙂

0 Likes
Message 5 of 27

calderg1000
Mentor
Mentor

Regards @angelinabrown0123 

If what you want is to select the block, with this line of code you can generically select any block. In your case you have a block with attributes; that will change its name when the attributes change.

 

(setq s (ssget'((0 . "insert"))))

 To get your name:

(vla-get-name(vlax-ename->vla-object(ssname s 0)))

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 6 of 27

Sea-Haven
Mentor
Mentor

We always had our title blocks at 0,0 so you can look for a block using the ssget "F" or "CP" which use co-ordinates to search for objects, this also works for a pt.

 

(setvar 'osmode 0) ; turn off snap or use a zoom in

 (setq ss (ssget (list 0 0)))
<Selection set: 000000006F0C67F0>

(entget (ssname ss 0))
((-1 . <Entity name: 3d7debe0>) (0 . "INSERT") (5 . "102B6")

0 Likes
Message 7 of 27

Kent1Cooper
Consultant
Consultant

@Sea-Haven wrote:

We always had our title blocks at 0,0 so you can look for a block using the ssget "F" or "CP" ....

(setq ss (ssget (list 0 0)))

....


That's fine if there's some drawn element at the insertion point, such as a corner of border lines in the Block.  But if 0,0 is the insertion point and the corner of the sheet, and the border/outline itself is inset from there, that won't work any more than picking manually at 0,0 would, with nothing there to pick on.

 

But in that case, you could get it with filtering for a Block with that as its insertion point:
(setq ss (ssget '((0 . "INSERT") (10 0.0 0.0 0.0))))

or even, if there would not be anything else drawn with a 10-code entry at that location other than the Block [such as the start of a Line], merely:
(setq ss (ssget '((10 0.0 0.0 0.0))))

Kent Cooper, AIA
0 Likes
Message 8 of 27

Sea-Haven
Mentor
Mentor

We had a rule at my work move the title block and get your butt kicked. yeah had a move it back to 0,0 lisp, multiple users.

 

Only problem with dxf 10 is that ssget still asks for a selection where as (ssget pt) works without user input yes has that draw back of possible miss or multiple chosen, using filter helps 

 

(entget (ssname (ssget (list 0.0 0.0 0.0)(list (cons 0 "INSERT"))) 0))

0 Likes
Message 9 of 27

angelinabrown0123
Advocate
Advocate

The problem of selecting blocks has been solved by @ronjonp, but I am facing another problem with lisp, the enclosing lisp does not print with some blocks nothing is showing in pdf.

0 Likes
Message 10 of 27

pbejse
Mentor
Mentor

@angelinabrown0123 wrote:

..., the enclosing lisp does not print with some blocks nothing is showing in pdf.


Check your UCS...

or you can do this

...
"No"
"Window"
(trans llpt 0 1)
(trans urpt 0 1)
"Fit"
"Center"
"yes"
...

HTH

0 Likes
Message 11 of 27

Kent1Cooper
Consultant
Consultant

@Sea-Haven wrote:

....

Only problem with dxf 10 is that ssget still asks for a selection where as (ssget pt) works without user input yes has that draw back of possible miss or multiple chosen, using filter helps 

....


If there won't be any other Block(s) or Xref(s) inserted at that point, you can get it without User input:

(setq ss (ssget "_X" '((10 0.0 0.0 0.0))))

and that could be further constrained to only the current space, only Block/Xref [in case there could be something like a Line start point or Text insertion point or Circle center there], etc.

Kent Cooper, AIA
0 Likes
Message 12 of 27

angelinabrown0123
Advocate
Advocate

@pbejse ,

Thanks for the code, I also tested on some other drawing with new code but it still doesn't generate PDF properly.

0 Likes
Message 13 of 27

pbejse
Mentor
Mentor

@angelinabrown0123 wrote:

Thanks for the code, I also tested on some other drawing with new code but it still doesn't generate PDF properly.


Quick question:

Why is the UCS rotated ? Are you planning to select mulitple titleblocks? [ that is what the lsp file was intending to do from the looks of it  . repeat / vl-sort / foreach ] ... you will have an issue with the pdf name(s).

 

 

0 Likes
Message 14 of 27

calderg1000
Mentor
Mentor

Regards @angelinabrown0123 

Your code works fine but in the WCS, but for some reason all your files are in the UCS, but for some reason the provided transformation is not working.
It would not be advisable to work the plots from the WCS and avoid problems. Because its blocks are rotated...?

it seems to apply Get-boundingbox to obtain the limit points, in this case it is not the most appropriate

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 15 of 27

Sea-Haven
Mentor
Mentor

This has been looked at before for me never plot in model space always a layout where the mview can be twisted to match a UCS and scale, would be worth looking into.

 

A example 10km road mulitple sheets and road approx horizontal on all sheets. Just multiple UCS. 

 

I went to a  layout of your dwg. The title is true size so its 841 long. It took like 2 minutes at most 

Just drew a line for angle of title block in Model space

Went to layout1 inserted MYBOX scale 1 0,0 etc

Did Mview inside mybox

Dbl click into mspace then zoom extents

Can see the line I made did UCS OB pick line, then Plan, then zoom e

Now set plot scale and erase temporary line for UCS.

Lock viewport so no false zooms

All done

 

Last question why is block dynamic and not a normal block ?

0 Likes
Message 16 of 27

pbejse
Mentor
Mentor
Accepted solution

My query regarding multiple blocks has been left unanswered, so here's a version with one selection.

(defun c:SpA1 (/ UCS2WCSMatrix WCS2UCSMatrix ucs-bbox ss file hnd pts)

;; Doug C. Broad, Jr.
;; can be used with vla-transformby to
;; transform objects from the UCS to the WCS
(defun UCS2WCSMatrix ()
  (vlax-tmatrix
    (append
      (mapcar
	'(lambda (vector origin)
	   (append (trans vector 1 0 t) (list origin))
	 )
	(list '(1 0 0) '(0 1 0) '(0 0 1))
	(trans '(0 0 0) 0 1)
      )
      (list '(0 0 0 1))
    )
  )
)
  
;; transform objects from the WCS to the UCS
(defun WCS2UCSMatrix ()
  (vlax-tmatrix
    (append
      (mapcar
	'(lambda (vector origin)
	   (append (trans vector 0 1 t) (list origin))
	 )
	(list '(1 0 0) '(0 1 0) '(0 0 1))
	(trans '(0 0 0) 1 0)
      )
      (list '(0 0 0 1))
    )
  )
)

;; UCS-BBOX (gile)
;; Returns the UCS coordinates of the object bounding box about UCS
;;
;; Argument
;; obj : a graphical object (ename or vla-object)
;;
;; Return
;; a list of left lower point and right upper point UCS coordinates

(defun ucs-bbox	(obj / space bb minpoint maxpoint line lst)
  (vl-load-com)
  (and (= (type obj) 'ENAME)
       (setq obj (vlax-ename->vla-object obj))
  )
  (vla-TransformBy obj (UCS2WCSMatrix))
  (setq bb (vla-getboundingbox obj 'minpoint 'maxpoint))
  (vla-TransformBy obj (WCS2UCSMatrix))
  (list
    (vlax-safearray->list minpoint)
    (vlax-safearray->list maxpoint)
  )
)

  
(vl-load-com)
	(if (setq ss (ssget "_+.:S:E" '((0 . "INSERT") (2 . "MyBox,`*U*"))))
        (progn	 
                (setq hnd (ssname ss 0)
                     file (strcat (getvar 'DWGPREFIX)
                                   (substr (setq dwg (getvar 'DWGNAME)) 1 (- (strlen dwg) 4))
                                   ".pdf"
                           )
                )

                (if (findfile file)
                    (vl-file-delete file)
                )

	       (setq pts (ucs-bbox (vlax-ename->vla-object hnd)))		  
               (command "-plot"
                         "yes"
                         "Model"
                         "DWG TO PDF.PC3"
                         "ISO A1 (594.00 x 841.00 MM)"
                         "Millimeters"
                         "Landscape"
                         "No"
                         "Window"
                         (Car pts)
                         (Cadr pts)
                         "Fit"
                         "Center"
                         "yes"
                         "acad.ctb"
                         "yes"
                         "No"
                        file
                        "Yes"
                        "Yes"
                )
            )
	  )
    (princ)
)

HTH

 

 

Message 17 of 27

angelinabrown0123
Advocate
Advocate

Wow. Its like magic! Thank you @pbejse. Way above my pay grade.

Many thanks for taking an interest in my project.

0 Likes
Message 18 of 27

angelinabrown0123
Advocate
Advocate

Hi @pbejse ,

Please help me one more time if possible, I have to select title block automatically, I tried to little change the code for automatically select the title block but it is not visible in printing all the objects.

 

(if (setq ss (ssget "_X" '((0 . "INSERT") (2 . "MyBox,`*U*"))))

 

thank you in advanced

0 Likes
Message 19 of 27

pbejse
Mentor
Mentor

@angelinabrown0123 wrote:

I have to select title block automatically,


Going back to my previous query, will there be more than one "MyBox" block per drawing? Very important to know this seemingly minor detail @angelinabrown0123 

 

0 Likes
Message 20 of 27

angelinabrown0123
Advocate
Advocate

@pbejse 

Currently there is only one title block in the drawing. But in future there may be multiple title block in the single drawing.

0 Likes