Gather list data from all blocks in a layer

Gather list data from all blocks in a layer

etilley327KA
Advocate Advocate
2,123 Views
34 Replies
Message 1 of 35

Gather list data from all blocks in a layer

etilley327KA
Advocate
Advocate

How might I go about getting the nested information from all the blocks in a layer.

0 Likes
Accepted solutions (2)
2,124 Views
34 Replies
Replies (34)
Message 2 of 35

Sea-Haven
Mentor
Mentor

Explain more what you mean by nested data.

0 Likes
Message 3 of 35

etilley327KA
Advocate
Advocate

I have some points which are a nested block. I need the X,Y,Z and some of the text data. Is there a way to get this list information without modifying the shots?

0 Likes
Message 4 of 35

ВeekeeCZ
Consultant
Consultant

Post some sample of real/imaginary situation - there is just one block in your drawing... -  and the form of output you need.

0 Likes
Message 5 of 35

etilley327KA
Advocate
Advocate

I'm looking to pull all the data from the the points in the "shot" layer and make a line from the first and the last shot numbers. Also, I'm looking to evaluate the Z elevations for range, average from four shots the users selects and insert a text between those four selected shots as a text.

0 Likes
Message 6 of 35

ВeekeeCZ
Consultant
Consultant

Learn how to use these functions. They are fairly simple to use and quite powerful.

 

 

Say, you need to get info from some attribute called "DESC2"... it's very simple:

(getpropertyvalue (car (entsel)) "DESC2")

 

But, if you need to put a block into Z elevation

(setpropertyvalue (setq e (car (entsel))) "Position/Z" (atof (getpropertyvalue e "ELEV2")))

 

And the other things.. these are the motivation to learn which I shouldn't deprive you of.

0 Likes
Message 7 of 35

etilley327KA
Advocate
Advocate

I appreciate the starting point, I'm gonna look into to these. Thank you

0 Likes
Message 8 of 35

etilley327KA
Advocate
Advocate

I apologize, I'm still trying to learn a lot of this and after reading those descriptions I'm still a little lost on the logic of how I would go about applying this. If I collected all of the data I needed from the layer the objects are in, how do I go about creating a list of that data for evaluation.

 

(defun c:FDERT ( / fs fsd)
(setq fs (ssget "_X" (list(cons 8 "SHOT"))))
(dumpallproperties(setq fsd(entget(car(fs)"pt#"))))
(princ)
)

0 Likes
Message 9 of 35

ВeekeeCZ
Consultant
Consultant

You were apparently absent when selection set processing was discussed, you can catch up HERE. My favorite one is 2a method.

Message 10 of 35

etilley327KA
Advocate
Advocate

Sweet! Ill give it a read.

0 Likes
Message 11 of 35

etilley327KA
Advocate
Advocate

So if I understand correctly I need it to cycle through all the objects. On my watch for "fsd" I'm getting nil, is this because its a block? 😂 Sorry

(defun c:FDERT ( / fs fsd x n s i e)
(if (setq fs(ssget "_X" (list(cons 8 "SHOT"))))
(progn
(setq i 0
n (sslength fs)
)
(while (< i n)
(setq e (ssname fs i)
fsd (cdr (assoc 0 (entget e)))
i (1+ i)
)
)
)
)
(princ)
)

0 Likes
Message 12 of 35

ВeekeeCZ
Consultant
Consultant

@etilley327KA wrote:

So if I understand correctly I need it to cycle through all the objects. On my watch for "fsd" I'm getting nil, is this because its a block? 😂 Sorry

(defun c:FDERT ( / fs fsd x n s i e)
(if (setq fs(ssget "_X" (list(cons 8 "SHOT"))))
(progn
(setq i 0
n (sslength fs)
)
(while (< i n)
(setq e (ssname fs i)
fsd (cdr (assoc 0 (entget e)))
i (1+ i)
)

(write-line fsd)
)
)
)
(princ)
)


 

It works for me. Try it with that red line to print it to the command line.

0 Likes
Message 13 of 35

etilley327KA
Advocate
Advocate

That gives me a print list of "insert" and "point". Does that mean I can extract the "pt#" text from fsd into another variable?

0 Likes
Message 14 of 35

ВeekeeCZ
Consultant
Consultant
Accepted solution

FSD is the name of the entity, INSERT means it's a block reference, POINT is a point.

It's kinda useless at this point, rather add "INSERT" to the SSGET filter. As you can see from (assoc 0 (entget e)) it's paired with 0 code number...

 

