Selecting a circle with a script

Selecting a circle with a script

leslie.lees
Advocate Advocate
2,693 Views
13 Replies
Message 1 of 14

Selecting a circle with a script

leslie.lees
Advocate
Advocate

Hi Peeps,

    Is there an easy was to select a circle with a script?

My circle is in a block and can be selected manually, and works if I get the accuracy spot on. However it fails if I then change the size by scaling on insertion, my method of selection by script gets it close to within 5 decimal places but autoCAD is still rejecting it. Can I relax the accuracy of selection to less places, like the fuzziness setting in the join command?

Regards

Les

0 Likes
Accepted solutions (1)
2,694 Views
13 Replies
Replies (13)
Message 2 of 14

steven-g
Mentor
Mentor

We would need to see the block and the script. There is in LT no way to select elements that are inside a block so I can only imagine you are trying to use some selection method that involves a fence or window selection from your description. There are some methods that can be used to allow a script to select "objects" but there is no one method that will work in all circumstances.

0 Likes
Message 3 of 14

pendean
Community Legend
Community Legend
Q: if you need to select it all the time, why is the Circle in a block?
Does this block need to be a Dynamic Block to give you more abilities and control instead?
0 Likes
Message 4 of 14

leslie.lees
Advocate
Advocate

The block is an existing block in my template which is just a circle and crosslines blocked at 1mm, which I just scale to the application I need.

Inserting uses...

 

-INSERT
Hole_Scaleable
72025,57975
18
18
0

 

Then later I'm trying to dim it using...

 

_dimdiameter
72031.36312141,57981.3648
72091,57874.5

 In Visual Studio, to generate values I'm using....

 

ScriptBox_TB.AppendText("_dimdiameter" & vbNewLine & (StartPositionX + (intHoleStartOnX + (intHoleDiameter * 0.70701349) / 2)) & "," & (StartPositionY - (intHoleStartOnY - ((intHoleDiameter * 0.7072) / 2))) & vbNewLine &
                                (StartPositionX + intHoleStartOnX + (intHoleDimEndOffsetX * 1.5)) & "," & (StartPositionY - (intHoleStartOnY + (intHoleDimEndOffsetY * 1.5))) & vbNewLine & vbNewLine)

 

Multiplying by 0.7071 didn't get as close as the values I'm using now.

Even if I put the objects in as individual items I still would need to select the circle, at the moment sometimes it works sometimes it doesn't, giving an error that object selected isn't a circle.

 

Appreciate your comments guys.

 

Regards

Les

0 Likes
Message 5 of 14

steven-g
Mentor
Mentor

I would still need to see the block, for the actual sizes, I don't use visual studio but presumably your variables are set to sizes relating to the block? I use Excel VBA for all my coding so I'm trying to work out what your code is doing.

0 Likes
Message 6 of 14

leslie.lees
Advocate
Advocate

I've attached the block..

 

As dimlinear requires three inputs (command, selection of the circle, position of the text to go) the first line in the VS code generates an X,Y value for the selection of the circle (i.e. hole diameter * 0.7071), and the second line is the position for the text part to go.

 

Regards

Les

 

EDIT:

This is work in progress... but the code generates script to create various sized baseplate with a selection of holes and any hole positions.

BasePlates.png

0 Likes
Message 7 of 14

steven-g
Mentor
Mentor
Accepted solution

Smiley Very Happy Beat you to it, I managed to work out what your code is doing, and found the problem, I think

 

When running scripts any coordinate input reacts with Autocad as though the actual cursor is being placed, so depending on the drawing zoom factor then Osnaps can play a major role in how things work. The dimdiameter command expects an object selection so if you are zoomed out far enough your script will find the circle but it might also find other objects, if you are zoomed in and the coordinates aren't 100% then it misses seeing the circle, and then when it expects you to poition the dimension Autocad expects a point, which means that if you are zoomed out too far then the "cursor" has lots of items under it and snaps to one of those points rather than your coordinates. And in this case it just confuses the whole script, try adding "non" before your  coordinates in your script creator and that should hopefully sort things out, "non" just turns off osnaps for the following input point

_dimdiameter
non 72031.36312141,57981.3648
non 72091,57874.5

Another trick is sometimes to use the zoom command in a script to make sure that osnaps do actually find the correct points

 

Message 8 of 14

leslie.lees
Advocate
Advocate

Sounds interesting...I'll explore...thank you for your interest. 😄

 

I should also (thinking out aloud) only need it for the circle select, as the second point for the text placement isn't worried about osnap....it's just an artbitrary position.

 

Playing now....

 

Regards

Les

0 Likes
Message 9 of 14

leslie.lees
Advocate
Advocate

Mmm...not working for me..

 

Using the block uploaded..try the attached script, you may need to change the textstyle.

 

There is another problem, which I won't mention yet, as I'd like to hear your initial response. But certaily looks like your zooming issue.

 

Enjoy 😄

0 Likes
Message 10 of 14

steven-g
Mentor
Mentor

In my testing it was actually the second part that failed, I was zoomed further out and can only imagine that Autocad had actually seen the center osnap of the circle as your placement for the dimension and so it failed to work.

0 Likes
Message 11 of 14

leslie.lees
Advocate
Advocate

After running the script F2 gives the following info....

 

Command: _dimdiameter

Select arc or circle: non 72041.36312141,57971.3648

Object selected is not a circle or arc.

Select arc or circle: non 72101,57864.5

Select arc or circle:

I may be forgiven for thinking it is the first input that is failing?? Do you have any thoughts on that?

0 Likes
Message 12 of 14

steven-g
Mentor
Mentor

You are correct, and this is the problem with zoom factor.

Try this script

 

0 Likes
Message 13 of 14

leslie.lees
Advocate
Advocate

Ok, I'll accept that as a solution.

 

Definitely the Zoom issue, it got stuck after zooming in, but added the 'dimdiameter' so I zoomed back out again and it worked fine, also found adding a 'w' after the zoom command worked for me.

 

Appreciate your help, many thanks.

 

Will be nice if it continues to work as I change all the dimensions in the VS app that creates this code. 😄

 

Did you notice any other issues? In particular the fact that the script needs to be dropped in up to three or four times before it works correctly. This seems odd.

 

regards

Les

0 Likes
Message 14 of 14

steven-g
Mentor
Mentor

I tried it starting out with different zoom positions and indeed noticed it sometimes failed to place the dimdiameter, which is a bit odd, almost as though it took too long to zoom in. So I added a delay and regen just after the zoom and that seems to fix it, but that is a new "glitch" that I have never noticed before.