Author Topic: Getting from a block ...  (Read 6359 times)

0 Members and 1 Guest are viewing this topic.

Hangman

  • Swamp Rat
  • Posts: 566
Getting from a block ...
« on: October 19, 2006, 05:15:06 PM »
Sorry, but I have another lame question to ask.  My brain is scattered and going in several different directions so my topics tend to go all over the place.

OK, so my question is,
Can I get a circle size from a block ??

I have the head of a 3/4" diameter bolt.  It's a block with an insertion point in the center.
My dream is to get the size of the bolt or circle (either diameter or radius, it doesn't matter) from the block and the insertion point just by doing an entsel or a single selection of the entity.

When I do a list on the object I get the following:
Quote
BLOCK REFERENCE  Layer: "S-Object"
                            Space: Model space
                   Handle = 2c2
       Block Name: "bolteDrawing12"
                at point, X=3'-7 15/16"  Y=    3'-7"  Z=    0'-0"
   X scale factor:   1.00000
   Y scale factor:   1.00000
   rotation angle:      0
   Z scale factor:   1.00000
  Scale uniformly: No
  Allow exploding: Yes

This gives me an insertion point, but not much else.

When I attach it to a variable, I get the following:
Quote
!bolt
(<Entity name: 7ef97150> (44.2741 42.5963 0.0))

**Side question - What are the three numbers listed at the end ??
I tried pulling them out thinking they were the insertion point of the block, but they don't give the same coordinates as the insertion point of the block.

I wouldn't think there is enough info from the !bolt to get the size of the circle, but I don't know enough about extracting info to know any better.

Thank you for your comments & help.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Getting from a block ...
« Reply #1 on: October 19, 2006, 05:24:10 PM »
Is the circle the only circle in the block?

The list of numbers that is returned by (entsel) is the center of the pickbox when the selection was made.

You can access the entity within the block using (nentsel). The radius of the inserted circle will be the block's circle obj's radius times the Insert's scale factor (assuming X/Y/Z scale is equal).

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Getting from a block ...
« Reply #2 on: October 19, 2006, 05:33:10 PM »
As Jeff stated, you can use nentsel something like this:

(setq x (entget (car (nentsel))))

(cdr (assoc 10 x));gets center

(cdr (assoc 40 x));gets radius

Ron

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Getting from a block ...
« Reply #3 on: October 19, 2006, 06:00:49 PM »
I would think something would tell you that it was a 3/4" bolt.
Eather the block name, "bolteDrawing12", or the scale?
Although I see it is scaled at 1.0 .
What tells you when inserting the block that it is a 3/4" bolt?

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Getting from a block ...
« Reply #4 on: October 19, 2006, 06:14:04 PM »
Thank you for your quick responses.  That's another of the many aspects of the Swamp that is impressive.

Quote
Is the circle the only circle in the block?
Yes it is.  Basically, if you look at a bolt from the top, you will see the outline of the hex head, a pline.  And then the circle, the diameter of the bolt itself.

Doht !!  NENTSEL - of course.  I keep forgetting about that one.

Thank you Ron for that example.  It helps me learn when I see code used in examples.

Quoted from CAB:
Quote
I would think something would tell you that it was a 3/4" bolt.
Eather the block name, "bolteDrawing12", or the scale?
Although I see it is scaled at 1.0 .
What tells you when inserting the block that it is a 3/4" bolt?

We have a routine that asks for an insertion point and a size for the placement of the bolt, then it draws the bolt & makes it a block.
So yes, the scale will show 1.0.  The name of the block, "bolteDrawing12" is the name & count of the blocks in the drawing.  I have been really temped to go modify the routine so it will give you the size in the name but I haven't done it yet.

I'm working on a slotted hole program, but I don't want it part of the bolte program as it is seldom used in comparison.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Hangman

  • Swamp Rat
  • Posts: 566
Re: Getting from a block ...
« Reply #5 on: October 20, 2006, 11:56:47 AM »
Aaal-righty then,
I'm having a bit of a struggle here.  Can you guys help me again, please.
This is what I currently have,
Code: [Select]
;
;;;get the bolt
;
  (setq bolt (entget (car (nentsel "\nSelect Bolt...  "))))
;
  (setq pts (caddr bolt))
  (setq pts (cdddr pts))
  (setq pts (car pts))
And this is what is received,
Quote
Select object: ((-1 . <Entity name: 7efe4100>) (0 . "LWPOLYLINE") (330 .
<Entity name: 7efe40e8>) (5 . "2C0") (100 . "AcDbEntity") (67 . 0) (8 . "0")
(100 . "AcDbPolyline") (90 . 6) (70 . 1) (43 . 0.0) (38 . 0.0) (39 . 0.0) (10
-0.375002 0.649523) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 -0.750004 0.0) (40 .
0.0) (41 . 0.0) (42 . 0.0) (10 -0.375002 -0.649523) (40 . 0.0) (41 . 0.0) (42 .
0.0) (10 0.375002 -0.649523) (40 . 0.0) (41 . 0.0) (42 . 0.0) (10 0.750004 0.0)
(40 . 0.0) (41 . 0.0) (42 . 0.0) (10 0.375002 0.649523) (40 . 0.0) (41 . 0.0)
(42 . 0.0) (210 0.0 0.0 1.0))

