How to find the center of Blocks?

How to find the center of Blocks?

Anonymous
Not applicable
4,040 Views
11 Replies
Message 1 of 12

How to find the center of Blocks?

Anonymous
Not applicable

There is a code I'm working on right now, where the code will find and display the coordinates and radius of ONLY circle and arcs.

I can filter them with:

 

(SSGET "_X" '((0 . "ARC,CIRCLE")))

 

BUT, I also have blocks where two circles with different radius is placed on the same coordinate.

Since these are blocks, the code above does not recognize the blocks as circles, so I can't get the coordinates.

I've tried:

 

(SETQ P1 (getstring T "Enter here: "))
\(SETQ ss1 (ssget "_x" '((0 . "INSERT")(2 . P1)))

 

CPT (CDR (ASSOC 10 (SETQ ENTS (ENTGET EN))))
PTR (CDR (ASSOC 40 (SETQ ENTS (ENTGET EN))))
UCPT (trans CPT 0 1)

 

Which does allow me to get the coordinate of the center, but not the radius. Is ASSOC 40 not the right number to use?

If someone can help me, that would be very helpful.

0 Likes
Accepted solutions (1)
4,041 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable

Sorry made a tremendous mistake, and wrote stuff on the tag which I didn't mean to.
Tried the code again it turns out that my SSGET doesn't seem to work now.

I think I thought that the SSGET was working by mistake.

If someone can think of the problem, that would be great too.

0 Likes
Message 3 of 12

dlanorh
Advisor
Advisor

Are these blocks dynamic, i.e. the circles can be different sizes; or static, the circles in the blocks are always the same size?

Are there two circles in the same block?

 

I am not one of the robots you're looking for

0 Likes
Message 4 of 12

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....

(SETQ P1 (getstring T "Enter here: "))
\(SETQ ss1 (ssget "_x" '((0 . "INSERT")(2 . P1)))

....

it turns out that my SSGET doesn't seem to work ....


 

[You don't want that backslash.]

 

When something in the (ssget) filter list requires evaluation -- that P1 variable -- you cannot use the "quoted list" approach with the preceding apostrophe on the entire list, but must use the explicit (list) function.  Inside that you can include a quoted list for the entity type, but you need to assemble the Block name entry with (cons):

  (SETQ

    ss1 (ssget "_x" (list '(0 . "INSERT") (cons 2 P1)))

    ....

 

You can get the insertion point of such a Block [may we assume that's also the center of the Circles?] from the (assoc 10) entry in entity data, but you can't get the radius of the nested Circle(s) as you do with a top-level Circle.  If the Circles in question are the outermost elements of the Block, you could find the middle of its bounding box.  Or, if you can always select the Block on one of the Circles, you could get the Circle's information with (nentsel) instead of (entsel), but that would be complicated if there might be other-than-1 scale factor(s), and/or if the Block insertion point is not also the Circle center, other-than-zero rotation.

Kent Cooper, AIA
0 Likes
Message 5 of 12

ronjonp
Mentor
Mentor

It's easier to solve these problems by posting an example drawing of what you're working with.

0 Likes
Message 6 of 12

Anonymous
Not applicable

The Block is dynamic, where you can change the diameter of both inner and outer circle manually, or from a list of predetermined list of choice. Also there is a tab where you can choose if you want to make the outer circle dotted or not.

0 Likes
Message 7 of 12

dlanorh
Advisor
Advisor

OK, what is the name of the block definition, or the effective name of one of the dynamic block references?

I am not one of the robots you're looking for

0 Likes
Message 8 of 12

Anonymous
Not applicable

Getting the center with ASSOC 10 is possible if I select these blocks manually. But I need to to filter these blocks from a bunch of other shapes and blocks, so a working filter is needed.

 

Name of the block could be another problem, I'm working in Japan right now and the name given to this block is:
"座グリ (平面) R3"

Which roughly translates to "Drill (Vertical Plane) R3"

Referencing a Drill hole looking from above.

 

The name written could be an issue, but since other people also use this block, I still would like to keep the name in Japanese. Could it be that the space are full-letters, instead of half-characters normally used?

0 Likes
Message 9 of 12

Scottu2
Advocate
Advocate

Could the routine  use the text/attribute to provide the information.  M6 requires a standard drill and tap size.  3 is a through hole.  And use the text insert point if it matches the circle/arc center.  Then you don't have to go in circles (pun intended).

0 Likes
Message 10 of 12

dlanorh
Advisor
Advisor

Sorry been a bit busy. You don't need to filter the blocks with the ssget, you can filter later by ignoring any non dynamic block where the effective name of the block doesn't match "*R3".

 

If the insertion point of the block is also the centre of the circles you only need to iterate the blocks entities and find the radius of any circle.

 

If the insertion point is not the centre of the circles you will have to use the VL explode method (don't worry this preserves the original block) which returns a copy of the block entities, and iterate this list extracting the centre and radius of any circle. Then delete exploded list. It sounds complicated but is achievable without a lot of code.

I am not one of the robots you're looking for

0 Likes
Message 11 of 12

Sea-Haven
Mentor
Mentor
 

For dynamic block just go to www.lee-mac.com and download his Dynamic block.lsp program it has everything you want in it, will return rad1 rad2 etc simply. It has get and put functions.

0 Likes
Message 12 of 12

Anonymous
Not applicable
Accepted solution

Sorry for the late response, been busy with other stuff.

Tried the Dynamic block.lsp you told me about, but couldn't find the right program I should be using.

 

But I did find another way where we just have a list of possible block names which I want the coordinates to be included.

and use:

SETQ SS1 (SSGET "_P" '((0 . "CIRCLE,INSERT"))) 

Which allows me to collect data on both blocks and circles.

(CDR (ASSOC 40 (SETQ ENTS (ENTGET EN))))

To get the name of the block.

Then I use the previously created list of acceptable blocks to check if any of the blocks should have coordinates in them.

I'm sure there was a better and easier way, but looking at my code which kept on not working (with my low skill sets probably) I did find a way.

Thank you for all your helps.

0 Likes