(if (setq fs (ssget "_X" '((0 . "INSERT") (8 . "SHOT")))) ...

 

The e variable is why you need to go thru all this circus, that's ename. The other valuable info is getting an entity definition list (d). You did it, but did not save it. 

 

(defun c:FDERT ( / fs fsd x n s i e)
  (if (setq fs(ssget "_X" '((0 . "INSERT") (8 . "SHOT"))))
    (progn
      (setq i 0
	    n (sslength fs)
	    )
      (while (< i n)
	(setq e (ssname fs i)
	      d (entget e)
	      i (1+ i)
	      )
	
	(print e)
	;(print d) or this
	)
      )
    )
  (princ)
  )

 

0 Likes
Message 15 of 35

ВeekeeCZ
Consultant
Consultant

One step further to play with. You should have learned the 2a method 🙂

 

(defun c:ListDescNumbers ( / s i e c)
  
  (if (setq s (ssget "_X" '((0 . "INSERT")
			    (2 . "SRVPNO5")
			    ;(8 . "SHOT")
			    )))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i))))
      (setq c (getpropertyvalue e "DESC2"))
      (print c)))

  (princ)
  )

 

Message 16 of 35

etilley327KA
Advocate
Advocate

Sweet! I'm slowly starting to understand this better, I really appreciate it. I'm gonna see were I can get from here. I'm sure this wont be my last question. Thanks again.

0 Likes
Message 17 of 35

etilley327KA
Advocate
Advocate

Do you know how I can get the start point of the entity for a certain "pt#" from the data?

 

(defun c:FDERT ( / fs i e fsn fsd)

(if (setq fs (ssget "_X" '((0 . "INSERT")
(2 . "SRVPNO5")
(8 . "SHOT")
)))
(repeat (setq i (sslength fs))
(setq e (ssname fs (setq i (1- i))))
(setq fsn (getpropertyvalue e "pt#"))))
(setq fsd (entget e))
(setq pnt(cdr(assoc 10 fsd)))
(princ)
)

0 Likes
Message 18 of 35

Sea-Haven
Mentor
Mentor

If you want to look for pt# = 1018 then you would get all the blocks and look at the block one by one, make sure it has attributes, then look at the tag details, Ok 2 methods if PT# is 1st attribute you can use a Item = 1 the 1st atrribute, or (nth 0 attributes) , or you can loop through all attributes check the tag name and if correct = "PT#" then,

get "Textstring" and compare is = "1018" if so you have a match.

 

Here is an example with "PT#" being 1st attribute. So no tag name check required.

 

(setq num "1018")
(setq fs (ssget "_X" '((0 . "INSERT")
(2 . "SRVPNO5")
(8 . "SHOT")
)))
(repeat (setq i (sslength fs))
(setq obj (vlax-ename->vla-object (ssname fs (setq i (- i 1)))))
(setq atts (vlax-invoke obj 'Getattributes))
(if (= (vla-get-textstring (nth 0 atts)) num)
(alert "found point")
)
)

 

 

Message 19 of 35

ВeekeeCZ
Consultant
Consultant

Well, don't really understand what you want.

 

IMHO another step you need is to learn how to build a list. You already have a selection set, also a sort of group of objects, but difficult to work with. A list is much more versatile and easier to  manipulate, supported by most functions, simply a fundamental lisp structure.

 

See HERE

* lst from 2 (or more) itms >> (list itm1 itm2). A special case is a dotted pair (cons itm1 itm2)

* itm add to lst -> (cons itm lst) - not the other way around!! The most preferable way. Also possible (append lst (list itm)) if the order matters.

* merge two lsts -> (append lst1 lst2). 

 

Then you need the sort func HERE 

 

Well, once you know all that, you would understand the code below (spoiler)

 

(vl-load-com)

(defun c:ConnectByPointNumbers ( / s i e l)
  
  (if (setq s (ssget "_A" '((0 . "INSERT")
			    (2 . "SRVPNO5")
			    ;(8 . "SHOT")
			    )))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i))))
      (if (not (vl-catch-all-error-p (setq a (vl-catch-all-apply 'getpropertyvalue (list e "PT#")))))      ; just in case - it prevents error if block have no att
	(setq l (cons (list (atoi a) (getpropertyvalue e "Position/X") (getpropertyvalue e "Position/Y")) l))))) 
  
  (and l
       (setq l (vl-sort l '(lambda (e1 e2) (< (car e1) (car e2)))))
       (entmake (append (list '(0 . "LWPOLYLINE") '(100 . "AcDbEntity") '(100 . "AcDbPolyline") '(70 . 0)  (cons 90 (length l)))
			(mapcar '(lambda (p) (cons 10 (cdr p))) l))))
  (princ)
  )

 

0 Likes
Message 20 of 35

etilley327KA
Advocate
Advocate

Great! Thanks for all the information. I'm gonna take some time and see if I can wrap my brain around all of this. I appreciate the schooling obi-wan.

0 Likes