Ok, so all's good, except the (40 . 0.0) parts.
I'm assuming these are in corrolation with the
Quote
(cdr (assoc 40 x));gets radius
mentioned by Ron.
And that's exactly what I'm receiving,
Quote
Command: (assoc 40 x)
(40 . 0.0)

Command: (cdr (assoc 40 x))
0.0

So it's not pulling the radius of the circle out of my block, right ?.?
What am I to do ??

...  Aaah, I just discovered something.  If I select the 6 sided polygon around the bolt, I get the (0 . "LWPOLYLINE") .
So the circle in the block has to be selected.

Is there a way where I can select the block like so,
Code: [Select]
(setq bolt (nentsel "\nSelect Bolt...  "))
Quote
Command: (setq bolt (nentsel))

Select object: (<Entity name: 7e9320f8> (44.1575 42.7079 0.0) ((1.0 0.0 0.0)
(0.0 1.0 0.0) (0.0 0.0 1.0) (43.9475 43.0145 0.0)) (<Entity name: 7e932110>))

Then pull out what I need, something like,
Code: [Select]
(setq circle (entget (car (ssget "L"))))
To get
Quote
((-1 . <Entity name: 7e9320f8>) (0 . "CIRCLE") (330 . <Entity
name: 7e9320e8>) (5 . "2BF") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 .
"AcDbCircle") (10 0.0 0.0 0.0) (40 . 0.375) (210 0.0 0.0 1.0))

 -- this obviously doesn't work as it is, can you show me how I would do it if it can be done ??
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Getting from a block ...
« Reply #6 on: October 20, 2006, 12:08:46 PM »
What is in the block?  Can you post it?

One way is to step through the blocks definition.  Use 'entsel' to get the block, then use 'entget' to get the list of dxf codes for the block entity.  Then use '(cdr (assoc 2 ' on the 'entget'ed list to get the block name.  Then use 'tblobjname' with ... will be easier to show with code.
Code: [Select]
(setq Sel (entsel "\n Select block: "))
(setq EntData (entget (car Sel)))
(setq BlkName (cdr (assoc 2 EntData)))
(setq BlkDefEnt (tblobjname "block" BlkName))
(setq tempEnt BlkDefEnt)
(while (setq tempEnt (entnext tempEnt))
 (setq tempEntData (entget tempEnt))
 (if (= (cdr (assoc 0 tempEntData)) "CIRCLE")
  (print tempEntData)
  ; here you will grab the stuff you want, I'm just printing it to the command line
 )
)

Hope this explains it more clearly than words.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

uncoolperson

  • Guest
Re: Getting from a block ...
« Reply #7 on: October 20, 2006, 12:13:21 PM »
how is the block put together?

