After nentsel check if the object is part of a block or not

After nentsel check if the object is part of a block or not

eakos1
Advocate Advocate
699 Views
11 Replies
Message 1 of 12

After nentsel check if the object is part of a block or not

eakos1
Advocate
Advocate

Hello,

 

I want to let select polylines inside a block or not inside a block. So I need an if function to decide if it is inside or not because I will be needed run different codes. 

How can I do it? Can someone help me ?

 

 

 

0 Likes
Accepted solutions (2)
700 Views
11 Replies
Replies (11)
Message 2 of 12

ВeekeeCZ
Consultant
Consultant
Accepted solution

Just check the length of returning list. Whether it's 2 (single entity) or 4 (nested entity)

 

It's too easy...

 


(defun c:test ()
  (if (setq s (nentsel))
    (if (= 4 (length s))
      "nested"
      "main"))
  )
Message 3 of 12

komondormrex
Mentor
Mentor

won't work with block's attribute.

0 Likes
Message 4 of 12

komondormrex
Mentor
Mentor

with any of block's nested entity

(if (= "AcDbBlockReference"
       (vla-get-objectname
	 (vla-objectidtoobject
	   (vla-get-activedocument (vlax-get-acad-object))
	   (vla-get-ownerid (vlax-ename->vla-object (car (nentsel "\nPick ename to check nestedness: "))))
	 )
       )
    )
    (princ "\nBlock Nested")
    (princ "\nRaw")
)

 

0 Likes
Message 5 of 12

eakos1
Advocate
Advocate

Sorry, but this works not. 

I've just made a simple POLYLINE, put it in a BLOCK and always shows as result: nRaw

In your program is "AcDbBlockReference" as criteria, but in reality it gives as result for me: "AcDbBlockTableRecord" 

 

And if I have an "heavy" POLYLINE in a block than your code gives as result: "AcDb2dPolyline" 

 

So this is code is not reliable. 

 

0 Likes
Message 6 of 12

eakos1
Advocate
Advocate

nentsel is somehow tricky, if I check the type with this way (cdr (assoc 0 (entget (car a)))), 

light POLYLINE: "LWPOLYLINE"

heavy POLILINE: "VERTEX

 

however with entsel selection:

light POLYLINE: "LWPOLYLINE"

heavy POLILINE: "POLYLINE

 

I don't know why it is so. 

0 Likes
Message 7 of 12

Sea-Haven
Mentor
Mentor
Accepted solution

Just a thought (ssget pt) the pt is the (cadr of the (nentsel the returned ssget should be 1 item and object type should be a "INSERT". have used this often to get an attribute and then the block as 1 pick. 

0 Likes
Message 8 of 12

eakos1
Advocate
Advocate

Thanks, it works 🙂

Even by blocks with attributes 

(if (= "INSERT"
       (cdr
	 (assoc	0
		(entget
		  (ssname (ssget (cadr (setq a (nentsel "\n Select the object which can be inside of a BLOCK too"))))
			  0
		  ) ;_ ssname
		) ;_ entget
	 ) ;_ assoc
       ) ;_ cdr
    ) ;_ =
  (princ "\nBlock Nested")
  (princ "\nRaw")
)

 

 

0 Likes
Message 9 of 12

komondormrex
Mentor
Mentor

well, sadly yes.

another one to check nestedness to a certain block, modelspace and paperspace included.

 

(defun c:check_nestedness (/ block_group nename)
	(if (setq block_group (assoc 2 (entget (cdr (assoc 330 (setq nename (entget (car (nentsel)))))))))
	  	(princ (strcat "\n \"" (cdr (assoc 0 nename)) "\" nested in block \"" (cdr block_group) "\""))
	  	(if (setq block_group (assoc 2 (setq nename (entget (cdr (assoc 330 nename))))))
		  (princ (strcat "\n \"" (cdr (assoc 0 nename)) "\" nested in block \"" (cdr block_group) "\""))
		  (if (setq block_group (assoc 2 (entget (cdr (assoc 330 nename)))))
		    (princ (strcat "\n \"" (cdr (assoc 0 nename)) "\" nested in block \"" (cdr block_group) "\""))
		    (princ "\nRaw")
		  )
	  	)
	)
  	(princ)
)

 

0 Likes
Message 10 of 12

eakos1
Advocate
Advocate

I think it work not well. 

If I select a simple LINE not in BLOCK I get this result:

"LINE" nested in block "*MODEL_SPACE"
"\n \"LINE\" nested in block \"*MODEL_SPACE\""

 

It is good that shows where the LINE is located, but it is not a BLOCK. The result should  be "Raw", am I right? I newer get "Raw" result. 

In case of BLOCK selection it works fine. 

 

 

0 Likes
Message 11 of 12

ВeekeeCZ
Consultant
Consultant

@eakos1 wrote:

nentsel is somehow tricky, if I check the type with this way (cdr (assoc 0 (entget (car a)))), 

light POLYLINE: "LWPOLYLINE"

heavy POLILINE: "VERTEX

 

however with entsel selection:

light POLYLINE: "LWPOLYLINE"

heavy POLILINE: "POLYLINE

 

I don't know why it is so. 


 

The relation VERTEX to POLYLINE is the same as ATTRIB to INSERT. 

Read more HERE about heavy polylines.

0 Likes
Message 12 of 12

komondormrex
Mentor
Mentor

that is because every entity belongs to a certain block. if an entity not belongs to a custom block it should belong to the model space or paper space block, because as a matter of fact they're blocks. if you want to exclude spaces from result you may try the code following.

(defun c:check_nestedness (/ block_group nename)
	(if (setq block_group (assoc 2 (entget (cdr (assoc 330 (setq nename (entget (car (nentsel)))))))))
	  	(setq nename (cdr (assoc 0 nename)))
	  	(if (setq block_group (assoc 2 (setq nename (entget (cdr (assoc 330 nename))))))
		  (setq nename (cdr (assoc 0 nename)))
		  (if (setq block_group (assoc 2 (entget (cdr (assoc 330 nename)))))
		    (setq nename (cdr (assoc 0 nename)))
		    (princ "\nRaw")
		  )
	  	)
	)
	(if (or (= "*Model_Space" (cdr block_group)) (= "*Paper_Space" (cdr block_group)))
		(princ (strcat "\n \"" nename "\" is raw"))
		(princ (strcat "\n \"" nename "\" nested in block \"" (cdr block_group) "\""))
	)
  	(princ)
)
0 Likes