Jump to content

Recommended Posts

Posted (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 by SLW210
Added Code Tags!
  • Replies 23
  • Created
  • Last Reply

Top Posters In This Topic

  • Lucay

    12

  • GLAVCVS

    7

  • BIGAL

    2

  • SLW210

    2

Top Posters In This Topic

Posted Images

Posted (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 by BIGAL
Posted

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?

 

Posted

In the future please use code tags for your code. (<> in the editor toolbar)

Posted

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.

 

image.png.ae32974b154766d16d32c59dd4f32472.png

 

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.

Posted

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

image.thumb.png.d030f94663a7ee9e756dc6f1cb39c7c2.png

 

For the excel part, I'd like to have something like this:

 

image.png.dd15234bba3758cbc5908ff7dd6a9c68.png

 

Thanks

  • 5 weeks later...
Posted

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

 

Posted

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

Posted

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.

Posted

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

Posted

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

Posted (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 by GLAVCVS
Posted

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.

Posted

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

Posted

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

Posted

I think I understand your problem now.
But I have a question: what happens when a building is divided between 2 hatches?

Posted

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

(...)

 

Posted (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 by GLAVCVS

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