might be able to just reverse the logic to figure out the size.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Getting from a block ...
« Reply #8 on: October 20, 2006, 12:35:36 PM »
Sorry, I don't know how to put a pic in here.
I've seen others do it, but, my luck doesn't allow it to happen  :-(

The block is just a 6 sided polygon with a circle in the middle, basically the head of a bolt.
I want the user to make a single selection, either the 6 sided polygon or the circle.  They are mearly selecting the block.
From there, I want the LiSP to distinguish between the polygon & the circle and take the circle.
I then need to get the radius of that circle.
I then can finish the routine.
I think I can get there after I figure this little piece out.  But I know just enough about lisp to get into a lot of trouble.  And my momma said my name was Trouble.   :roll:

Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Getting from a block ...
« Reply #9 on: October 20, 2006, 12:43:46 PM »
Did what I post not help?  To use, at the command line type in '(progn' then past the code, then end the call with ')'.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Getting from a block ...
« Reply #10 on: October 20, 2006, 12:52:49 PM »
doht, gett'n there, hang on.

I've got some people bugg'n me about drawings.  Others about details and others about a Friday afternoon deadline.

They won't leave me alone so I can play.  Gimme a few minutes.   ^-^
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CADaver

  • Guest
Re: Getting from a block ...
« Reply #11 on: October 20, 2006, 01:32:04 PM »
We have a routine that asks for an insertion point and a size for the placement of the bolt, then it draws the bolt & makes it a block.
So yes, the scale will show 1.0.  The name of the block, "bolteDrawing12" is the name & count of the blocks in the drawing.  I have been really temped to go modify the routine so it will give you the size in the name but I haven't done it yet.

Okay, I've kind of waded through the posts and I think you'd be MUCH better served focusing your effort here for a couple of reasons. 
One, with a block named to match the size, you won't need twelve different block names for one 3/4" bolt, when you need another just insert the one already built.  That will make counting bolts later a lot easier, plus file size advantages with multiple use blocks..
Two, a simple LIST will tell you size it is
And three, modifying the existing bolt making function should be a lot easier than wading through that particular block to find a circle diameter of a specific circle.

But that's just my take on it.

daron

  • Guest
Re: Getting from a block ...
« Reply #12 on: October 20, 2006, 01:38:08 PM »
Hangman? Another problem with >>what you selected<< is that it is not a circle. It is a
Code: [Select]
(0 . "LWPOLYLINE") polyline. If I remember correctly the 40, 41's are bulge factors or something. For a polyline vertice set, you'd be looking at all the 10's for you coordinates. My guess is you selected the hex, not the circle.

Make sure you select a circle.

daron

  • Guest
Re: Getting from a block ...
« Reply #13 on: October 20, 2006, 01:40:17 PM »
Oops. You caught that. Just ignore me.

Hangman

  • Swamp Rat
  • Posts: 566
Re: Getting from a block ...
« Reply #14 on: October 20, 2006, 01:58:36 PM »
Tim,
I've run your routine and it work well.  But when I try to assoc 40 for the circle, I get (40 . 0.0)
So with this info, I'm assuming I'll have to get to 'could-er, caid-er, cadd-er' to get the (40 . 0.375) radius I need ?.?

Quoted from CADaver:
Quote
Okay, I've kind of waded through the posts and I think you'd be MUCH better served focusing your effort here for a couple of reasons.  
One, with a block named to match the size, you won't need twelve different block names for one 3/4" bolt, when you need another just insert the one already built.  That will make counting bolts later a lot easier, plus file size advantages with multiple use blocks..
Two, a simple LIST will tell you size it is
And three, modifying the existing bolt making function should be a lot easier than wading through that particular block to find a circle diameter of a specific circle.
Randy, I agree on renaming the block when it's created and I plan to that eventually.  It would help in a lot of ways, so thank you for you thoughts & comments there.  However, I'd still have to go through a lot of this to get the size of the radius of the circle out of the name to use here.  This way, whatever the name of the block, I will still get the info I need.

I think Tim's on the right track.
The user can pick the block, regardless of what entity of the block is picked.
The routine will decifer the info and find two things;  A- the center of the circle, B- the radius of the circle
The routine will then create points along the X axis from the center of the circle,
And so on and so forth.

Yup Daron, we caught it.  But thanks though, I appreciate your help.
Hangman  8)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Drafting Board, Mechanical Arm, KOH-I-NOOR 0.7mm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~