Lucay Posted December 12, 2024 Posted December 12, 2024 (edited) Hello, I'm asking for your help again with my plans with buildings. The idea here is that I have a layer containing buildings and other layers with hatched areas in different colors (red, orange, yellow...). Ideally, I'd like to write in an Excel file the names of the buildings in the red zone, those in the orange zone etc... I've started the following code, which gives me a selection of the polylines of the buildings in the red zone: (defun c:exposition (/ ss i sn e) (setq selz1 (ssadd)) (if (setq ss (ssget "x" (list '(0 . "LWPOLYLINE") '(8 . "emprise batiment polylignes")))) (repeat (setq i (sslength ss)) (if (ssget "_CP" (mapcar 'cdr (vl-remove-if-not '(lambda (p) (= (car p) 10)) (entget (setq sn (ssname ss (setq i (1- i))))) ) ) '((0 . "HATCH") (62 . 1)) ; red hatches ) (ssadd sn selz1) ) ) ) (sssetfirst nil selz1) (princ) ) I currently only have a selection of polylines in the code output. From this selection I'd like to obtain the names of the buildings and then write the information to an Excel file. My problem is that to find the names of the buildings I need to create blocks and the code above doesn't work with blocks. Hence my question: is it possible to give names to polylines or is it possible to adapt the above code with blocks? I haven't looked into the excel part yet (apart from the code available on github). Thanks Edited December 13, 2024 by SLW210 Added Code Tags! Quote
BIGAL Posted December 12, 2024 Posted December 12, 2024 (edited) I would use something like do the ssget "_CP" twice getting the text on a layer ie building name using the (0 . "TEXT") filter, same if you use a block with attributes of building details a better way. Edited December 12, 2024 by BIGAL Quote
Lucay Posted December 13, 2024 Author Posted December 13, 2024 Okay, so if I just change the line 4 command with the following one it should work the same? (setq ss (ssget "x" (list '(0 . "LWPOLYLINE") '(8 . "emprise batiment polylignes")))) --> (setq ss (ssget "x" (list '(0 . "INSERT") '(8 . "emprise batiment polylignes")))) Until now nothing happened when I try this, I thought it was not working for blocks. The method to get the text with the layer name, if I understand correctly, this means that I have to create as many layers as there are buildings? Quote
SLW210 Posted December 13, 2024 Posted December 13, 2024 In the future please use code tags for your code. (<> in the editor toolbar) Quote
BIGAL Posted December 13, 2024 Posted December 13, 2024 No something like this is ok. You get all the outside plines with a ssget, you run a loop of these plines and use a 2nd ssget "_CP" and look for text on your Building Layer. The "Building 1" can also be a block with an attribute of the building name. Can help with the Excel bit as well. You need to post a sample dwg say like image. Need a Excel sample as well so can see desired output. Quote
Lucay Posted December 16, 2024 Author Posted December 16, 2024 Ah yes, it's practical that way. Most of the building names aren't inside the building outlines, but I'll fix that :). Here's a diagram of what my drawings look like For the excel part, I'd like to have something like this: Thanks Quote
Lucay Posted January 15 Author Posted January 15 small update: I've followed your advice and created polylines for each building outline and inserted text inside each building. This works very well with the following code (only deal with red hatches) with one exception: the results are not consistent. In other words, sometimes there are no omissions, all the buildings have been taken into account and sometimes there are omissions. For the buildings that can be missing (always the same ones), there is nothing special: the text belongs to the desired layer, the polyline also belongs to the desired layer, etc. I can not differentiate those from the others.. Do you know what might be wrong? Thanks (defun c:exposition () (setq selz1 (ssadd)) (setq namesz1 nil) (if (setq ss (ssget "x" (list '(0 . "LWPOLYLINE") '(8 . "emprise batiment polylignes")))) (repeat (setq i (sslength ss)) (if (ssget "_CP" (mapcar 'cdr (vl-remove-if-not ;Remove items in the following list if the following predicate function evaluates to nil '(lambda (p) (= (car p) 10)) (entget (setq sn (ssname ss (setq i (1- i))))) ) ) '((0 . "HATCH") (62 . 1)) ) (ssadd sn selz1) ) ) ) (repeat (setq j (sslength selz1)) (if (setq sel (ssget "_CP" (mapcar 'cdr (vl-remove-if-not '(lambda (p) (= (car p) 10)) (entget (setq sn (ssname selz1 (setq j (1- j))))) ) ) '((0 . "TEXT,MTEXT") (8 . "numero marine"))) ) (progn (setq text (cdr (assoc 1 (entget (ssname sel 0))))) (setq namesz1 (cons text namesz1)) ) ) ) Quote
Lee Mac Posted January 15 Posted January 15 Note that the Crossing Polygon ("CP") selection mode is a graphical selection whose result will depend on the objects currently displayed within the drawing area - objects which fulfil the selection criteria but are not currently within the drawing area will not be selected. To avoid this, either zoom to a window slightly larger than the boundary of the crossing polygon, or zoom to extents (assuming that your drawing is not too large/congested - as this may also affect the selection). Quote
Lucay Posted January 16 Author Posted January 16 Thank for your reply Yes I tried zooming in or out but I did'nt notice any difference, I'll try again. What bothers me is that it's the same buildings that are forgotten most of the time and sometimes taken into account with a minute's interval between the different tests. I have tried another drawing (very basic plan) and I got the same issues with only a few buildings. Quote
Lucay Posted January 22 Author Posted January 22 I think I've found the problem: it's the type of hatching. I used "solid" hatching because it was cleaner and visually prettier but with "ANSI" style hatching, on the few occasions that I tested all the polylines were taken into account. Does anyone know why this is the case and if it's possible to have the same results with solid hatching? Thanks Quote
Lucay Posted January 27 Author Posted January 27 After further investigations, changing the type of hatching does change the results but there are still some outlines that are missing, and I still do not know why... Quote
GLAVCVS Posted Tuesday at 02:57 PM Posted Tuesday at 02:57 PM (edited) 1 hour ago, SLW210 said: Can you post a drawing? That's right, Lucay We can't understand 100% of what your problem is if we can't see the same thing you see. Edited Tuesday at 02:59 PM by GLAVCVS Quote
GLAVCVS Posted Tuesday at 07:35 PM Posted Tuesday at 07:35 PM I have drawn several rectangles, inserted a text inside each one and created a hatch for each rectangle. I have changed the color of several of these hatches to red and applied different hatch patterns to them: 'SOLID', 'AR-CONC' and 'AR-B816'. But your code always works fine returning a list with the content of the texts included in each red hatch. So it may be something that is happening in your drawing. Quote
Lucay Posted Wednesday at 05:29 AM Author Posted Wednesday at 05:29 AM Hello, Yes I was going to do that but I can't post the drawing I'm working on. I'll try to create an equivalent. I hope to send it to you this weekend. Thanks guys Quote
Lucay Posted Saturday at 07:46 PM Author Posted Saturday at 07:46 PM I had trouble making an example that didn't work every time... In the attached files, I got different results depending on the type of hatch. I have the impression that the outlines that are not always detected are the smaller ones. The "Test AUTOCAD 2" has strange results (only a few outlines are detected with solid hatches and much more with ansi type). In my original file, I have a lot more buildings, much more different shapes, size etc.. If you have any suggestions... Thank you Test AUTOCAD.dwg Test AUTOCAD 2.dwg Quote
GLAVCVS Posted Saturday at 09:01 PM Posted Saturday at 09:01 PM I think I understand your problem now. But I have a question: what happens when a building is divided between 2 hatches? Quote
Lucay Posted Saturday at 09:25 PM Author Posted Saturday at 09:25 PM I haven't attached all the code, but in fact I'm looking for all the buildings for each colour, and then I'm sorting if a building is between two hatching of different colours. I prioritise certain colours in these cases. In the following lines, ("nameszi" stands for the names list of the buildings that are crossed by one colour - but possibly another) (setq rmv nil) (foreach elt namesz2 (if (member elt namesz1) (setq namesz2 (vl-remove elt namesz2)) (setq rmv (cons elt rmv)) ) ) (foreach elt namesz3 (if (or (member elt namesz2) (member elt rmv)) (setq namesz3 (vl-remove elt namesz3)) (setq rmv (cons elt rmv)) ) ) (...) Quote
GLAVCVS Posted yesterday at 12:14 AM Posted yesterday at 12:14 AM (edited) I think your approach should be the other way around: get the lists of points from the hatches and make selection sets of the building perimeters and their centroid texts. Edited yesterday at 12:15 AM by GLAVCVS Quote
GLAVCVS Posted yesterday at 12:22 AM Posted yesterday at 12:22 AM Everything will be much easier Quote
Recommended Posts
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.