Message 1 of 35
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
How might I go about getting the nested information from all the blocks in a layer.
Solved! Go to Solution.
How might I go about getting the nested information from all the blocks in a layer.
Solved! Go to Solution.
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?
Post some sample of real/imaginary situation - there is just one block in your drawing... - and the form of output you need.
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.
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.
I appreciate the starting point, I'm gonna look into to these. Thank you
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)
)
Sweet! Ill give it a read.
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)
)
@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.
That gives me a print list of "insert" and "point". Does that mean I can extract the "pt#" text from fsd into another variable?
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) )
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) )
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.
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)
)
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")
)
)
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) )
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.