finding empty 2D area

finding empty 2D area

kazfukuoka
Enthusiast Enthusiast
467 Views
7 Replies
Message 1 of 8

finding empty 2D area

kazfukuoka
Enthusiast
Enthusiast

Hi Community,

This question is about 2D drawing (ignoring Z).
Is there any way to see if a rectangular area is empty?
Something like bool IsEmpty(x, y, w, h).

 

As a background, here is what I want to do: There are some entities of interest in the drawing.
I want to add information text close to each of those entities.
To find a space to draw the text, I want to find an empty space near each of such entities.

0 Likes
Accepted solutions (1)
468 Views
7 Replies
Replies (7)
Message 2 of 8

norman.yuan
Mentor
Mentor
Accepted solution

Assume that you want to do it in a regular AutoCAD session with a MdiActiveDocument (that is, there is Editor available), you can simply use 

Edit.SelectWindow() to see if the PromptResult returns OK or Error. OK means something inside the selecting window, Error mean nothing is selected (that is what you want to know). Make sure you zoom to the window before calling SelectWindow().

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 8

kazfukuoka
Enthusiast
Enthusiast

Thank you Norman, this will do for now.

Although Edit.SelectWindow() is handy, it cannot be the final solution because of the zooming requirement.
I wish to find a nicer solution for the future improvement.

0 Likes
Message 4 of 8

kerry_w_brown
Advisor
Advisor

@kazfukuoka ,

How much user interaction will be allowed ?

 

Are you manually selecting the  "entities of interest" ?

 

Regards,


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 5 of 8

kazfukuoka
Enthusiast
Enthusiast

Hi Kerry, I am wishing for a fully automatic way.
The "entities of interest" is created by my program.

 

In case user interaction is allowed,
I could use jig to let user select a good space.

Message 6 of 8

a.kouchakzadeh
Advocate
Advocate

in that case you know the cordinates of your drawing. you can zoom extents then create a region with that rectangle.

since entities of interest are created by your programs, now you can get geometric extents of those entities and create another region.

subtract the entity regions from the large region and you will be able to get some thing. then you can convert that region to a polyline using Giles Geometry extension. then you can find the empty areas.

Message 7 of 8

kerry_w_brown
Advisor
Advisor

@kazfukuoka wrote:

Hi Kerry, I am wishing for a fully automatic way.
The "entities of interest" is created by my program.

 

In case user interaction is allowed,
I could use jig to let user select a good space.


Yes, I was going to suggest using an MTEXT Jig to place the notation ( with a leader if needed )
This could  fairly easily be built into the workflow loop  

loop {

    zoom to area of interest 

    create "entities of interest"     

    invoke  Jig for relevant MText
}

 

Added: Link : perhaps something like this from Gilles

https://forums.autodesk.com/t5/net/how-to-crate-mtext-and-visible-with-the-cursor-amp-exit-when/m-p/...

 

Added afterthought: Even if you are able to develop a full automatic smart process you'll probably want/need to check processed object and each MText  notation. . . .  so there may not be much difference in total time spent . . . .except for the simpler code development  😀

 

Regards,

 


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
Message 8 of 8

kazfukuoka
Enthusiast
Enthusiast

Both of you are right. I go with Edit.SelectWindow().

 

I worried too much considering the zooming step ugly.
But when the most important thing is to get the job done, such extra one step is not bad.
Working on AutoCAD requires lots of compromise anyway 😀

 

Thanks a lot

0 Likes