Jump to content

Creating a rectangle around the perimeter of a selected rectangular object


Nikon

Recommended Posts

Posted

This code works well with static blocks, but when working with dynamic blocks, 
the frame shift to the left. Is there any way to fix this? 
Or do need separate code for dynamic blocks? Thank you in advance...

;;; Creating a rectangle around the perimeter of a selected rectangular object
(defun c:ObjBoundary (/ obj objType vla-obj pt1 pt2 minPoint maxPoint pline)
  (princ "\nSelect object: ")
  (if (setq obj (entsel))
    (progn
      (setq obj (car obj)) 
      
          (setq objType (cdr (assoc 0 (entget obj))))
      (princ (strcat "\nThe object type is selected: " objType))
    
      (setq vla-obj (vlax-ename->vla-object obj))
      
      (setq pt1 (vlax-make-safearray vlax-vbDouble '(0 . 2)))
      (setq pt2 (vlax-make-safearray vlax-vbDouble '(0 . 2)))

      (vla-GetBoundingBox vla-obj 'pt1 'pt2)
      
      (setq minPoint (list 
                       (vlax-safearray-get-element pt1 0)
                       (vlax-safearray-get-element pt1 1)
                       (vlax-safearray-get-element pt1 2)
                     )
            maxPoint (list
                       (vlax-safearray-get-element pt2 0)
                       (vlax-safearray-get-element pt2 1)
                       (vlax-safearray-get-element pt2 2)
                     )
      )
      
      (setq pline (entmakex 
                   (list 
                     '(0 . "LWPOLYLINE")
                     '(100 . "AcDbEntity")
                     '(100 . "AcDbPolyline")
                     '(90 . 4)     
                     '(70 . 1)     
                     (cons 10 (list (car minPoint) (cadr minPoint) 0.0)) 
                     (cons 10 (list (car maxPoint) (cadr minPoint) 0.0)) 
                     (cons 10 (list (car maxPoint) (cadr maxPoint) 0.0)) 
                     (cons 10 (list (car minPoint) (cadr maxPoint) 0.0)) 
                   )
                 ))
      
      (princ "\nThe perimeter of the object is created as a polyline.")
      (princ)
    )
    (princ "\nThe object is not selected.")
  )
  (princ)
)

(vl-load-com)
(princ "\nThe perimeter of the object - enter the command Object Boundary to run.")
(princ)

 

ObjBoundary.png

Posted

Hi Nikon
Blocks are scarce in my diet.
But if you add any of those disobedient blocks 🤪, maybe I can help you.

  • Thanks 1
Posted (edited)
4 hours ago, GLAVCVS said:

Hi Nikon


Blocks are scarce in my diet.
But if you add any of those disobedient blocks 🤪, maybe I can help you.

Hi @GLAVCVS The blocks are obedient, but the bounding box is disobedient...

 

OBJBOUNDARY.dwg

Edited by Nikon
Posted

There are a couple of 'ATTDEF' objects with the 'VISIBLE' property disabled.

Img1.png

Posted (edited)

Use this to see for yourself

 

(defun c:todovis (/ cj n ent lstent)
  (if (setq cj (ssget "x" '((60 . 1))))
    (while (setq ent (ssname cj (setq n (if n (1+ n) 0))))
      (entmod (append (entget ent) (list '(60 . 0))))
    )
  )
  (princ)
)

 

Edited by GLAVCVS
  • Thanks 1
Posted

I guess you should just move those attributes a little to the right and make them invisible again.

  • Thanks 1
Posted (edited)
1 hour ago, GLAVCVS said:
(defun c:todovis (/ cj n ent lstent)
 (if (setq cj (ssget "x" '((60 . 1))))
 (while (setq ent (ssname cj (setq n (if n (1+ n) 0))))
 (setq lstent (append (setq lstent (entget ent)) (list '(60 . 0)))
 n (+ n 1)
 )
 (entmod lstent)
 )
 )
 (princ)
)

What a good code! Thanks!

Is it possible to configure the creation of a frame for dynamic blocks with attributes that go beyond the block?

Is it possible to ignore this in the code so that attributes are not taken into account when creating the frame?

todovis.png

Edited by Nikon
Posted (edited)
33 minutes ago, GLAVCVS said:

I guess you should just move those attributes a little to the right and make them invisible again.

If the attributes are inside the block, then the frame is created correctly.
Do I always need to check for hidden attributes?
It's a little uncomfortable...

todovis1.png   block-ok.png

Edited by Nikon
Posted

No
Simply modifying the matrix blocks will solve the problem.
If no one can do it on your own, or if no one has done it before, then I'll help you do it tomorrow.

  • Thanks 1
Posted (edited)

Hi

Try this

(defun c:makeBlockObedient (/ conj it n e le)
  (princ "\nSelect block to analyze...")
  (if (setq conj (ssget  '((0 . "INSERT"))))
    (while (setq it (ssname conj (setq n (if n (1+ n) 0))))
      (while (/= (cdr (assoc 0 (setq le (entget (setq e (entnext (if e e it))))))) "SEQEND")
	(if (assoc 60 le)
	  (if (setq p (getpoint (cdr (assoc 10 le)) "\nInvisible attribute detected: Indicates its new position (RIGHT CLICK to skip)...? "))
	    (vla-move (vlax-ename->vla-object e) (vlax-3d-point (cdr (assoc 10 le))) (vlax-3d-point p))
	  )
	)
      )
    )
  )
  (princ)
)

 

Edited by GLAVCVS
  • Like 1
Posted

Use it on any block of this type and save it

Posted (edited)
25 minutes ago, GLAVCVS said:
"\nInvisible attribute detected: Indicates  its new position (RIGHT CLICK to skip)...? "))

Hi

@GLAVCVS thanks!

This code makes the block Obedient.

Muchas gracias! Es super! Te debo otra taza de cafe... ☕

Edited by Nikon
  • Like 1
Posted

Hi Nikon

 

Isn't more easy, in your case, to get the insertion point as the lower-left corner, and for the top-right corner just add the width, height?   Multiplied with the scale, if necessary.

Posted (edited)
11 hours ago, Stefan BMR said:

Isn't more easy, in your case, to get the insertion point as the lower-left corner, and for the top-right corner just add the width, height?   Multiplied with the scale, if necessary.

Lisp ObjBoundary involves creating frames for different objects (not just blocks), so the insertion point should not be taken into account here (imho)...

The insertion points can be in different places, the borders should not depend on them....

Image 10.png

Edited by Nikon
Posted
Hace 12 horas, Stefan BMR dijo:

Hola Nikon

 

¿No sería más fácil, en tu caso, colocar el punto de inserción en la esquina inferior izquierda y, para la esquina superior derecha, simplemente sumar el ancho y la altura? Multiplicado por la escala, si es necesario.

@Stefan BMR
Simply, after running 'makeBlockObedient' for each block that needs it, copy the modified instance and paste it into a new drawing that will serve as a template in the future.

  • Thanks 1
Posted

Obviously, any new instance of that block created in that template will retain the necessary modifications so that the problem does not occur again.

  • Agree 1
Posted (edited)
12 minutes ago, GLAVCVS said:

Obviously, any new instance of that block created in that template will retain the necessary modifications so that the problem does not occur again.

Initially, I just wanted the creation of borders in the code ObjBoundary to be independent of the location of hidden or visible block attributes...

Edited by Nikon

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...